Debian Codegraph @

scripts/sbin/drbl-prepare-memtest

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: prepare the memtest86+ by using the files on the system or download and extract the required programs for DRBL.
5 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
6
7 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
8 [scip-shell system . . `[`. -e /etc/drbl/drbl-ocs.confscip-shell filesystem . . `/etc/drbl/drbl-ocs.conf`. ] && . /etc/drbl/drbl-ocs.confscip-shell source . . `/etc/drbl/drbl-ocs.conf`.
9 [scip-shell system . . `[`. -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions
10
11 # Local settings
12 # By default we only copy the required files to $pxelinux_binsrc_dir. This option will allow us to copy files to dir $pxecfg_pd.
13 deploy_to_system_too="no"
14
15 # Functions
16 USAGEscip-shell shell shell-project 0.0.0 USAGE().() {
17 echoscip-shell system . . echo. "Put the memtest86+ files in DRBL package repository"
18 echoscip-shell system . . echo. "Usage: $0 [OPTION]"
19 echoscip-shell system . . echo. "OPTION:"
20 echoscip-shell system . . echo. "-u, --from-upstream Use the binary from upstream ($MEMTEST86_URL). If this option is not assigned, DRBL will try to use the memtest86+ from your GNU/Linux distribution."
21 echoscip-shell system . . echo. "-mv, --memtest86-version VERSION The memtest86+ version to be used with -u|--from-upstream. If not assigned, the version number specified in drbl.conf will be used."
22 echoscip-shell system . . echo. "-d, --deploy-to-system-too Deploy the file to DRBL system ($pxecfg_pd), too."
23 echoscip-shell system . . echo. "Ex: To use the memtest86+ 4.20 from $MEMTEST86_URL, run '$0 -u -mv 4.20'"
24 }
25
26 #
27 put_memtest_bin_2_drbl_reposcip-shell shell shell-project 0.0.0 put_memtest_bin_2_drbl_repo().() {
28 local memtest_bin_abs_path="$1"
29 [scip-shell system . . `[`. -z "$memtest_bin_abs_path" ] && return 1
30 echoscip-shell system . . echo. "Putting memtest86+ in DRBL package repository $memtest86_dir/... "
31 memtest_f="$(shorten_memtest_filename `basenamescip-shell system . . basename. $memtest_bin_abs_path`)"
32 cpscip-shell system . . cp. -af $memtest_bin_abs_path $memtest86_dir/$memtest_f
33 memtest_v="$(LC_ALL=C stringsscip-shell system . . strings. $memtest_bin_abs_path | grepscip-shell system . . grep. -Ei 'Memtest86\+[[:space:]]+v' |\
34 sed -r -e "s/^[[:space:]]*//g" | sort | head -n 1)"
35 echoscip-shell system . . echo. "Memtest86+ version: $memtest_v"
36 echoscip-shell system . . echo. $memtest_v > $memtest86_dir/VERSION
37 echoscip-shell system . . echo. "done!"
38 if [scip-shell system . . `[`. "$deploy_to_system_too" = "yes" ]; then
39 echoscip-shell system . . echo. -n "Putting memtest86+ in DRBL system dir $pxecfg_pd/... "
40 cpscip-shell system . . cp. -af $memtest_f $pxecfg_pd/
41 echoscip-shell system . . echo. $memtest_v > $pxecfg_pd/MEMTEST86+_VERSION
42 echoscip-shell system . . echo. "done!"
43 fi
44 } # end of put_memtest_bin_2_drbl_repo
45
46 #
47 put_upstream_memtestscip-shell shell shell-project 0.0.0 put_upstream_memtest().(){
48 # Function to use the upstream binary directly
49 local ver="$1"
50 if [scip-shell system . . `[`. -z "$ver" ]; then
51 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
52 echoscip-shell system . . echo. "No upstream memtest version was assigned. Program terminated."
53 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
54 USAGEscip-shell shell shell-project 0.0.0 USAGE().
55 exit 1
56 fi
57 memfile="memtest86+-${ver}.bin"
58 tmp_wd="$(LC_ALL=C mktempscip-shell system . . mktemp. -d /tmp/memtest_tmp.XXXXXXXscip-shell filesystem . . `/tmp/memtest_tmp.XXXXXXX`.)"
59 echoscip-shell system . . echo. -n "Downloading ${ver} memtest86+ files from $MEMTEST86_URL... "
60 LC_ALL=C wget $wget_opt -P $tmp_wd $MEMTEST86_URL/$ver/$memfile
61 echoscip-shell system . . echo. "done!"
62 put_memtest_bin_2_drbl_reposcip-shell shell shell-project 0.0.0 put_memtest_bin_2_drbl_repo(). $tmp_wd/$memfile
63 if [scip-shell system . . `[`. -d "$tmp_wd" -a -n "$(echoscip-shell system . . echo. "$tmp_wd" | grepscip-shell system . . grep. -i memtest_tmp)" ]; then
64 rmscip-shell system . . rm. -rf $tmp_wd
65 fi
66 } # end of put_upstream_memtest
67 #
68 shorten_memtest_filenamescip-shell shell shell-project 0.0.0 shorten_memtest_filename().() {
69 local inp_fn="$1"
70 # memtest86+.bin -> mt86+x32.mbr
71 # memtest86+x32.bin -> mt86+x32.mbr
72 # memtest86+x32.efi -> mt86+x32.efi
73 # memtest86+ia32.bin -> mt86+x32.mbr
74 # memtest86+ia32.efi -> mt86+x32.efi
75 # memtest86+x64.bin -> mt86+x64.mbr
76 # memtest86+x64.efi -> mt86+x64.efi
77 case "$inp_fn" in
78 memtest86+.bin) echoscip-shell system . . echo. mt86+x32.mbr;;
79 memtest86+x32.bin) echoscip-shell system . . echo. mt86+x32.mbr;;
80 memtest86+x32.efi) echoscip-shell system . . echo. mt86+x32.efi;;
81 memtest86+ia32.bin) echoscip-shell system . . echo. mt86+x32.mbr;;
82 memtest86+ia32.efi) echoscip-shell system . . echo. mt86+x32.efi;;
83 memtest86+x64.bin) echoscip-shell system . . echo. mt86+x64.mbr;;
84 memtest86+x64.efi) echoscip-shell system . . echo. mt86+x64.efi;;
85 *) echoscip-shell system . . echo. $inp_fn;;
86 esac
87 } # end of shorten_memtest_filename
88 #
89 put_distribution_memtestscip-shell shell shell-project 0.0.0 put_distribution_memtest().() {
90 # Function to use the package from distribution.
91 # Memtest86+ file name on different distributions:
92 # Debian/Ubuntu
93 # <= v7.2: /boot/memtest86+x64.bin, /boot/memtest86+x64.efi;
94 # >= v8.0: /boot/mt86+ia32, /boot/mt86+x64 (Unified Binary, no longer separate .bin (Legacy) and .efi (UEFI) files
95 # i.e., a single binary for both UEFI and legacy boot.)
96 # SuSE: "memtest.bin"
97 # Fedora 14: "/boot/memtest86+"
98 # Centos 5.6: "/boot/memtest86+-1.65"
99 if $query_pkglist_exist_cmd memtest86+ &>/dev/nullscip-shell filesystem . . `/dev/null`.; then
100 # Found on the system
101 # For Redhat-like system, there might return more than one file on a system, i.e. one file belongs to 2 rpm packages.
102 # 2022/11/23, 2023/05/17 On Debian, memtest86+ v6 is available:
103 # /boot/memtest86+x32.bin
104 # /boot/memtest86+x32.efi
105 # /boot/memtest86+ia32.bin (For newer package)
106 # /boot/memtest86+ia32.efi (For newer package)
107 # /boot/memtest86+x64.bin
108 # /boot/memtest86+x64.efi
109 # While for memtest86+ <= v5, the file is:
110 # /boot/memtest86+.bin
111
112 # For syslinux in FAT file system,
113 # "memtest86+.bin" is 9 characters, will go wrong when it's FAT (usb flash drive). We use memtest to overwrite the one comes from Debian live.
114 # In addition, do NOT use memtest.bin, use memtest instead of memtest.bin
115 # since "*.bin" has specially purpose for syslinux.
116 # So here they are:
117 # memtest86+.bin -> mt86+x32.mbr
118 # memtest86+x32.bin -> mt86+x32.mbr
119 # memtest86+x32.efi -> mt86+x32.efi
120 # memtest86+ia32.bin -> mt86+x32.mbr
121 # memtest86+ia32.efi -> mt86+x32.efi
122 # memtest86+x64.bin -> mt86+x64.mbr
123 # memtest86+x64.efi -> mt86+x64.efi
124
125 # For memtest <= v5.0
126 memtest_bin="$(LC_ALL=C $query_pkglist_cmd memtest86+ | grepscip-shell system . . grep. -Ew "(memtest86\+.bin$|memtest\.bin$|^/boot/memtest86+)" | sortscip-shell system . . sort. | headscip-shell system . . head. -n 1)"
127 # For memtest >= v6.0
128 memtest_x32_bin="$(LC_ALL=C $query_pkglist_cmd memtest86+ | grepscip-shell system . . grep. -Ew "^/boot/memtest86\+x32\.bin" | sortscip-shell system . . sort. | headscip-shell system . . head. -n 1)"
129 memtest_x32_efi="$(LC_ALL=C $query_pkglist_cmd memtest86+ | grepscip-shell system . . grep. -Ew "^/boot/memtest86\+x32\.efi" | sortscip-shell system . . sort. | headscip-shell system . . head. -n 1)"
130 memtest_x32_bin="$(LC_ALL=C $query_pkglist_cmd memtest86+ | grepscip-shell system . . grep. -Ew "^/boot/memtest86\+ia32\.bin" | sortscip-shell system . . sort. | headscip-shell system . . head. -n 1)"
131 memtest_x32_efi="$(LC_ALL=C $query_pkglist_cmd memtest86+ | grepscip-shell system . . grep. -Ew "^/boot/memtest86\+ia32\.efi" | sortscip-shell system . . sort. | headscip-shell system . . head. -n 1)"
132 memtest_x64_bin="$(LC_ALL=C $query_pkglist_cmd memtest86+ | grepscip-shell system . . grep. -Ew "^/boot/memtest86\+x64\.bin" | sortscip-shell system . . sort. | headscip-shell system . . head. -n 1)"
133 memtest_x64_efi="$(LC_ALL=C $query_pkglist_cmd memtest86+ | grepscip-shell system . . grep. -Ew "^/boot/memtest86\+x64\.efi" | sortscip-shell system . . sort. | headscip-shell system . . head. -n 1)"
134 # For memtest >= v8.0
135 memtest_x64="$(LC_ALL=C $query_pkglist_cmd memtest86+ | grepscip-shell system . . grep. -Ew "^/boot/mt86\+x64$" | sortscip-shell system . . sort. | headscip-shell system . . head. -n 1)"
136 for im in $memtest_x64 $memtest_bin $memtest_x32_bin $memtest_x32_efi $memtest_x64_bin $memtest_x64_efi; do
137 eval imfile="\$im"
138 if [scip-shell system . . `[`. -n "$imfile" ]; then
139 echoscip-shell system . . echo. "Found $imfile in this system, copying the memtest file to DRBL local repository..."
140 put_memtest_bin_2_drbl_reposcip-shell shell shell-project 0.0.0 put_memtest_bin_2_drbl_repo(). $imfile
141 else
142 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
143 echoscip-shell system . . echo. "Package of memtest was installed, but memtest boot file not found!"
144 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
145 fi
146 done
147 else
148 # Download and extract it. The reason we do not install it is we do not want to bother the server's boot menu
149 tmp_wd="$(LC_ALL=C mktempscip-shell system . . mktemp. -d /tmp/memtest_tmp.XXXXXXXscip-shell filesystem . . `/tmp/memtest_tmp.XXXXXXX`.)"
150 echoscip-shell system . . echo. "Trying to download memtest86+ from distribution repository..."
151 if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
152 # Debian
153 # The binary for memtest86+ in Debian Squeeze: /boot/memtest86+.bin
154 # Clean all stale deb files in the cache dir. Otherwise there might be some old version of debs exist in the cache dir.
155 LC_ALL=C apt-getscip-shell system . . apt-get. clean
156 LC_ALL=C apt-getscip-shell system . . apt-get. -d --reinstall install memtest86+
157 (
158 cd $tmp_wd
159 LC_ALL=C dpkgscip-shell system . . dpkg. --extract /var/cache/apt/archives/memtest86+*.deb .
160 if [scip-shell system . . `[`. -e "$(pwdscip-shell system . . pwd.)/boot/mt86+x64" ]; then
161 put_memtest_bin_2_drbl_reposcip-shell shell shell-project 0.0.0 put_memtest_bin_2_drbl_repo(). "$(pwdscip-shell system . . pwd.)"/boot/mt86+x64
162 elif [scip-shell system . . `[`. -e "$(pwdscip-shell system . . pwd.)/boot/memtest86+64.bin" ]; then
163 put_memtest_bin_2_drbl_reposcip-shell shell shell-project 0.0.0 put_memtest_bin_2_drbl_repo(). "$(pwdscip-shell system . . pwd.)"/boot/memtest86+x64.bin
164 elif [scip-shell system . . `[`. -e "$(pwdscip-shell system . . pwd.)/boot/memtest86+64.efi" ]; then
165 put_memtest_bin_2_drbl_reposcip-shell shell shell-project 0.0.0 put_memtest_bin_2_drbl_repo(). "$(pwdscip-shell system . . pwd.)"/boot/memtest86+x64.efi
166 fi
167 )
168 elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then
169 # SuSE
170 # The binary for memtest86+ in openSuse 11.3 is: /boot/memtest.bin
171 LC_ALL=C zypper install -d -f -y memtest86+
172 memtest86_rpm="$(LC_ALL=C findscip-shell system . . find. /var/cache/zypp/packages/scip-shell filesystem . . `/var/cache/zypp/packages/`. -name "memtest86+-*.rpm" -print)"
173 memtest_bin="$(LC_ALL=C rpm -qpl "$memtest86_rpm" | grepscip-shell system . . grep. -Ew "memtest.bin$")"
174 (
175 cd $tmp_wd
176 LC_ALL=C rpm2cpio "$memtest86_rpm" | cpio -idm
177 put_memtest_bin_2_drbl_reposcip-shell shell shell-project 0.0.0 put_memtest_bin_2_drbl_repo(). "$(pwdscip-shell system . . pwd.)"/$memtest_bin
178 )
179 else
180 # RH-like
181 # The binary for memtest86+ in Fedora 14 is: /boot/memtest86+-4.10
182 LC_ALL=C yumdownloader --destdir $tmp_wd memtest86+
183 memtest_bin="$(LC_ALL=C rpm -qpl "$tmp_wd/memtest86*.rpm" | grepscip-shell system . . grep. -Ew "^/boot/memtest86+")"
184 (
185 cd $tmp_wd
186 LC_ALL=C rpm2cpio $tmp_wd/memtest86*.rpm | cpio -idm
187 put_memtest_bin_2_drbl_reposcip-shell shell shell-project 0.0.0 put_memtest_bin_2_drbl_repo(). "$(pwdscip-shell system . . pwd.)"/$memtest_bin
188 )
189 fi
190 if [scip-shell system . . `[`. -d "$tmp_wd" -a -n "$(LC_ALL=C echoscip-shell system . . echo. "$tmp_wd" | grepscip-shell system . . grep. -i memtest_tmp)" ]; then
191 rmscip-shell system . . rm. -rf $tmp_wd
192 fi
193 fi
194 } # end of put_distribution_memtest
195
196 ############
197 ### MAIN ###
198 ############
199
200 check_if_root
201 ask_and_load_lang_set
202
203 #
204 while [scip-shell system . . `[`. $# -gt 0 ]; do
205 case "$1" in
206 -u|--from-upstream) shift; mode="from-upstream" ;;
207 -mv|--memtest86-version)
208 shift;
209 if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then
210 # skip the -xx option, in case
211 memtest_ver_requested="$1"
212 [scip-shell system . . `[`. -z "$memtest_ver_requested" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1
213 shift
214 fi
215 ;;
216 -d|--deploy-to-system-too) shift; deploy_to_system_too="yes" ;;
217 *) USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 ;;
218 esac
219 done
220
221 # Check arch
222 cpu_arch="$(LC_ALL=C unamescip-shell system . . uname. -m)"
223 if [scip-shell system . . `[`. "$cpu_arch" != "i686" -a "$cpu_arch" != "x86_64" ]; then
224 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
225 echoscip-shell system . . echo. "CPU arch is not i386/i686 or x86_64!"
226 echoscip-shell system . . echo. "Skipping preparing memtest+!"
227 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
228 echoscip-shell system . . echo. "$msg_program_stop"
229 exit 3
230 fi
231
232 # mode is essential
233 [scip-shell system . . `[`. -z "$mode" ] && mode="from-distribution"
234 [scip-shell system . . `[`. -z "$memtest_ver_requested" ] && memtest_ver_requested="$MEMTEST86_VER_DEF"
235
236 case "$mode" in
237 from-distribution) put_distribution_memtestscip-shell shell shell-project 0.0.0 put_distribution_memtest(). ;;
238 from-upstream) put_upstream_memtestscip-shell shell shell-project 0.0.0 put_upstream_memtest(). $memtest_ver_requested ;;
239 esac
240
241 exit 0