diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd6bf4cd..1b1c1dc4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,4 +18,19 @@ jobs: run: DEBIAN_FRONTEND=noninteractive sudo apt-get install -yq --no-install-recommends build-essential debhelper dh-python dpkg-dev python3 python3-distutils-extra po-debconf pyflakes3 lsb-release gnu-efi - name: Build package run: dpkg-buildpackage --no-sign - + pre-commit: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Refresh dependencies + run: sudo apt update + - name: Install dependencies + run: sudo apt install shellcheck -y + - name: Run pre-commit hooks + run: | + ./contrib/setup + source venv/bin/activate + sed -i "/no-commit-to-branch/,+1d" .pre-commit-config.yaml + pre-commit run --all-files diff --git a/.gitignore b/.gitignore index d475a73f..c82411d7 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ debian/files debian/tmp/ secure_boot/MokSBStateSet.efi .vscode +/venv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..08b899ab --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: +- repo: local + hooks: + - id: shellcheck + name: check shellscript style + language: system + entry: shellcheck -e SC1091 + types: [shell] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..6d775c6a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,13 @@ +# Contributor Guidelines + +## Getting started + +To set up your local environment, from the top level of the checkout run + +`./contrib/setup` + +This will create pre-commit hooks to fixup many code style issues +before your code is submitted. + +On some Linux distributions this will install all build dependencies +needed to compile fwupd as well. diff --git a/README.md b/README.md index bf7d00c3..7d9b5e85 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Dell Recovery Media Creator ----- +# Dell Recovery Media Creator + [![Build Status](https://travis-ci.org/dell/dell-recovery.png)](https://travis-ci.org/dell/dell-recovery) The Dell Recovery media creation tool supports two different usage modes, @@ -8,39 +8,43 @@ create an image from an existing recovery partition with no customizations. In builder mode, the tool allows modifying the source of the base image, the source of the framework, as well as injection of additional content. -# Tool Modes +## Tool Modes + +### End User Mode -End User Mode ---- When a customer receives a Dell machine that has been factory shipped with Linux, there will be an icon available in GNOME shell to launch this tool. They will be prompted for what type of media they would like to create. -Out of box experience mode ---- +### Out of box experience mode + If a DVD burner or USB port is found on the machine, customers will be offered to create media at the end of the out of box experience. -Media builder mode ---- -In builder mode, the user will be offered a variety of options that allow them to create ISOs based upon +### Media builder mode + +In builder mode, the user will be offered a variety of options that allow them +to create ISOs based upon different snapshots of release upon standard Ubuntu media. -The latest information on how to use builder mode will be documented within the integrated help dialog. +The latest information on how to use builder mode will be documented within the +integrated help dialog. -# Flow +## Flow -Due to the nature of including a recovery partition, the installation flow varies from the standard Ubuntu +Due to the nature of including a recovery partition, the installation flow +varies from the standard Ubuntu installation. It is further documented [here](installation_flow.md). -Ubiquity ---- -Dell recovery is built with an integrated Ubiquity plugin. It is branched with each Ubuntu LTS release and -has code that will tightly integrate with Ubiquity for factory installation. Documentation for all of the -features in Ubiquity mode and how to create packages to support it are stored outside of the dell-recovery -tree. +### Ubiquity + +Dell recovery is built with an integrated Ubiquity plugin. It is branched with +each Ubuntu LTS release and has code that will tightly integrate with Ubiquity +for factory installation. Documentation for all of the features in Ubiquity +mode and how to create packages to support it are stored outside of the +dell-recovery tree. + +### Modifying a factory image -Modifying a factory image ---- Information about how to modify a factory image are available [here](modifying_factory_image.md). diff --git a/casper/hooks/dell-bootstrap b/casper/hooks/dell-bootstrap index feae5ece..c54b8a26 100755 --- a/casper/hooks/dell-bootstrap +++ b/casper/hooks/dell-bootstrap @@ -18,15 +18,15 @@ esac . /usr/share/initramfs-tools/hook-functions -cp /usr/share/dell/scripts/pool.sh $DESTDIR/scripts -if [ ! -f $DESTDIR/scripts/casper-bottom/99dell_bootstrap ]; then - cp /usr/share/dell/casper/scripts/99dell_bootstrap $DESTDIR/scripts/casper-bottom +cp /usr/share/dell/scripts/pool.sh "$DESTDIR"/scripts +if [ ! -f "$DESTDIR"/scripts/casper-bottom/99dell_bootstrap ]; then + cp /usr/share/dell/casper/scripts/99dell_bootstrap "$DESTDIR"/scripts/casper-bottom fi #invoked from dell-recovery if [ -n "$INJECT" ]; then - if ! grep 99dell_bootstrap $DESTDIR/scripts/casper-bottom/ORDER >/dev/null; then - cat >> $DESTDIR/scripts/casper-bottom/ORDER << EOF + if ! grep 99dell_bootstrap "$DESTDIR"/scripts/casper-bottom/ORDER >/dev/null; then + cat >> "$DESTDIR"/scripts/casper-bottom/ORDER << EOF /scripts/casper-bottom/99dell_bootstrap "\$@" [ -e /conf/param.conf ] && . /conf/param.conf EOF diff --git a/casper/scripts/99dell_bootstrap b/casper/scripts/99dell_bootstrap index 09af940e..40071cd2 100755 --- a/casper/scripts/99dell_bootstrap +++ b/casper/scripts/99dell_bootstrap @@ -61,19 +61,19 @@ elif [ -e /root/isodevice/scripts/emergency.sh ]; then fi if [ -d /root/isodevice ]; then - if [ -f /root/isodevice/.disk/info.recovery -a ! -f /root/isodevice/.disk/info ]; then + if [ -f /root/isodevice/.disk/info.recovery ] && [ ! -f /root/isodevice/.disk/info ]; then mount -o remount,rw /root/isodevice cp /root/isodevice/.disk/info.recovery /root/isodevice/.disk/info mount -o remount,ro /root/isodevice fi -elif [ -f /root/cdrom/.disk/info.recovery -a ! -f /root/cdrom/.disk/info ]; then +elif [ -f /root/cdrom/.disk/info.recovery ] && [ ! -f /root/cdrom/.disk/info ]; then mount -o remount,rw /root/cdrom cp /root/cdrom/.disk/info.recovery /root/cdrom/.disk/info mount -o remount,ro /root/cdrom fi #Force ubiquity to run in automatic regardless if there are ubiquity options in /proc/cmdline (except single user mode) -if ! grep -q "single" /proc/cmdline 2>&1 >/dev/null; then +if ! grep -q "single" /proc/cmdline >/dev/null 2>&1; then sed -i "s/ubiquity=\$/ubiquity=1/; s/\$automatic\ \$choose/--automatic/" /root/etc/init/ubiquity.conf fi #if they use a ubiquity icon it needs to run in automatic @@ -134,7 +134,7 @@ ln -s /dev/null /root/etc/systemd/system/snapd.service KERNELS=$(find /root/cdrom/kernel -maxdepth 1 -type d 2>/dev/null | sed "s,/root,,; /\/cdrom\/kernel\/$/d") if [ -n "$KERNELS" ]; then for KERNEL in $KERNELS; do - ln -s $KERNEL /root/lib/modules + ln -s "$KERNEL" /root/lib/modules done fi @@ -143,12 +143,14 @@ rm -f /root/var/cache/debconf/*.dat-old # Later emergency installer fixes if [ -d /root/cdrom/scripts/emergency-scripts ]; then + # shellcheck source=/dev/null for script in /root/cdrom/scripts/emergency-scripts/[0-9]*; do - . $script + . "$script" done elif [ -d /root/isodevice/scripts/emergency-scripts ]; then + # shellcheck source=/dev/null for script in /root/isodevice/scripts/emergency-scripts/[0-9]*; do - . $script + . "$script" done fi diff --git a/contrib/setup b/contrib/setup new file mode 100755 index 00000000..d4ba8f8b --- /dev/null +++ b/contrib/setup @@ -0,0 +1,19 @@ +#!/bin/bash -e +# Setup the repository. + +cd "$(dirname "$0")/.." + +DEPS=shellcheck +OS=$(python3 -c "import distro; print(distro.linux_distribution()[0].split()[0].lower())") +if [ "$OS" = "ubuntu" ]; then + if ! python3 -c "import venv"; then + DEPS="python3-venv" + fi + sudo apt install $DEPS +fi + +python3 -m venv venv +source venv/bin/activate + +python3 -m pip install pre-commit +pre-commit install diff --git a/debian/dell-recovery-bootloader.postrm b/debian/dell-recovery-bootloader.postrm index 28853fb6..a24b8ce9 100644 --- a/debian/dell-recovery-bootloader.postrm +++ b/debian/dell-recovery-bootloader.postrm @@ -6,7 +6,7 @@ if [ "$1" = "purge" ]; then TARGET=/var/lib/dell-recovery FILES="boot.img core.img grub.cfg grubenv grubx64.efi grub-setup.exe" for file in $FILES; do - rm -f $TARGET/$file + rm -f $TARGET/"$file" done rm -rf $TARGET/iso fi diff --git a/grub/99_dell_recovery b/grub/99_dell_recovery index 669690e6..4547e2c1 100755 --- a/grub/99_dell_recovery +++ b/grub/99_dell_recovery @@ -2,7 +2,7 @@ source /usr/lib/grub/grub-mkconfig_lib -cat << EOF +cat << 'EOF' menuentry "#RECOVERY_TEXT#" { search --no-floppy --hint '(hd0,#PARTITION#)' --set --fs-uuid #UUID# set uuid_options="uuid=#UUID#" diff --git a/installation_flow.md b/installation_flow.md index aed27c98..8237ead7 100644 --- a/installation_flow.md +++ b/installation_flow.md @@ -1,60 +1,94 @@ -Although the installer for Dell recovery media is the same as standard Ubuntu (*ubiquity*), the installation flow varies. +# Installation Flow -# Standard Ubuntu installation -A standard Ubuntu installation from a USB key only has one installation *phase*. The user is prompted for installation options such as disk, timezone, keyboard and username and installation runs in the background. +Although the installer for Dell recovery media is the same as standard Ubuntu +(*ubiquity*), the installation flow varies. -When the install is complete, upon rebooting the machine they are brought to a Ubuntu login screen and can use the computer. +## Standard Ubuntu installation -# *Standard* OEM installation -A standard OEM Ubuntu installation will be preseeded to operate in an automated fashion. Any questions that are not answered in the preseeding process will be prompted by the GUI. After installation is finished, the system will either be shut down or rebooted into **OEM-Config mode**. +A standard Ubuntu installation from a USB key only has one installation *phase*. + The user is prompted for installation options such as disk, timezone, keyboard + and username and installation runs in the background. -In **OEM-Config mode** the user will be prompted for questions that might not be the same as those preseeded. For example, Keyboard layout, Timezone or Language. +When the install is complete, upon rebooting the machine they are brought to a +Ubuntu login screen and can use the computer. + +## *Standard* OEM installation + +A standard OEM Ubuntu installation will be preseeded to operate in an automated +fashion. Any questions that are not answered in the preseeding process will be +prompted by the GUI. After installation is finished, the system will either be +shut down or rebooted into **OEM-Config mode**. + +In **OEM-Config mode** the user will be prompted for questions that might not be + the same as those preseeded. For example, Keyboard layout, Timezone or + Language. After completing OEM-Config, the user is brought to an Ubuntu login screen. -# Dell OEM installation +## Dell OEM installation + The Dell OEM installation is split across ***three** distinct phases*. -It is split this way to be able to support an archicture with a factory recovery partition on the hard disk. -This factory recovery partition is used both for Dell manufacturing as well as for customer based recovery. +It is split this way to be able to support an archicture with a factory recovery + partition on the hard disk. +This factory recovery partition is used both for Dell manufacturing as well as +for customer based recovery. + +### Phase 1: Prepare partitions and content + +The first phase prepares the disk and loads the recovery partition content onto +it. This can be approached from 3 different methods. -## Phase 1: Prepare partitions and content -The first phase prepares the disk and loads the recovery partition content onto it. This can be approached from 3 different methods. +#### Dell factory -### Dell factory +1. In the Dell factory we integrate with existing manufacturing tools, and these + tools create initial partition layout (ESP and Recovery partition) and load the + content onto the disk. -1. In the Dell factory we integrate with existing manufacturing tools, and these tools create initial partition layout (ESP and Recovery partition) and load the content onto the disk. +2. Other manufacturing tools also configure next boot (`BootOrder`/`BootNext` + variables) +3. Other manufacturing tools control reboot cycle. +4. On the next boot we’ll boot directly into phase 2. -2. Other manufacturing tools also configure next boot (`BootOrder`/`BootNext` variables) -3. Other manufacturing tools control reboot cycle. -4. On the next boot we’ll boot directly into phase 2. +#### Customer USB recovery -### Customer USB recovery +1. If customer boots up USB recovery disk, it will come to a prompt selecting +which disk to use to install to. +2. Customer presses next, and disk is wiped, content copied to ESP and recovery + partition +3. Boot variables set for next boot +4. System automatically reboots into phase 2. -1. If customer boots up USB recovery disk, it will come to a prompt selecting which disk to use to install to. -2. Customer presses next, and disk is wiped, content copied to ESP and recovery partition -3. Boot variables set for next boot -4. System automatically reboots into phase 2. +#### Customer HDD recovery -### Customer HDD recovery +1. GUI tool is offered in OS that will change grub next boot option to a recove +ry option we left to boot recovery partition. +2. Customer can also interrupt GRUB silent menu to select this option. +3. Customer agrees to wipe content. +4. System continues to phase 2. -1. GUI tool is offered in OS that will change grub next boot option to a recovery option we left to boot recovery partition. -2. Customer can also interrupt GRUB silent menu to select this option. -3. Customer agrees to wipe content. -4. System continues to phase 2. +### Phase 2: Install Ubuntu +This part of the installation is fully automated. The OS is booted from the rec +overy partition and the Ubiquity installer will launch. -## Phase 2: Install Ubuntu -This part of the installation is fully automated. The OS is booted from the recovery partition and the Ubiquity installer will launch. +Ubiquity will create additional partitions to install into, and all files will +be copied in. Any applicable drivers and updated packages distributed in +`/debs` of the recovery partition will be installed by Ubiquity and +dell-recovery plugins. -Ubiquity will create additional partitions to install into, and all files will be copied in. Any applicable drivers and updated packages distributed in `/debs` of the recovery partition will be installed by Ubiquity and dell-recovery plugins. +After Ubiquity finishes, a set of post-install scripts provided by Dell in the +`/scripts` directory of the recovery partition will run to complete the install. -After Ubiquity finishes, a set of post-install scripts provided by Dell in the `/scripts` directory of the recovery partition will run to complete the install. +When this phase is run during manufacturing, the system will return to Dell +manufacturing process. -When this phase is run during manufacturing, the system will return to Dell manufacturing process. +### Phase 3: Out of box experience -## Phase 3: Out of box experience -In a Dell manufactured machine, this is the first phase that a customer will actually see. +In a Dell manufactured machine, this is the first phase that a customer will +actually see. -As with standard OEM installation, the customer will select the Language, Timezone, Keyboard Layout, a username and a password. +As with standard OEM installation, the customer will select the Language, +Timezone, Keyboard Layout, a username and a password. -However specific to the Dell OEM install an additional page will prompt to create USB recovery media to use in the event of a failure. +However specific to the Dell OEM install an additional page will prompt to +create USB recovery media to use in the event of a failure. diff --git a/late/chroot_scripts/02-grub.sh b/late/chroot_scripts/02-grub.sh index b69365cc..e7ccaaeb 100755 --- a/late/chroot_scripts/02-grub.sh +++ b/late/chroot_scripts/02-grub.sh @@ -23,6 +23,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. +# shellcheck disable=SC2240 . /usr/share/dell/scripts/fifuncs "" IFHALT "Rerun GRUB update" diff --git a/late/chroot_scripts/03-ubuntu-drivers.sh b/late/chroot_scripts/03-ubuntu-drivers.sh index 0b979d19..eda3047b 100755 --- a/late/chroot_scripts/03-ubuntu-drivers.sh +++ b/late/chroot_scripts/03-ubuntu-drivers.sh @@ -6,8 +6,9 @@ export DEBIAN_FRONTEND=noninteractive IFHALT "Run ubuntu-drivers autoinstall" echo 'APT::Get::AllowUnauthenticated "true";' > /etc/apt/apt.conf.d/99disable_authentication -for blacklist in $(find /cdrom/scripts/chroot-scripts/blacklist /isodevice/scripts/chroot-scripts/blacklist -type f 2>/dev/null); do - UBUNTU_DRIVERS_BLACKLIST="$UBUNTU_DRIVERS_BLACKLIST $(cat $blacklist)" +LIST=$(find /cdrom/scripts/chroot-scripts/blacklist /isodevice/scripts/chroot-scripts/blacklist -type f 2>/dev/null) +for blacklist in $LIST; do + UBUNTU_DRIVERS_BLACKLIST="$UBUNTU_DRIVERS_BLACKLIST $(cat "$blacklist")" done if [ -n "$UBUNTU_DRIVERS_BLACKLIST" ]; then echo "UBUNTU_DRIVERS_BLACKLIST: $UBUNTU_DRIVERS_BLACKLIST" diff --git a/late/chroot_scripts/04-disable-hibernate.sh b/late/chroot_scripts/04-disable-hibernate.sh index 552a080d..7dd8c925 100755 --- a/late/chroot_scripts/04-disable-hibernate.sh +++ b/late/chroot_scripts/04-disable-hibernate.sh @@ -3,7 +3,7 @@ # Disable hibernate (S4) if RAM >= 4GB. (LP: #1284474) for i in $(dmidecode -t 17 | grep Size | cut -d ':' -f 2 | cut -d ' ' -f 2); do - memsize=$((${memsize:-0} + $i)) + memsize=$((${memsize:-0} + i)) done if [ ${memsize:-0} -ge 4096 ]; then diff --git a/late/chroot_scripts/05-enable-oem-config.sh b/late/chroot_scripts/05-enable-oem-config.sh index 0856e0e6..58531afb 100755 --- a/late/chroot_scripts/05-enable-oem-config.sh +++ b/late/chroot_scripts/05-enable-oem-config.sh @@ -23,6 +23,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. +# shellcheck disable=SC2240 . /usr/share/dell/scripts/fifuncs "" IFHALT "Enable oem-config" diff --git a/late/chroot_scripts/95-set_UTC_TZ.sh b/late/chroot_scripts/95-set_UTC_TZ.sh index 5336d10a..03712952 100755 --- a/late/chroot_scripts/95-set_UTC_TZ.sh +++ b/late/chroot_scripts/95-set_UTC_TZ.sh @@ -33,10 +33,10 @@ # the time offset for ICC tz_offset.py was adjusted # from 5:30 to 5 # ==== Do we need to change this??? - -for arg in $(cat /proc/cmdline); do - if echo $arg | grep "MFGSITE=" 2>&1 >/dev/null; then - SITE=$(echo $arg | cut -d'=' -f2) +ARGLIST=$(cat /proc/cmdline) +for arg in $ARGLIST; do + if echo "$arg" | grep "MFGSITE=" > /dev/null 2>&1; then + SITE=$(echo "$arg" | cut -d'=' -f2) fi done diff --git a/late/scripts/CLEANUP-SCRIPT b/late/scripts/CLEANUP-SCRIPT index e7e78003..dd24279c 100755 --- a/late/scripts/CLEANUP-SCRIPT +++ b/late/scripts/CLEANUP-SCRIPT @@ -22,10 +22,9 @@ # MA 02110-1301, USA. #check the /mnt mount point -mount | grep "/mnt" 2>/dev/null -if [ $? -eq 0 ];then +if mount | grep -q "/mnt" 2>/dev/null;then umount /mnt fi #revert the mount points -mount -o remount,$MOUNT_PROPERTY /cdrom +mount -o remount,"$MOUNT_PROPERTY" /cdrom diff --git a/late/scripts/FAIL-SCRIPT b/late/scripts/FAIL-SCRIPT index b8d14b18..4e4380f7 100755 --- a/late/scripts/FAIL-SCRIPT +++ b/late/scripts/FAIL-SCRIPT @@ -27,6 +27,7 @@ # BE AWARE THAT THIS SCRIPT IS CALLED FROM OUTSIDE THE CHROOT. # The OS is mounted under $TARGET +# shellcheck disable=SC2240 . /usr/share/dell/scripts/fifuncs "target" set -x @@ -38,7 +39,7 @@ if [ "$BOOTDEV" = "$TARGETDEV" ]; then #cleanup potentially stale mount points for mountpoint in $MOUNT_CLEANUP; do - umount -l $mountpoint + umount -l "$mountpoint" done if [ -d "/isodevice" ]; then @@ -50,8 +51,8 @@ if [ "$BOOTDEV" = "$TARGETDEV" ]; then fistlog="/tmp/fist.err" if [ -f $RP/SDR ]; then - dualos=`sed -n '/DUALOS/=' $RP/SDR` - if [ $dualos ]; then + dualos=$(sed -n '/DUALOS/=' $RP/SDR) + if [ "$dualos" ]; then fistlog="/tmp/DUALOS_FIST.ERR" fi fi @@ -61,18 +62,18 @@ if [ "$BOOTDEV" = "$TARGETDEV" ]; then grub-editenv $RP/factory/grubenv set recordfail=1 # create a dmesg.log file to record the dmesg info - touch $TARGET/$LOG/dmesg.log 2>&1 - chattr +a $TARGET/$LOG/dmesg.log - dmesg >> $TARGET/$LOG/dmesg.log + touch "$TARGET"/"$LOG"/dmesg.log 2>&1 + chattr +a "$TARGET"/"$LOG"/dmesg.log + dmesg >> "$TARGET"/"$LOG"/dmesg.log if [ -x /dell/fist/tal ]; then IFHALT "Reporting logs to DMP" - cp -f $TARGET/$LOG/chroot.sh.log $fistlog + cp -f "$TARGET"/"$LOG"/chroot.sh.log $fistlog /dell/fist/tal PutFiles $fistlog /dell/fist/tal PutFiles "$TARGET/$LOG/dmesg.log" sync elif [ ! -d /sys/firmware/efi ]; then - grub-setup -d $RP/factory $BOOTDEV + grub-setup -d $RP/factory "$BOOTDEV" fi #If we have another script to run, do it diff --git a/late/scripts/SUCCESS-SCRIPT b/late/scripts/SUCCESS-SCRIPT index f266d1ee..aedd50b3 100755 --- a/late/scripts/SUCCESS-SCRIPT +++ b/late/scripts/SUCCESS-SCRIPT @@ -27,20 +27,21 @@ # BE AWARE THAT THIS SCRIPT IS CALLED FROM OUTSIDE THE CHROOT. # The OS is mounted under $TARGET +# shellcheck disable=SC2240 . /usr/share/dell/scripts/fifuncs "target" set -x set -e IFHALT "(SUCCESS) Clean-Up .." -chroot $TARGET /usr/share/dell/scripts/pool.sh cleanup +chroot "$TARGET" /usr/share/dell/scripts/pool.sh cleanup #Fixup APT how we want it for a successful oem-config run -rm -f $TARGET/var/lib/apt/lists/*Packages -rm -f $TARGET/etc/apt/sources.list.d/dell.list +rm -f "$TARGET"/var/lib/apt/lists/*Packages +rm -f "$TARGET"/etc/apt/sources.list.d/dell.list #https://bugs.launchpad.net/ubuntu/+source/choose-mirror/+bug/550694 if [ -f "$TARGET/etc/apt/sources.list" ]; then - sed -i "s/http:\/\/.*.archive.ubuntu.com/http:\/\/archive.ubuntu.com/" $TARGET/etc/apt/sources.list + sed -i "s/http:\/\/.*.archive.ubuntu.com/http:\/\/archive.ubuntu.com/" "$TARGET"/etc/apt/sources.list fi #The script below was removed because we use a package based solution in @@ -49,7 +50,7 @@ fi #We disabled Ethernet in phase 1 and 2 of installation, now enable it back. (LP: #1329148) if [ -f "$TARGET/etc/init/network-manager.conf.orig" ]; then - mv $TARGET/etc/init/network-manager.conf.orig $TARGET/etc/init/network-manager.conf + mv "$TARGET"/etc/init/network-manager.conf.orig "$TARGET"/etc/init/network-manager.conf fi if [ "$BOOTDEV" = "$TARGETDEV" ]; then @@ -63,7 +64,7 @@ if [ "$BOOTDEV" = "$TARGETDEV" ]; then # Bypass the grub2-signed issue. (LP: #1482514) IFHALT "Renaming .disk/info to .disk/info.recovery" - if [ -f "$RP/.disk/info.recovery" -a -f "$RP/.disk/info" ]; then + if [ -f "$RP/.disk/info.recovery" ] && [ -f "$RP/.disk/info" ]; then rm -fr $RP/.disk/info elif [ -f "$RP/.disk/info" ]; then mv $RP/.disk/info $RP/.disk/info.recovery @@ -71,8 +72,8 @@ if [ "$BOOTDEV" = "$TARGETDEV" ]; then fistlog="/tmp/fist.log" if [ -f $RP/SDR ]; then - dualos=`sed -n '/DUALOS/=' $RP/SDR` - if [ $dualos ]; then + dualos=$(sed -n '/DUALOS/=' $RP/SDR) + if [ "$dualos" ]; then fistlog="/tmp/DUALOS_FIST.LOG" fi fi @@ -96,20 +97,20 @@ if [ "$BOOTDEV" = "$TARGETDEV" ]; then rm -rf $RP/.disk/casper-uuid* IFHALT "Regenerate md5sum.txt at the end..." - $(python3 << EOF + eval "$(python3 << EOF from Dell.recovery_common import regenerate_md5sum regenerate_md5sum("$RP") EOF -) +)" IFHALT "Report the LOG..." # create a dmesg.log file to record the dmesg info - touch $TARGET/$LOG/dmesg.log 2>&1 - chattr +a $TARGET/$LOG/dmesg.log - dmesg >> $TARGET/$LOG/dmesg.log + touch "$TARGET"/"$LOG"/dmesg.log 2>&1 + chattr +a "$TARGET"/"$LOG"/dmesg.log + dmesg >> "$TARGET"/"$LOG"/dmesg.log if [ -f /dell/fist/tal ]; then - cp $TARGET/$LOG/chroot.sh.log $fistlog + cp "$TARGET"/"$LOG"/chroot.sh.log $fistlog /dell/fist/tal PutFiles $fistlog /dell/fist/tal PutFiles "$TARGET/$LOG/dmesg.log" rm -rf /cdrom/debs/fist diff --git a/late/scripts/fetch_logs.sh b/late/scripts/fetch_logs.sh index c35169f2..6f5a40aa 100755 --- a/late/scripts/fetch_logs.sh +++ b/late/scripts/fetch_logs.sh @@ -19,25 +19,23 @@ dump_MFG() BD="" BDD="" # check to see if it's already mounted, if not mount it - readlink /dev/disk/by-label/OS | grep "sd" - if [ $? -eq 0 ]; then - BD=`readlink /dev/disk/by-label/OS | cut -c7-9` + if readlink /dev/disk/by-label/OS | grep -q "sd"; then + BD=$(readlink /dev/disk/by-label/OS | cut -c7-9) drive="/dev/${BD}1" BDD="/dev/${BD}" echo "Find boot disk ${drive}" else - readlink /dev/disk/by-label/OS | grep "mmc" - if [ $? -eq 0 ]; then - BD=`readlink /dev/disk/by-label/OS | cut -c7-13` + if readlink /dev/disk/by-label/OS | grep -q "mmc"; then + BD=$(readlink /dev/disk/by-label/OS | cut -c7-13) drive="/dev/${BD}p1" BDD="/dev/${BD}" log "Find boot disk ${drive}" echo "Find boot disk ${drive}" else - readlink /dev/disk/by-label/OS | grep "nvme" - if [ $? -eq 0 ]; then - BD=`readlink /dev/disk/by-label/OS | cut -c7-13` + if readlink /dev/disk/by-label/OS | grep -q "nvme"; then + BD=$(readlink /dev/disk/by-label/OS | cut -c7-13) drive="/dev/${BD}p1" + # shellcheck disable=SC2034 BDD="/dev/${BD}" echo "Find boot disk ${drive}" else @@ -46,29 +44,27 @@ dump_MFG() fi fi fi - mount | grep -iqs "$drive" - if [ $? -gt 0 ]; then + if ! mount | grep -iqs "$drive"; then echo "Mounting EFI System Partition" if [ ! -d /mnt/efi ]; then mkdir /mnt/efi fi - mount $drive /mnt/efi + mount "$drive" /mnt/efi ESP="/mnt/efi" else - ESP=`mount | grep -is "$drive" | cut -d" " -f3` + ESP=$(mount | grep -is "$drive" | cut -d" " -f3) fi ################################################################## if [ "$ESP" = "" ]; then echo "Unable to find EFI System Partition which holds MFGMEDIA" fi # this code will account for case sensitivity of MFGMEDIA path - MFGMEDIA=`ls ${ESP} | grep -i "MFGMEDIA"` + MFGMEDIA=$(ls "${ESP}"/*"MFGMEDIA"*) if [ "$MFGMEDIA" = "" ]; then echo "Missing MFGMEDIA folder from EFI System Partition" else # copy the file - cp -rf ${ESP}/${MFGMEDIA} ./ - if [ $? -gt 0 ]; then + if ! cp -rf "${ESP}"/"${MFGMEDIA}" ./; then echo "Failed to copy MFGMEDIA" return 255 else @@ -79,8 +75,7 @@ dump_MFG() } #find the usb key mount point -usb_part=`mount | grep "/cdrom" | cut -d ' ' -f 1` -if [ $? -ne 0 ]; then +if ! mount | grep "/cdrom" | cut -d ' ' -f 1; then echo "Can't find the USB key!!" exit 1 fi @@ -94,18 +89,17 @@ fi mkdir /cdrom/OSLogs STICKY=$(mount | sed '/\/cdrom/!d; s,\(.*\) on .*,\1,;') -linux_part=`fdisk -l | grep "Linux filesystem" | grep -v "$STICKY" | cut -d ' ' -f 1` +linux_part=$(fdisk -l | grep "Linux filesystem" | grep -v "$STICKY" | cut -d ' ' -f 1) #check the mount partition -if [ -z $linux_part ];then +if [ -z "$linux_part" ];then #store the disk layout info lsblk > /cdrom/OSLogs/disk_part echo "This disk has not parted yet!!" exit 1 fi #mount the partition -mount | grep "/mnt" 2>/dev/null -if [ $? -ne 0 ];then - mount $linux_part /mnt +if ! mount | grep "/mnt" 2>/dev/null;then + mount "$linux_part" /mnt fi #copy the FI logs if installation happens during FI mfglog='' @@ -120,8 +114,7 @@ if [ -d /mnt/var/log ];then touch dmesg.log 2>&1 chattr +a dmesg.log dmesg >> dmesg.log - tar -zcf "/cdrom/OSLogs/ubuntu.log.tar.gz" /mnt/var/log/ dmesg.log $mfglog 2>/dev/null - if [ $? -eq 0 ];then + if tar -zcf "/cdrom/OSLogs/ubuntu.log.tar.gz" /mnt/var/log/ dmesg.log "$mfglog" 2>/dev/null;then echo "Finish copying the OS installation logs!" fi else diff --git a/late/scripts/fifuncs b/late/scripts/fifuncs index 50f70bfc..948a9210 100755 --- a/late/scripts/fifuncs +++ b/late/scripts/fifuncs @@ -24,16 +24,16 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. -wd=""$1"" +wd="""$1""" screenmsg() { - echo $* > /dev/ttyprintk 2>&1 + echo "$*" > /dev/ttyprintk 2>&1 } IFHALT() { - if [ -f /$wd/tmp/superhalt.flg ]; then + if [ -f /"$wd"/tmp/superhalt.flg ]; then touch /tmp/halt.flg - screenmsg "Halting ---> "$1 + screenmsg "Halting ---> $1" set +x while [ -f /tmp/halt.flg ]; do sleep 2 @@ -60,11 +60,11 @@ match_system_device() echo "Need Vendor and Product arguments" return 1 fi - DEVICES=$(find -L /sys/bus/$1/devices -maxdepth 2 -name $DEVICE_FILE) + DEVICES=$(find -L /sys/bus/"$1"/devices -maxdepth 2 -name $DEVICE_FILE) for file in $DEVICES; do - CHECK_DEVICE=$(cat $file) - DIRECTORY=$(dirname $file) - CHECK_VENDOR=$(cat $DIRECTORY/$VENDOR_FILE) + CHECK_DEVICE=$(cat "$file") + DIRECTORY=$(dirname "$file") + CHECK_VENDOR=$(cat "$DIRECTORY"/$VENDOR_FILE) if [ "$CHECK_VENDOR" != "$2" ] && [ "$CHECK_VENDOR" != "0x$2" ]; then continue fi diff --git a/late/scripts/pool.sh b/late/scripts/pool.sh index 8318a4a6..0d671ff6 100755 --- a/late/scripts/pool.sh +++ b/late/scripts/pool.sh @@ -67,7 +67,7 @@ if [ ! -f /etc/apt/sources.list.d/dell.list ]; then for dir in /cdrom/debs /isodevice/debs /dell/debs; do if [ -d "$dir" ]; then - cd $dir + cd $dir || exit apt-ftparchive packages ../../$dir | sed "s/^Filename:\ ..\//Filename:\ .\//" >> /Packages fi done diff --git a/late/scripts/secure-boot.sh b/late/scripts/secure-boot.sh index ebf6ea34..59c1f31e 100644 --- a/late/scripts/secure-boot.sh +++ b/late/scripts/secure-boot.sh @@ -7,7 +7,7 @@ efi_vars_dir=/sys/firmware/efi/vars EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c SB="$efi_vars_dir/SecureBoot-$EFI_GLOBAL_VARIABLE/data" if [ -e "$SB" ] && \ - [ "$(( $(printf 0x%x \'"$(cat $SB | cut -b1)") & 1 ))" = 1 ]; then + [ "$(( $(printf 0x%x \'"$(< $SB cut -b1)") & 1 ))" = 1 ]; then SECURE_BOOT="1" fi @@ -16,11 +16,11 @@ fi if [ -z "$SECURE_BOOT" ] && [ -f "$EFI_APP" ]; then cp -v "$EFI_APP" /boot/efi/EFI/ubuntu/ PARTITION_NODE=$(mount | sed '/\/boot\/efi/!d; s, .*,,; s,/dev/,,;') - DEVICE=$(readlink /sys/class/block/$PARTITION_NODE | sed "s,/$PARTITION_NODE,,; s,.*/,,") - PARTITION_NUMBER=$(cat /sys/class/block/$PARTITION_NODE/partition) - efibootmgr -C -l '\EFI\ubuntu\MokSBStateSet.efi' -L 'MokSBStateSet' -d /dev/$DEVICE -p $PARTITION_NUMBER + DEVICE=$(readlink /sys/class/block/"$PARTITION_NODE" | sed "s,/$PARTITION_NODE,,; s,.*/,,") + PARTITION_NUMBER=$(cat /sys/class/block/"$PARTITION_NODE"/partition) + efibootmgr -C -l '\EFI\ubuntu\MokSBStateSet.efi' -L 'MokSBStateSet' -d /dev/"$DEVICE" -p "$PARTITION_NUMBER" BOOTNUM=$(efibootmgr | sed '/MokSBStateSet/!d; s,\* .*,,; s,Boot,,') BOOTORDER=$(efibootmgr | sed '/BootOrder/!d; s/BootOrder: //') - efibootmgr -o $BOOTORDER,$BOOTNUM - efibootmgr -v -n $BOOTNUM + efibootmgr -o "$BOOTORDER","$BOOTNUM" + efibootmgr -v -n "$BOOTNUM" fi diff --git a/late/scripts/target_chroot.sh b/late/scripts/target_chroot.sh index e979dce1..56b03412 100755 --- a/late/scripts/target_chroot.sh +++ b/late/scripts/target_chroot.sh @@ -47,8 +47,9 @@ do for i in $(find $d -type f -executable | sort); do echo "running chroot script: $i" > /dev/tty12 - IFHALT $i - ext=`echo $i | sed 's/^.*\.//'` + IFHALT "$i" + # ext=`echo $i | sed 's/^.*\.//'` + echo "${i//^.*\.//}" $i done fi diff --git a/modifying_factory_image.md b/modifying_factory_image.md index 1fd19b00..aa9a1a29 100644 --- a/modifying_factory_image.md +++ b/modifying_factory_image.md @@ -1,18 +1,24 @@ -Modifying Factory images ----- -Factory images (.ISO) can be modified to include any additional Debian packages or to run extra scripts after the image installation is complete. +# Modifying Factory images -Development purposes --- +Factory images (.ISO) can be modified to include any additional Debian packages +or to run extra scripts after the image installation is complete. -For development purposes, additional `.deb` packages can be placed onto a USB stick with a factory image already written to it if the USB stick is formatted as FAT32. +## Development purposes -1. Create the directories `debs/main` on the USB stick if they don't already exist. -2. Copy all .deb packages and their dependencies into the `debs/main` directory on the USB disk. +For development purposes, additional `.deb` packages can be placed onto a USB +stick with a factory image already written to it if the USB stick is formatted +as FAT32. -Production purposes --- -To write these packages into a new ISO image, the **Dell Recovery** tool needs to be executed in *builder* mode. In *builder* mode it can take an existing factory ISO image and modify it. +1. Create the directories `debs/main` on the USB stick if they don't already +exist. +2. Copy all .deb packages and their dependencies into the `debs/main` directory + on the USB disk. + +## Production purposes + +To write these packages into a new ISO image, the **Dell Recovery** tool needs +to be executed in *builder* mode. In *builder* mode it can take an existing +factory ISO image and modify it. From an Ubuntu machine with `dell-recovery` installed, execute: diff --git a/po/import.sh b/po/import.sh index 6dc36c86..3f6b9eec 100755 --- a/po/import.sh +++ b/po/import.sh @@ -1,21 +1,21 @@ #!/bin/sh FILE=launchpad-export.tar.gz if [ -n "$1" ]; then - if echo $1 | grep "launchpadlibrarian.net" 2>/dev/null; then + if echo "$1" | grep "launchpadlibrarian.net" 2>/dev/null; then wget "$1" -O $FILE else FILE="$1" fi fi -if [ ! -f $FILE ]; then +if [ ! -f "$FILE" ]; then echo "Missing file: $FILE" exit 1 fi -tar xzzf $FILE +tar xzzf "$FILE" mv dell-recovery/*.po . rm -rf dell-recovery for x in dell-recovery-*.po ; do - echo $x ; - mv $x ${x#dell-recovery-} ; + echo "$x" ; + mv "$x" "${x#dell-recovery-}" ; done diff --git a/tests/grub-binaries b/tests/grub-binaries index fb872295..12b0a1c1 100755 --- a/tests/grub-binaries +++ b/tests/grub-binaries @@ -1,6 +1,8 @@ #!/bin/sh -e -export TARGET=$(mktemp -d) -export SOURCE_GRUBDIR=`pwd`/grub/ +TARGET=$(mktemp -d) +export TARGET +SOURCE_GRUBDIR=$(pwd)/grub/ +export SOURCE_GRUBDIR grub/build-binaries.sh -rm -rf $TARGET +rm -rf "$TARGET" echo "No problems building grub binaries."