1
|
#!/bin/sh
|
2
|
# Functions which perform the extraction / installation of system to disk
|
3
|
|
4
|
. ${BACKEND}/functions-mountoptical.sh
|
5
|
|
6
|
# Performs the extraction of data to disk from a uzip or tar archive
|
7
|
start_extract_uzip_tar()
|
8
|
{
|
9
|
if [ -z "$INSFILE" ]
|
10
|
then
|
11
|
exit_err "ERROR: Called extraction with no install file set!"
|
12
|
fi
|
13
|
|
14
|
# Check if we have a .count file, and echo it out for a front-end to use in progress bars
|
15
|
if [ -e "${INSFILE}.count" ]
|
16
|
then
|
17
|
echo "INSTALLCOUNT: `cat ${INSFILE}.count`"
|
18
|
fi
|
19
|
|
20
|
# Check if we are doing an upgrade, and if so use our exclude list
|
21
|
if [ "${INSTALLMODE}" = "upgrade" ]
|
22
|
then
|
23
|
TAROPTS="-X ${PROGDIR}/conf/exclude-from-upgrade"
|
24
|
else
|
25
|
TAROPTS=""
|
26
|
fi
|
27
|
|
28
|
echo_log "pc-sysinstall: Starting Extraction"
|
29
|
|
30
|
case ${PACKAGETYPE} in
|
31
|
uzip) # Start by mounting the uzip image
|
32
|
MDDEVICE=`mdconfig -a -t vnode -o readonly -f ${INSFILE}`
|
33
|
mkdir -p ${FSMNT}.uzip
|
34
|
mount -r /dev/${MDDEVICE}.uzip ${FSMNT}.uzip
|
35
|
if [ "$?" != "0" ]
|
36
|
then
|
37
|
exit_err "ERROR: Failed mounting the ${INSFILE}"
|
38
|
fi
|
39
|
cd ${FSMNT}.uzip
|
40
|
|
41
|
# Copy over all the files now!
|
42
|
tar cvf - . 2>/dev/null | tar -xpv -C ${FSMNT} ${TAROPTS} -f - 2>&1 | tee -a ${FSMNT}/.tar-extract.log
|
43
|
if [ "$?" != "0" ]
|
44
|
then
|
45
|
cd /
|
46
|
echo "TAR failure occured:" >>${LOGOUT}
|
47
|
cat ${FSMNT}/.tar-extract.log | grep "tar:" >>${LOGOUT}
|
48
|
umount ${FSMNT}.uzip
|
49
|
mdconfig -d -u ${MDDEVICE}
|
50
|
exit_err "ERROR: Failed extracting the tar image"
|
51
|
fi
|
52
|
|
53
|
# All finished, now lets umount and cleanup
|
54
|
cd /
|
55
|
umount ${FSMNT}.uzip
|
56
|
mdconfig -d -u ${MDDEVICE}
|
57
|
;;
|
58
|
tar) tar -xpv -C ${FSMNT} -f ${INSFILE} ${TAROPTS} >&1 2>&1
|
59
|
if [ "$?" != "0" ]
|
60
|
then
|
61
|
exit_err "ERROR: Failed extracting the tar image"
|
62
|
fi
|
63
|
;;
|
64
|
esac
|
65
|
|
66
|
# Check if this was a FTP download and clean it up now
|
67
|
if [ "${INSTALLMEDIUM}" = "ftp" ]
|
68
|
then
|
69
|
echo_log "Cleaning up downloaded archive"
|
70
|
rm ${INSFILE}
|
71
|
rm ${INSFILE}.count >/dev/null 2>/dev/null
|
72
|
rm ${INSFILE}.md5 >/dev/null 2>/dev/null
|
73
|
fi
|
74
|
|
75
|
echo_log "pc-sysinstall: Extraction Finished"
|
76
|
|
77
|
};
|
78
|
|
79
|
# Performs the extraction of data to disk from a directory with split files
|
80
|
start_extract_split()
|
81
|
{
|
82
|
if [ -z "${INSDIR}" ]
|
83
|
then
|
84
|
exit_err "ERROR: Called extraction with no install directory set!"
|
85
|
fi
|
86
|
|
87
|
echo_log "pc-sysinstall: Starting Extraction"
|
88
|
|
89
|
# Used by install.sh
|
90
|
DESTDIR="${FSMNT}"
|
91
|
export DESTDIR
|
92
|
|
93
|
HERE=`pwd`
|
94
|
DIRS=`ls -d ${INSDIR}/*|grep -Ev '(uzip|kernels|src)'`
|
95
|
for dir in ${DIRS}
|
96
|
do
|
97
|
cd "${dir}"
|
98
|
if [ -f "install.sh" ]
|
99
|
then
|
100
|
echo "Extracting" `basename ${dir}`
|
101
|
echo "y" | sh install.sh >/dev/null
|
102
|
if [ "$?" != "0" ]
|
103
|
then
|
104
|
exit_err "ERROR: Failed extracting ${dir}"
|
105
|
fi
|
106
|
else
|
107
|
exit_err "ERROR: ${dir}/install.sh does not exist"
|
108
|
fi
|
109
|
done
|
110
|
cd "${HERE}"
|
111
|
|
112
|
KERNELS=`ls -d ${INSDIR}/*|grep kernels`
|
113
|
cd "${KERNELS}"
|
114
|
if [ -f "install.sh" ]
|
115
|
then
|
116
|
echo "Extracting" `basename ${KERNELS}`
|
117
|
echo "y" | sh install.sh generic >/dev/null
|
118
|
if [ "$?" != "0" ]
|
119
|
then
|
120
|
exit_err "ERROR: Failed extracting ${KERNELS}"
|
121
|
fi
|
122
|
echo 'kernel="GENERIC"' > "${FSMNT}/boot/loader.conf"
|
123
|
else
|
124
|
exit_err "ERROR: ${KERNELS}/install.sh does not exist"
|
125
|
fi
|
126
|
cd "${HERE}"
|
127
|
|
128
|
SOURCE=`ls -d ${INSDIR}/*|grep src`
|
129
|
cd "${SOURCE}"
|
130
|
if [ -f "install.sh" ]
|
131
|
then
|
132
|
echo "Extracting" `basename ${SOURCE}`
|
133
|
echo "y" | sh install.sh all >/dev/null
|
134
|
if [ "$?" != "0" ]
|
135
|
then
|
136
|
exit_err "ERROR: Failed extracting ${SOURCE}"
|
137
|
fi
|
138
|
else
|
139
|
exit_err "ERROR: ${SOURCE}/install.sh does not exist"
|
140
|
fi
|
141
|
cd "${HERE}"
|
142
|
|
143
|
echo_log "pc-sysinstall: Extraction Finished"
|
144
|
};
|
145
|
|
146
|
# Function which will attempt to fetch the install file before we start
|
147
|
# the install
|
148
|
fetch_install_file()
|
149
|
{
|
150
|
get_value_from_cfg ftpPath
|
151
|
if [ -z "$VAL" ]
|
152
|
then
|
153
|
exit_err "ERROR: Install medium was set to ftp, but no ftpPath was provided!"
|
154
|
fi
|
155
|
|
156
|
FTPPATH="${VAL}"
|
157
|
|
158
|
# Check if we have a /usr partition to save the download
|
159
|
if [ -d "${FSMNT}/usr" ]
|
160
|
then
|
161
|
OUTFILE="${FSMNT}/usr/.fetch-${INSFILE}"
|
162
|
else
|
163
|
OUTFILE="${FSMNT}/.fetch-${INSFILE}"
|
164
|
fi
|
165
|
|
166
|
# Do the fetch of the archive now
|
167
|
fetch_file "${FTPPATH}/${INSFILE}" "${OUTFILE}" "1"
|
168
|
|
169
|
# Check to see if there is a .count file for this install
|
170
|
fetch_file "${FTPPATH}/${INSFILE}.count" "${OUTFILE}.count" "0"
|
171
|
|
172
|
# Check to see if there is a .md5 file for this install
|
173
|
fetch_file "${FTPPATH}/${INSFILE}.md5" "${OUTFILE}.md5" "0"
|
174
|
|
175
|
# Done fetching, now reset the INSFILE to our downloaded archived
|
176
|
INSFILE="${OUTFILE}" ; export INSFILE
|
177
|
|
178
|
};
|
179
|
|
180
|
# Function which does the rsync download from the server specifed in cfg
|
181
|
start_rsync_copy()
|
182
|
{
|
183
|
# Load our rsync config values
|
184
|
get_value_from_cfg rsyncPath
|
185
|
if [ -z "${VAL}" ]; then
|
186
|
exit_err "ERROR: rsyncPath is unset! Please check your config and try again."
|
187
|
fi
|
188
|
RSYNCPATH="${VAL}" ; export RSYNCPATH
|
189
|
|
190
|
get_value_from_cfg rsyncHost
|
191
|
if [ -z "${VAL}" ]; then
|
192
|
exit_err "ERROR: rsyncHost is unset! Please check your config and try again."
|
193
|
fi
|
194
|
RSYNCHOST="${VAL}" ; export RSYNCHOST
|
195
|
|
196
|
get_value_from_cfg rsyncUser
|
197
|
if [ -z "${VAL}" ]; then
|
198
|
exit_err "ERROR: rsyncUser is unset! Please check your config and try again."
|
199
|
fi
|
200
|
RSYNCUSER="${VAL}" ; export RSYNCUSER
|
201
|
|
202
|
get_value_from_cfg rsyncPort
|
203
|
if [ -z "${VAL}" ]; then
|
204
|
exit_err "ERROR: rsyncPort is unset! Please check your config and try again."
|
205
|
fi
|
206
|
RSYNCPORT="${VAL}" ; export RSYNCPORT
|
207
|
|
208
|
COUNT="1"
|
209
|
while
|
210
|
z=1
|
211
|
do
|
212
|
if [ ${COUNT} -gt ${RSYNCTRIES} ]
|
213
|
then
|
214
|
exit_err "ERROR: Failed rsync command!"
|
215
|
break
|
216
|
fi
|
217
|
|
218
|
rsync -avvzHsR \
|
219
|
--rsync-path="rsync --fake-super" \
|
220
|
-e "ssh -p ${RSYNCPORT}" \
|
221
|
${RSYNCUSER}@${RSYNCHOST}:${RSYNCPATH}/./ ${FSMNT}
|
222
|
if [ "$?" != "0" ]
|
223
|
then
|
224
|
echo "Rsync failed! Tries: ${COUNT}"
|
225
|
else
|
226
|
break
|
227
|
fi
|
228
|
|
229
|
COUNT="`expr ${COUNT} + 1`"
|
230
|
done
|
231
|
|
232
|
};
|
233
|
|
234
|
|
235
|
# Entrance function, which starts the installation process
|
236
|
init_extraction()
|
237
|
{
|
238
|
# Figure out what file we are using to install from via the config
|
239
|
get_value_from_cfg installFile
|
240
|
|
241
|
if [ ! -z "${VAL}" ]
|
242
|
then
|
243
|
INSFILE="${VAL}" ; export INSFILE
|
244
|
else
|
245
|
# If no installFile specified, try our defaults
|
246
|
if [ "$INSTALLTYPE" = "FreeBSD" ]
|
247
|
then
|
248
|
case $PACKAGETYPE in
|
249
|
uzip) INSFILE="${FBSD_UZIP_FILE}" ;;
|
250
|
tar) INSFILE="${FBSD_TAR_FILE}" ;;
|
251
|
split)
|
252
|
INSDIR="${FBSD_BRANCH_DIR}"
|
253
|
|
254
|
# This is to trick opt_mount into not failing
|
255
|
INSFILE="${INSDIR}"
|
256
|
;;
|
257
|
esac
|
258
|
else
|
259
|
case $PACKAGETYPE in
|
260
|
uzip) INSFILE="${UZIP_FILE}" ;;
|
261
|
tar) INSFILE="${TAR_FILE}" ;;
|
262
|
esac
|
263
|
fi
|
264
|
export INSFILE
|
265
|
fi
|
266
|
|
267
|
# Lets start by figuring out what medium we are using
|
268
|
case ${INSTALLMEDIUM} in
|
269
|
dvd|usb) # Lets start by mounting the disk
|
270
|
opt_mount
|
271
|
if [ ! -z "${INSDIR}" ]
|
272
|
then
|
273
|
INSDIR="${CDMNT}/${INSDIR}" ; export INSDIR
|
274
|
start_extract_split
|
275
|
|
276
|
else
|
277
|
INSFILE="${CDMNT}/${INSFILE}" ; export INSFILE
|
278
|
start_extract_uzip_tar
|
279
|
fi
|
280
|
;;
|
281
|
ftp) fetch_install_file
|
282
|
start_extract_uzip_tar
|
283
|
;;
|
284
|
rsync) start_rsync_copy
|
285
|
;;
|
286
|
*) exit_err "ERROR: Unknown install medium" ;;
|
287
|
esac
|
288
|
|
289
|
};
|