Skip to content

Commit bb1816d

Browse files
fix(shellcheck): multios-usb.sh
Signed-off-by: Sebastien Varrette <[email protected]>
1 parent bb66853 commit bb1816d

File tree

1 file changed

+42
-48
lines changed

1 file changed

+42
-48
lines changed

multios-usb.sh

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trap '{
3535

3636
cd "$(dirname "$(readlink -f "$0")")"
3737

38-
echo "Arguments: $*" > $log_file
38+
echo "Arguments: $*" > "${log_file}"
3939

4040
showUsage() {
4141
cat <<- EOF
@@ -138,15 +138,15 @@ if [[ $updateOnly == yes ]]; then
138138
umount_partitions () {
139139
if [ "$manMounted" = true ]; then
140140
sudo umount "$part_data"
141-
rm -rf ${tmpdir}
141+
rm -rf "${tmpdir}"
142142
fi
143143
}
144144

145145
update_config () {
146146
echo -e "\n\e[1;41m++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m"
147147
echo -e "\e[1;41m++ Are you sure you want to update config files? ++\e[0m"
148-
echo -e "\e[1;41m++ All modified files in "config" directory will be removed! ++\e[0m"
149-
echo -e "\e[1;41m++ If you have modified any files, please copy them NOW to the "config_priv" directory. ++\e[0m"
148+
echo -e "\e[1;41m++ All modified files in \"config\" directory will be removed! ++\e[0m"
149+
echo -e "\e[1;41m++ If you have modified any files, please copy them NOW to the \"config_priv\" directory. ++\e[0m"
150150
echo -e "\e[1;41m++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m"
151151
echo -e "\nYour config files version: $currVer"
152152
echo -e "New config files version: $newVer"
@@ -164,12 +164,12 @@ if [[ $updateOnly == yes ]]; then
164164
esac
165165

166166
echo "Updating..."
167-
rm -rf ${part_data}/MultiOS-USB/config
168-
cp -r config ${part_data}/MultiOS-USB
167+
rm -rf "${part_data}/MultiOS-USB/config"
168+
cp -r config "${part_data}/MultiOS-USB"
169169
}
170170

171171
echo -e "\nMultiOS-USB updater"
172-
part_data=$(findmnt -no TARGET ${devp}2) || true
172+
part_data=$(findmnt -no TARGET "${devp}2") || true
173173
if [ -z "$part_data" ]; then
174174
manMounted=true
175175
tmpdir=$(mktemp -d)
@@ -207,7 +207,7 @@ if [[ $updateOnly == yes ]]; then
207207
echo -e "\nConfig files version: $newVer"
208208
else
209209
OLDIFS=$IFS
210-
IFS=. v1=($newVer) v2=($currVer)
210+
IFS=. v1=("$newVer") v2=("$currVer")
211211
IFS=$OLDIFS
212212

213213
for pos in 0 1 2; do
@@ -245,20 +245,14 @@ case "$fs_type" in
245245
esac
246246

247247
# Check for required software
248-
missing_soft="0"
249-
command -v dd &> /dev/null || { echo "dd is required but not installed."; missing_soft="1"; }
250-
command -v tar &> /dev/null || { echo "tar is required but not installed."; missing_soft="1"; }
251-
command -v xz &> /dev/null || { echo "xz is required but not installed."; missing_soft="1"; }
252-
command -v sgdisk &> /dev/null || { echo "sgdisk (gdisk) is required but not installed."; missing_soft="1"; }
253-
command -v wipefs &> /dev/null || { echo "wipefs is required but not installed."; missing_soft="1"; }
254-
command -v mkfs.fat &> /dev/null || { echo "mkfs.fat is required but not installed."; missing_soft="1"; }
255-
if [ "$fs_type" = "fat32" ]; then fs_prog="mkfs.fat"; else fs_prog="mkfs.$fs_type"; fi
256-
command -v $fs_prog &> /dev/null || { echo "$fs_prog is required but not installed."; missing_soft="1"; }
257-
258-
if [ "$missing_soft" -ne 0 ]; then
259-
echo -e "\n\e[0;41mNot all required programs are installed. Exiting...\e[0m\n"
248+
[ "$fs_type" = "fat32" ] && fs_prog="mkfs.fat" || fs_prog="mkfs.$fs_type"
249+
for cmd in dd tar xz sgdisk wipefs "$fs_prog"; do
250+
# shellcheck disable=SC2086
251+
if [ ! -x "$(command -v ${cmd} 2>/dev/null)" ]; then
252+
echo "${cmd} is required but not installed. Exiting"
260253
exit 1
261-
fi
254+
fi
255+
done
262256

263257
# Check for root
264258
if [ "$(id -u)" -ne 0 ]; then
@@ -286,28 +280,28 @@ esac
286280
umount -f "${devp}"* &> /dev/null || true
287281

288282
echo "Creating partitions..."
289-
sgdisk -Z "$dev" &>> $log_file
290-
sgdisk -n 1::"+${efi_size}" -t 1:0700 -c 1:"EFI System" -A 1:set:0 -A 1:set:62 -A 1:set:63 "$dev" &>> $log_file
291-
sgdisk -n 2::"${data_size}" -t 2:"$part_code" -c 2:"$part_name" "$dev" &>> $log_file
283+
sgdisk -Z "$dev" |& tee -a "$log_file"
284+
sgdisk -n 1::"+${efi_size}" -t 1:0700 -c 1:"EFI System" -A 1:set:0 -A 1:set:62 -A 1:set:63 "$dev" |& tee -a "$log_file"
285+
sgdisk -n 2::"${data_size}" -t 2:"$part_code" -c 2:"$part_name" "$dev" |& tee -a "$log_file"
292286

293-
wipefs -af "${devp}1" &>> $log_file
294-
wipefs -af "${devp}2" &>> $log_file
287+
wipefs -af "${devp}1" |& tee -a "$log_file"
288+
wipefs -af "${devp}2" |& tee -a "$log_file"
295289

296290
echo "Formating partitions..."
297-
mkfs.fat -F 16 -n "MultiOS-EFI" "${devp}1" &>> $log_file
291+
mkfs.fat -F 16 -n "MultiOS-EFI" "${devp}1" |& tee -a "$log_file"
298292

299293
case "$fs_type" in
300294
ext2|ext3|ext4)
301-
mkfs.${fs_type} -L "$data_label" "${devp}2" &>> $log_file
295+
mkfs."${fs_type}" -L "$data_label" "${devp}2" |& tee -a "$log_file"
302296
;;
303297
fat32)
304-
mkfs.fat -F 32 -n "$data_label" "${devp}2" &>> $log_file
298+
mkfs.fat -F 32 -n "$data_label" "${devp}2" |& tee -a "$log_file"
305299
;;
306300
exfat)
307-
mkfs.exfat -n "$data_label" "${devp}2" &>> $log_file
301+
mkfs.exfat -n "$data_label" "${devp}2" |& tee -a "$log_file"
308302
;;
309303
ntfs)
310-
mkfs.ntfs --fast -L "$data_label" "${devp}2" &>> $log_file
304+
mkfs.ntfs --fast -L "$data_label" "${devp}2" |& tee -a "$log_file"
311305
;;
312306
*)
313307
echo "Error! $fs_type is an invalid filesystem type."
@@ -320,36 +314,36 @@ part_data="${tmpdir}/part_data"
320314
part_efi="${tmpdir}/part_efi"
321315
mkdir "$part_data" "$part_efi"
322316

323-
mount ${devp}1 $part_efi
324-
mount ${devp}2 $part_data
317+
mount "${devp}1" "$part_efi"
318+
mount "${devp}2" "$part_data"
325319

326320
echo "Copying files..."
327-
mkdir -p $part_data/{MultiOS-USB/tools,ISOs} $part_efi/{EFI/BOOT,grub/fonts}
328-
cp -r config config_priv themes LICENSE README.md MultiOS-USB.version $part_data/MultiOS-USB
329-
cp -r binaries/{syslinux-*,mt86plus_*,efitools-*,wimboot-*,mountiso} $part_data/MultiOS-USB/tools
321+
mkdir -p "$part_data"/{MultiOS-USB/tools,ISOs} "$part_efi"/{EFI/BOOT,grub/fonts}
322+
cp -r config config_priv themes LICENSE README.md MultiOS-USB.version "$part_data/MultiOS-USB"
323+
cp -r binaries/{syslinux-*,mt86plus_*,efitools-*,wimboot-*,mountiso} "$part_data/MultiOS-USB/tools"
330324

331325
echo "Installing bootloader..."
332-
tar -xf binaries/grub-*/i386-pc.tar.xz -C $part_efi/grub
326+
tar -xf binaries/grub-*/i386-pc.tar.xz -C "$part_efi/grub"
333327

334-
cat > $part_efi/grub/grub.cfg << EOF
328+
cat > "$part_efi/grub/grub.cfg" << EOF
335329
search -f /MultiOS-USB/config/grub.config --no-floppy --set=root
336330
source /MultiOS-USB/config/grub.config
337331
EOF
338332

339-
cp binaries/grub-*/grubenv $part_efi/grub
340-
cp -r binaries/grub-*/unicode.pf2 $part_efi/grub/fonts
341-
cp -r binaries/shim-signed_*/*.efi $part_efi/EFI/BOOT
342-
cp binaries/grub-*/grubx64.efi $part_efi/EFI/BOOT
343-
cp -r cert/ $part_efi/EFI/
333+
cp binaries/grub-*/grubenv "$part_efi/grub"
334+
cp -r binaries/grub-*/unicode.pf2 "$part_efi/grub/fonts"
335+
cp -r binaries/shim-signed_*/*.efi "$part_efi/EFI/BOOT"
336+
cp binaries/grub-*/grubx64.efi "$part_efi/EFI/BOOT"
337+
cp -r cert/ "$part_efi/EFI/"
344338

345339
dd conv=fsync status=none if="$part_efi/grub/i386-pc/boot.img" of="${dev}" bs=1 count=446
346340
dd conv=fsync status=none if="$part_efi/grub/i386-pc/core.img" of="${dev}" bs=512 count=2014 seek=34
347341

348-
mv "$log_file" $part_data/MultiOS-USB/install.log
349-
chmod -R o+rw $part_data
342+
mv "$log_file" "$part_data/MultiOS-USB/install.log"
343+
chmod -R o+rw "$part_data"
350344

351345
sync
352-
umount $part_efi
353-
umount $part_data
354-
rm -rf ${tmpdir}
346+
umount "$part_efi"
347+
umount "$part_data"
348+
rm -rf "${tmpdir}"
355349
echo -e "\n\e[0;42mMultiOS-USB has been successfully installed.\e[0m\n"

0 commit comments

Comments
 (0)