]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2014 IPFire Team <info@ipfire.org> # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | function download() { | |
23 | wget -U "IPFire-NetInstall/2.x" "$@" | |
24 | } | |
25 | ||
26 | if [ $# -lt 2 ]; then | |
27 | echo "$0: Insufficient number of arguments" >&2 | |
28 | exit 2 | |
29 | fi | |
30 | ||
31 | DESTINATION="${1}" | |
32 | DOWNLOAD_URL="${2}" | |
33 | ||
34 | DOWNLOAD_TARGET="/tmp/post-install.exe" | |
35 | ||
36 | if download -O "${DESTINATION}${DOWNLOAD_TARGET}" "${DOWNLOAD_URL}"; then | |
37 | echo "Downloading post-install script from ${DOWNLOAD_URL}..." | |
38 | ||
39 | # Make it executable | |
40 | chmod a+x "${DESTINATION}${DOWNLOAD_TARGET}" | |
41 | ||
42 | # Replace /etc/resolv.conf so that we will have | |
43 | cp -fb /etc/resolv.conf ${DESTINATION}/etc/resolv.conf | |
44 | for i in /dev /proc /sys; do | |
45 | mount --bind "${i}" "${DESTINATION}${i}" | |
46 | done | |
47 | ||
48 | # Execute the downloaded script | |
49 | chroot "${DESTINATION}" sh --login -c "${DOWNLOAD_TARGET}" | |
50 | retval=$? | |
51 | ||
52 | # Cleanup the environment | |
53 | mv -f ${DESTINATION}/etc/resolv.conf{~,} | |
54 | for i in /dev /proc /sys; do | |
55 | umount "${DESTINATION}${i}" | |
56 | done | |
57 | rm -f "${DESTINATION}${DOWNLOAD_TARGET}" | |
58 | ||
59 | exit ${retval} | |
60 | ||
61 | # In case the download failed | |
62 | else | |
63 | echo "Could not download the post-install script" >&2 | |
64 | exit 1 | |
65 | fi |