installer: Implement option to run a postinstall script in the installer

This commit is contained in:
Michael Tremer
2014-10-26 20:11:04 +01:00
parent a8fca24560
commit 681c9bbe61
5 changed files with 89 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
#usr/bin/downloadsource.sh
#usr/bin/execute-postinstall.sh
#usr/bin/start-networking.sh
#usr/bin/installer
#usr/lib/dracut/modules.d/99installer

View File

@@ -34,6 +34,7 @@ bin_PROGRAMS = \
bin_SCRIPTS = \
downloadsource.sh \
execute-postinstall.sh \
start-networking.sh
#- installer -------------------------------------------------------------------

View File

@@ -18,6 +18,7 @@ install() {
inst /etc/system-release
inst /usr/bin/installer
inst /usr/bin/downloadsource.sh
inst /usr/bin/execute-postinstall.sh
inst /usr/local/bin/iowrap
# Kernel drivers
@@ -46,7 +47,7 @@ install() {
inst_libdir_file "libnss_dns.so.*"
# Misc. tools
inst_multiple cut grep eject id killall md5sum touch
inst_multiple chmod cut grep eject id killall md5sum touch
inst_multiple -o fdisk cfdisk df ps top
# Hardware IDs

View File

@@ -0,0 +1,65 @@
#!/bin/sh
###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2014 IPFire Team <info@ipfire.org> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
function download() {
wget -U "IPFire-NetInstall/2.x" "$@"
}
if [ $# -lt 2 ]; then
echo "$0: Insufficient number of arguments" >&2
exit 2
fi
DESTINATION="${1}"
DOWNLOAD_URL="${2}"
DOWNLOAD_TARGET="/tmp/post-install.exe"
if download -O "${DESTINATION}${DOWNLOAD_TARGET}" "${DOWNLOAD_URL}"; then
echo "Downloading post-install script from ${DOWNLOAD_URL}..."
# Make it executable
chmod a+x "${DESTINATION}${DOWNLOAD_TARGET}"
# Replace /etc/resolv.conf so that we will have
cp -fb /etc/resolv.conf ${DESTINATION}/etc/resolv.conf
for i in /dev /proc /sys; do
mount --bind "${i}" "${DESTINATION}${i}"
done
# Execute the downloaded script
chroot "${DESTINATION}" sh --login -c "${DOWNLOAD_TARGET}"
retval=$?
# Cleanup the environment
mv -f ${DESTINATION}/etc/resolv.conf{~,}
for i in /dev /proc /sys; do
umount "${DESTINATION}${i}"
done
rm -f "${DESTINATION}${DOWNLOAD_TARGET}"
exit ${retval}
# In case the download failed
else
echo "Could not download the post-install script" >&2
exit 1
fi

View File

@@ -233,6 +233,7 @@ static struct config {
int perform_download;
int disable_swap;
char download_url[STRING_SIZE];
char postinstall[STRING_SIZE];
} config = {
.unattended = 0,
.serial_console = 0,
@@ -240,6 +241,7 @@ static struct config {
.perform_download = 0,
.disable_swap = 0,
.download_url = DOWNLOAD_URL,
.postinstall = "\0",
};
static void parse_command_line(struct config* c) {
@@ -280,6 +282,13 @@ static void parse_command_line(struct config* c) {
strncpy(c->download_url, val, sizeof(c->download_url));
c->perform_download = 1;
// Require networking for the download
c->require_networking = 1;
// postinstall script
} else if (strcmp(key, "installer.postinstall") == 0) {
strncpy(c->postinstall, val, sizeof(c->postinstall));
// Require networking for the download
c->require_networking = 1;
}
@@ -807,6 +816,17 @@ int main(int argc, char *argv[]) {
// Umount source drive and eject
hw_umount(SOURCE_MOUNT_PATH);
// Download and execute the postinstall script
if (*config.postinstall) {
snprintf(commandstring, sizeof(commandstring),
"/usr/bin/execute-postinstall.sh %s %s", DESTINATION_MOUNT_PATH, config.postinstall);
if (runcommandwithstatus(commandstring, title, _("Running post-install script..."), logfile)) {
errorbox(_("Post-install script failed."));
goto EXIT;
}
}
snprintf(commandstring, STRING_SIZE, "/usr/bin/eject %s", sourcedrive);
mysystem(logfile, commandstring);