-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunpack_run.sh.tmpl
76 lines (64 loc) · 1.41 KB
/
unpack_run.sh.tmpl
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
#!/bin/sh
## Image installer for ONIE.
## Based on ONIE updater.
##
## Shell archive template
##
## Strings of the form %%VAR%% are replaced during construction.
##
echo -n "Verifying image checksum ..."
sha1=$(sed -e '1,/^exit_marker$/d' "$0" | sha1sum | awk '{ print $1 }')
payload_sha1=%%IMAGE_SHA1%%
if [ "$sha1" != "$payload_sha1" ] ; then
echo
echo "ERROR: Unable to verify archive checksum"
echo "Expected: $payload_sha1"
echo "Found : $sha1"
exit 1
fi
echo " OK."
tmp_dir=
clean_up() {
if [ "$(id -u)" = "0" ] ; then
umount $tmp_dir > /dev/null 2>&1
fi
rm -rf $tmp_dir
exit $1
}
# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || clean_up 1
fi
cd $tmp_dir
echo -n "Unpacking the installer ..."
sed -e '1,/^exit_marker$/d' $archive_path | tar xz || clean_up 1
echo " done."
cd $cur_wd
extract=no
args=":x"
while getopts "$args" a ; do
case $a in
x)
extract=yes
;;
*)
;;
esac
done
if [ "$extract" = "yes" ] ; then
# stop here
echo "Image extracted to: $tmp_dir"
if [ "$(id -u)" = "0" ] ; then
echo "To un-mount the tmpfs when finished type: umount $tmp_dir"
fi
exit 0
fi
cd $tmp_dir
$tmp_dir/os-installer.sh "$@"
rc="$?"
cd $cur_wd
clean_up $rc
exit_marker