From 50fdc82ebb9d70aacfef9e2543ab5ebebf10b6d0 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Feb 07 2022 22:25:57 +0000 Subject: Add CI tests and CD pipeline (#117) Add Github Actions workflow Reduce interactivity in a CI environment Change to systemd-nspawn from chroot Clean up some magic strings as variables Remove firefox (Cisco GPG repo problems) Unmount everything and xz resulting image Co-authored-by: Nikhil Jha --- diff --git a/.env b/.env index 8019000..b01bcdb 100644 --- a/.env +++ b/.env @@ -4,12 +4,13 @@ PP_IMAGE=${PP_IMAGE:-/dev/loop1} PP_PARTA=${PP_PARTA:-${PP_IMAGE}p1} PP_PARTB=${PP_PARTB:-${PP_IMAGE}p2} +FED_IMAGE=${FED_IMAGE:-/dev/loop0} # Output file name. OUT_NAME=${OUT_NAME:-fedora.img} # Only needed if you want a custom file, otherwise do not change. # FEDORA_RAW_FILE=Fedora-Minimal-Rawhide-20200302.n.1.aarch64.raw.xz -FEDORA_RAW_SOURCE=${EFDORA_RAW_SOURCE:-https://dl.fedoraproject.org/pub/fedora-secondary/development/rawhide/Spins/aarch64/images} +FEDORA_RAW_SOURCE=${FEDORA_RAW_SOURCE:-https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Spins/aarch64/images} KERNEL_RAW_DIR=${KERNEL_RAW_DIR:-pp1-5.7} export PP_IMAGE diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..687514f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,65 @@ +name: Run build + +"on": + push: + paths-ignored: + - README.md + - COPYING + pull_request: + release: + types: + - published + - prereleased + workflow_dispatch: # Allows manually triggering + +env: + PP_IMAGE: /dev/loop10 + FED_IMAGE: /dev/loop11 + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + - name: Makes extra disk space + uses: greg-hellings/make-space@v1 + - name: Install necessary tools + run: | + sudo apt update + sudo apt install -yy systemd-container qemu-user-static u-boot-tools btrfs-progs dosfstools xz-utils sssd + sudo service sssd start + - name: Download files + run: | + set -ex -o pipefail + ./download-files.sh + - name: Execute build + run: | + set -ex -o pipefail + sudo -E ./all.sh + # Compress image + sudo xz -T 0 fedora.img + - name: Store fedora.img.xz as an artifact + uses: actions/upload-artifact@v2 + with: + name: image + path: fedora.img.xz + if-no-files-found: error + + release: + needs: + - build # Can only run after the build has created the artifact + runs-on: ubuntu-latest + if: github.event_name == 'release' + steps: + - name: Download fedora.img.xz + uses: actions/download-artifact@v2 + with: + name: image + - name: Upload files to release + uses: ncipollo/release-action@v1 + with: + artifacts: fedora.img.xz + allowUpdates: true + name: ${{ github.event.name }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/00-create-empty-image.sh b/00-create-empty-image.sh index 84b83eb..6a1256a 100755 --- a/00-create-empty-image.sh +++ b/00-create-empty-image.sh @@ -9,8 +9,13 @@ echo "========================" # Approximately 6GB image. echo "Create image called $OUT_NAME? Make sure this doesn't exist, or it will be replaced." -read -p "Continue? [y/N] " -n 1 -r +if [ ! -z "$PS1" ]; then + read -p "Continue? [y/N] " -n 1 -r +else + REPLY=y +fi echo + if [[ $REPLY =~ ^[Yy]$ ]] then if [[ -e "$OUT_NAME" ]] diff --git a/00-selftest.sh b/00-selftest.sh index 12e0c74..18ec36b 100755 --- a/00-selftest.sh +++ b/00-selftest.sh @@ -27,6 +27,8 @@ fi command -v mkfs.btrfs >/dev/null 2>&1 || { echo >&2 "I require mkfs.btrfs but it's not installed. Aborting."; exit 1; } command -v mkfs.vfat >/dev/null 2>&1 || { echo >&2 "I require mkfs.vfat but it's not installed. Aborting."; exit 1; } +command -v systemd-nspawn >/dev/null 2>&1 || { echo >&2 "I require systemd-nspawn but it's not installed. Aborting."; exit 1; } + if [[ $HOSTARCH != "aarch64" ]]; then command -v qemu-aarch64-static >/dev/null 2>&1 || { echo >&2 "I require qemu-aarch64-static but it's not installed. Aborting."; exit 1; } fi diff --git a/01-partition-drive.sh b/01-partition-drive.sh index b05e82a..156ba0f 100755 --- a/01-partition-drive.sh +++ b/01-partition-drive.sh @@ -23,11 +23,15 @@ fi # Warning echo "=== WARNING WARNING WARNING ===" -infecho "This script will mount to /dev/loop1." +infecho "This script will mount to ${PP_IMAGE}." infecho "Make sure nothing else is mounted there: lsblk" echo "=== WARNING WARNING WARNING ===" echo -read -p "Continue? [y/N] " -n 1 -r +if [ ! -z "$PS1" ]; then + read -p "Continue? [y/N] " -n 1 -r +else + REPLY=y +fi echo if [[ $REPLY =~ ^[Yy]$ ]] then diff --git a/02-install-rootfs.sh b/02-install-rootfs.sh index a8b858e..e789a1a 100755 --- a/02-install-rootfs.sh +++ b/02-install-rootfs.sh @@ -24,11 +24,15 @@ fi # Warning echo "=== WARNING WARNING WARNING ===" -infecho "This script will try to mount to /dev/loop0." +infecho "This script will try to mount to ${FED_IMAGE}." infecho "Make sure nothing else is there with: lsblk" echo "=== WARNING WARNING WARNING ===" echo -read -p "Continue? [y/N] " -n 1 -r +if [ ! -z "$PS1" ]; then + read -p "Continue? [y/N] " -n 1 -r +else + REPLY=y +fi echo if [[ $REPLY =~ ^[Yy]$ ]] then @@ -37,9 +41,9 @@ then mkdir -p rootfs infecho "Mounting Fedora image..." - losetup /dev/loop0 rawhide.raw - partprobe -s /dev/loop0 - mount /dev/loop0p3 imgfs + losetup "${FED_IMAGE}" rawhide.raw + partprobe -s ${FED_IMAGE} + mount ${FED_IMAGE}p3 imgfs infecho "Mounting SD Card rootfs..." partprobe -s $PP_IMAGE @@ -47,14 +51,18 @@ then mount $PP_PARTB rootfs infecho "Copying files..." - rsync -a --progress imgfs/* rootfs/ + if [ ! -z "$PS1" ]; then + rsync -a --progress imgfs/* rootfs/ + else + rsync -a imgfs/* rootfs/ + fi infecho "Deleting contents of /boot..." rm -rf rootfs/boot/* infecho "Unmounting everything..." - umount /dev/loop0p3 - losetup -d /dev/loop0 + umount ${FED_IMAGE}p3 + losetup -d ${FED_IMAGE} umount $PP_PARTB infecho "Deleting temp directories..." diff --git a/03-install-kernel.sh b/03-install-kernel.sh index c34cd1b..36395e3 100755 --- a/03-install-kernel.sh +++ b/03-install-kernel.sh @@ -33,7 +33,11 @@ infecho "Also, I didn't test this so it might also cause WWIII or something." infecho "I'm not responsible for anything that happens, you should read the script first." echo "=== WARNING WARNING WARNING ===" echo -read -p "Continue? [y/N] " -n 1 -r +if [ ! -z "$PS1" ]; then + read -p "Continue? [y/N] " -n 1 -r +else + REPLY=y +fi echo if [[ $REPLY =~ ^[Yy]$ ]] then diff --git a/04-edit-fstab.sh b/04-edit-fstab.sh index 248ead6..cb4b2ad 100755 --- a/04-edit-fstab.sh +++ b/04-edit-fstab.sh @@ -29,7 +29,11 @@ infecho "I didn't test this so it might also cause WWIII or something." infecho "I'm not responsible for anything that happens, you should read the script first." echo "=== WARNING WARNING WARNING ===" echo -read -p "Continue? [y/N] " -n 1 -r +if [ ! -z "$PS1" ]; then + read -p "Continue? [y/N] " -n 1 -r +else + REPLY=y +fi echo if [[ $REPLY =~ ^[Yy]$ ]] then diff --git a/05-setup-user.sh b/05-setup-user.sh index 918b5be..ca76879 100755 --- a/05-setup-user.sh +++ b/05-setup-user.sh @@ -31,7 +31,11 @@ infecho "I didn't test this so it might also cause WWIII or something." infecho "I'm not responsible for anything that happens, you should read the script first." echo "=== WARNING WARNING WARNING ===" echo -read -p "Continue? [y/N] " -n 1 -r +if [ ! -z "$PS1" ]; then + read -p "Continue? [y/N] " -n 1 -r +else + REPLY=y +fi echo if [[ $REPLY =~ ^[Yy]$ ]] then @@ -50,30 +54,26 @@ then cp phone-scripts/* rootfs/root - infecho "Mounting your /dev into the rootfs..." - infecho "This is neccesary for dnf to work, because reasons." - mount --bind /dev rootfs/dev - infecho "Copy resolv.conf /etc/tmp-resolv.conf" cp /etc/resolv.conf rootfs/etc/tmp-resolv.conf if [[ $HOSTARCH != "aarch64" ]]; then infecho "Chrooting with qemu into rootfs..." - chroot rootfs qemu-aarch64-static /bin/bash /root/all.sh + systemd-nspawn -D rootfs qemu-aarch64-static /bin/bash /root/all.sh infecho "KILLING ALL QEMU PROCESSES, MAKE SURE YOU HAVE NO MORE RUNNING!" - killall -9 /usr/bin/qemu-aarch64-static + killall -9 /usr/bin/qemu-aarch64-static || true + + infecho "Removing qemu binary, so it doesn't stay in image" + rm -f rootfs/usr/bin/qemu-aarch64-static else infecho "Chrooting into rootfs..." chroot rootfs /bin/bash /root/all.sh fi - infecho "Unmounting your /dev from the rootfs..." - sleep 3 - umount rootfs/dev - infecho "Unmounting rootfs..." sleep 3 + umount $PP_PARTA umount $PP_PARTB rmdir rootfs fi diff --git a/cleanup.sh b/cleanup.sh index 63a9ecc..564f78f 100755 --- a/cleanup.sh +++ b/cleanup.sh @@ -2,7 +2,7 @@ source .env -umount /dev/loop0p3 +umount ${FED_IMAGE}p3 umount $PP_PARTB umount $PP_PARTA sleep 3 @@ -10,4 +10,4 @@ rmdir imgfs rmdir rootfs rmdir $KERNEL_RAW_DIR/imgfs rmdir $KERNEL_RAW_DIR/rootfs -losetup -d /dev/loop0 +losetup -d ${FED_IMAGE} diff --git a/download-files.sh b/download-files.sh index 445072a..ea99635 100755 --- a/download-files.sh +++ b/download-files.sh @@ -6,7 +6,11 @@ source .env echo "This script will download a few GB of Fedora and a few MB of Kernel into the current directory." echo "Look inside the script if you would rather download manually." echo -read -p "Continue? [y/N] " -n 1 -r +if [ ! -z "$PS1" ]; then + read -p "Continue? [y/N] " -n 1 -r +else + REPLY=y +fi echo if [[ $REPLY =~ ^[Yy]$ ]] then diff --git a/phone-scripts/01-create-sudo-user.sh b/phone-scripts/01-create-sudo-user.sh index 2a287d3..3f02f1e 100755 --- a/phone-scripts/01-create-sudo-user.sh +++ b/phone-scripts/01-create-sudo-user.sh @@ -13,6 +13,6 @@ infecho () { infecho "Adding user \"pine\"..." adduser pine -passwd pine +printf 123456 | passwd --stdin pine groupadd feedbackd usermod -aG wheel,video,feedbackd pine diff --git a/phone-scripts/02-install-packages.sh b/phone-scripts/02-install-packages.sh index a6ad06d..a4e28c4 100644 --- a/phone-scripts/02-install-packages.sh +++ b/phone-scripts/02-install-packages.sh @@ -22,15 +22,16 @@ infecho "Link temp-resolv.conf" ln -sfv /etc/tmp-resolv.conf /etc/resolv.conf infecho "Enabling COPR repository..." -dnf -y copr enable njha/mobile +dnf -q -y copr enable njha/mobile infecho "Removing old kernel..." infecho "THIS WILL FAIL, DON'T WORRY ITS PROBABLY OK" -dnf -y remove kernel || rpm -e --noscripts kernel-core -dnf -y install linux-firmware +dnf -q -y remove kernel || rpm -e --noscripts kernel-core +dnf -q -y install linux-firmware +# Firefox is currently causing problems with Cisco H.264 RPMs infecho "Installing recommended packages..." -dnf -y install megi-kernel feedbackd phoc phosh squeekboard gnome-shell ModemManager rtl8723cs-firmware \ +dnf -q -y install megi-kernel feedbackd phoc phosh squeekboard gnome-shell ModemManager rtl8723cs-firmware \ dbus-x11 chatty calls carbons purple-mm-sms pinephone-helpers evolution-data-server \ f35-backgrounds-gnome epiphany gnome-contacts NetworkManager-wwan \ firefox nautilus gvfs-goa megapixels gnome-power-manager gnome-usage xdg-user-dirs pipewire-alsa \ @@ -47,4 +48,4 @@ infecho "Making COPR higher priority for kernel updates..." echo "priority=10" >> /etc/yum.repos.d/_copr\:copr.fedorainfracloud.org\:njha\:mobile.repo infecho "Upgrading packages..." -dnf -y upgrade +dnf -q -y upgrade