This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathspp-usb-creator
executable file
·157 lines (138 loc) · 3.42 KB
/
spp-usb-creator
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
151
152
153
154
155
156
157
#!/bin/bash
#
# Creation of USB stick for HP SPP
script=$(readlink -f "$0")
script_path=$(dirname "$script")
script_name=$(basename "$script")
# shellcheck source=/dev/null
if ! source "$script_path/_functions"; then
echo "Function inclusion failed."
exit 1
fi
# 8GB usb min size limit
# todo determine min usb size based on iso size
device_size_limit=$((8 * 1000 * 1000 * 1000))
function help {
echo
echo "Usage: $script_name --iso <pathToIso> --device </dev/sdX> [--poweroff]"
echo
echo "Creates bootable USB stick from HP SPP ISO."
echo " --iso Uses provided ISO file"
echo " --device Use the specified unmounted device as target"
echo " --poweroff Power off system after update"
echo
exit 1
}
# process options
while [[ $# -ge 1 ]]; do
key="$1"
shift
case "$key" in
--poweroff)
poweroff=1
;;
--device)
device="$1"
shift
;;
--iso)
iso="$1"
shift
;;
--help)
help
;;
*)
# unknown
;;
esac
done
if [ -z "$iso" ]; then
_error "Missing path to .iso file."
help
fi
if [[ -z "$device" ]]; then
_error "Missing device."
help
fi
# required cmd line tools
_check_tools syslinux
if ! mbr_bin_path=$(_get_mbr_bin_path); then
exit 1
fi
echo -n "All data on ´$device´ will be deleted, proceed? [y/N] "
read -rn 1 confirm
echo ""
if [ "$confirm" != "y" ]; then
echo ""
exit 1
fi
cleanup() {
_umount "$(_mnt_point "${device}1")"
_umount "$(_mnt_point "${iso}")"
}
execute() {
if ! _exec "$*"; then
handle_code 1
fi
}
handle_code() {
local code="$1"
if [ "$code" -ne 0 ]; then
cleanup
exit 1
fi
}
check_device() {
_log "Check device ´$1´"
local device="$1"
local device_size
device_size=$((512 * $(cat "/sys/block/$(basename "$device")/size")))
if [ "${device_size}" -lt "${device_size_limit}" ]; then
_error "Device is too small. Current: ${device_size} Expected min: ${device_size_limit}"
handle_code 1
fi
}
check_iso_content() {
_log "Check ISO content ´$1´"
local mnt="$1"
if [[ ! -d "$mnt/system" ]] || [[ ! -d "$mnt/usb" ]]; then
_error "Missing system/ or usb/ directory at SPP directory structure. Maybe wrong iso file?"
handle_code 1
fi
}
prepare_device() {
_log "Prepare device ´$1´"
local device="$1"
_log "Create fat32 partition..."
execute "echo -e 'o\nn\np\n1\n\n+7G\na\n1\nw' | fdisk ${device}"
execute "mkfs.vfat ${device}1"
execute "dd conv=notrunc bs=440 count=1 if=\"$mbr_bin_path\" of=${device}"
execute "syslinux -i ${device}1"
}
fill_device() {
_log "Copy data from ´$1´ to ´$2´... may take some time"
local srcMnt="$1"
local trgMnt="$2"
execute "cp -R ${srcMnt}/* ${trgMnt}"
execute "cp ${srcMnt}/system/* ${srcMnt}/usb/syslinux.cfg ${trgMnt}/"
execute "cp $script_path/*.scexe ${trgMnt}/hp/swpackages/"
execute "cp $script_path/*.rpm ${trgMnt}/hp/swpackages/"
# Remove line DEFAULT vesamenu.c32
# vesamenu often fails
execute "sed -i 's/^DEFAULT.*//' ${trgMnt}/syslinux.cfg"
execute "sed -i 's/^TIMEOUT.*/timeout\ 1/i' ${trgMnt}/syslinux.cfg"
if [ "$poweroff" -eq 1 ]; then
execute "sed -i 's/^ONTIMEOUT.*/ONTIMEOUT\ sos_poweroff/i' ${trgMnt}/syslinux.cfg"
fi
}
iso_mnt=$(_mount_iso "$iso")
handle_code $?
check_iso_content "$iso_mnt"
check_device "$device"
prepare_device "$device"
device_mnt=$(_mount_device "${device}1")
handle_code $?
fill_device "$iso_mnt" "$device_mnt"
cleanup
echo "SPP Usb Stick Ready."