forked from hetzneronline/installimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallimage
executable file
·150 lines (121 loc) · 3.72 KB
/
installimage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
#
# installimage main start script
#
# originally written by Florian Wicke and David Mayr
# (c) 2007-2021, Hetzner Online GmbH
#
# simple params - restart with other params
case $1 in
proxmox4) exec "$0" -c proxmox4 -x proxmox4 ;;
proxmox5) exec "$0" -c proxmox5 -x proxmox5 ;;
proxmox6) exec "$0" -c proxmox6 -x proxmox6 ;;
proxmox7) exec "$0" -c proxmox7 -x proxmox7 ;;
hsa-baculadir) exec "$0" -c hsa-baculadir -x hsa-baculadir ;;
hsa-minimal64) exec "$0" -c hsa-minimal64 -x hsa-minimal64 ;;
hsa-managed) exec "$0" -c hsa-managed -x hsa-managed ;;
hsa-sql) exec "$0" -c hsa-sql -x hsa-sql ;;
esac
clear
wd=$(pwd)
export wd
# important: set pipefile bash option, see bash manual
set -o pipefail
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export EXITCODE=0
# invalidate all caches, so we get the latest version from nfs
echo 3 >/proc/sys/vm/drop_caches
# realconfig
SCRIPTPATH="$(dirname "$0")"
REALCONFIG="$SCRIPTPATH/config.sh"
FOLD="$(mktemp -d /installimage.XXXXX)"
# copy our config file and read global variables and functions
cp -a "$REALCONFIG" /tmp/install.vars
. /tmp/install.vars
# clear debugfile
echo > "$DEBUGFILE"
# cleanup on EXIT
trap cleanup EXIT
# get command line options
if [ $# -lt 1 ] && [ ! -e "$AUTOSETUPCONFIG" ] ; then
echo ""
echo -e "${YELLOW}run 'installimage -h' to get help for command line arguments."
echo -e "${GREEN}starting interactive mode ...${NOCOL}"
echo ""
# press any key or sleep 1 sec ...
read -n1 -t1
fi
. "$GETOPTIONSFILE"
# deleting possible existing files and create dirs
{
umount -l "$FOLD/*"
rm -rf "$FOLD"
mkdir -p "$FOLD/nfs"
mkdir -p "$FOLD/hdd"
} >/dev/null 2>&1
cd "$FOLD" || exit 1
debug "# starting installimage"
# log hardware data
debug "-------------------------------------"
hwdata="/usr/local/bin/hwdata"
[ -f $hwdata ] && $hwdata | grep -v "^$" | debugoutput
debug "-------------------------------------"
# generate new config file with our parameters and the template config from the nfs-server
debug "# make clean config"
if [ -f /tmp/install.vars ]; then
. /tmp/install.vars
else
debug "=> FAILED"
fi
# Unmount all partitions and print an error message if it fails
output=$(unmount_all) ; EXITCODE=$?
if [ $EXITCODE -ne 0 ] ; then
echo ""
echo -e "${RED}ERROR unmounting device(s):$NOCOL"
echo "$output"
echo ""
echo -e "${RED}Cannot continue, device(s) seem to be in use.$NOCOL"
echo "Please unmount used devices manually or reboot the rescuesystem and retry."
echo ""
exit 1
fi
stop_lvm_raid ; EXITCODE=$?
if [ $EXITCODE -ne 0 ] ; then
echo ""
echo -e "${RED}ERROR stopping LVM and/or RAID device(s):$NOCOL"
echo ""
echo -e "${RED}Cannot continue, device(s) seem to be in use.$NOCOL"
echo "Please stop used lvm/raid manually or reboot the rescuesystem and retry."
echo ""
exit 1
fi
# check if we have a autosetup-file, else we start the menu
if [ -e "$AUTOSETUPCONFIG" ] ; then
# start autosetup
export AUTOSETUP="true"
cp "$AUTOSETUPCONFIG" "$FOLD/install.conf"
[ "$OPT_CONFIGFILE" ] && mv "$AUTOSETUPCONFIG" "$AUTOSETUPCONFIG.bak-$(date +%Y%m%d-%H%M%S)"
debug "# executing autosetup ..."
if [ -f "$AUTOSETUPFILE" ] ; then
. "$AUTOSETUPFILE" ; EXITCODE=$?
else
echo ""
echo -e "${RED}ERROR: $AUTOSETUPFILE does not exist${NOCOL}"
debug "=> FAILED, $AUTOSETUPFILE does not exist"
fi
else
# start the menu
debug "# executing setupfile"
if [ -f "$SETUPFILE" ] ; then
. "$SETUPFILE" ; EXITCODE=$?
else
debug "=> FAILED, $SETUPFILE does not exist"
echo ""
echo -e "${RED}ERROR: Cant find files${NOCOL}"
fi
fi
if [ "$EXITCODE" = "1" ]; then
exit 1
fi
# vim: ai:ts=2:sw=2:et