From 681c9bbe619ada94cc614719d276aa31397e2476 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 26 Oct 2014 20:11:04 +0100 Subject: [PATCH] installer: Implement option to run a postinstall script in the installer --- config/rootfiles/common/installer | 1 + src/installer/Makefile.am | 1 + src/installer/dracut-module/module-setup.sh | 3 +- src/installer/execute-postinstall.sh | 65 +++++++++++++++++++++ src/installer/main.c | 20 +++++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/installer/execute-postinstall.sh diff --git a/config/rootfiles/common/installer b/config/rootfiles/common/installer index 71b537dd33..a0cb093434 100644 --- a/config/rootfiles/common/installer +++ b/config/rootfiles/common/installer @@ -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 diff --git a/src/installer/Makefile.am b/src/installer/Makefile.am index 62625fd0fe..d0e52dc187 100644 --- a/src/installer/Makefile.am +++ b/src/installer/Makefile.am @@ -34,6 +34,7 @@ bin_PROGRAMS = \ bin_SCRIPTS = \ downloadsource.sh \ + execute-postinstall.sh \ start-networking.sh #- installer ------------------------------------------------------------------- diff --git a/src/installer/dracut-module/module-setup.sh b/src/installer/dracut-module/module-setup.sh index 992fcecb79..187b12eb15 100755 --- a/src/installer/dracut-module/module-setup.sh +++ b/src/installer/dracut-module/module-setup.sh @@ -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 diff --git a/src/installer/execute-postinstall.sh b/src/installer/execute-postinstall.sh new file mode 100644 index 0000000000..695f1b521c --- /dev/null +++ b/src/installer/execute-postinstall.sh @@ -0,0 +1,65 @@ +#!/bin/sh +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2014 IPFire Team # +# # +# 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 . # +# # +############################################################################### + +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 diff --git a/src/installer/main.c b/src/installer/main.c index d3e1c6e3ed..ad388e6a91 100644 --- a/src/installer/main.c +++ b/src/installer/main.c @@ -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); -- 2.39.2