From 40833754a9b2b72db576cbec0fce675fc8f31ec6 Mon Sep 17 00:00:00 2001 From: Nikhil Jha Date: Feb 18 2020 18:56:22 +0000 Subject: add safety --- diff --git a/00-selftest.sh b/00-selftest.sh new file mode 100644 index 0000000..0a8695b --- /dev/null +++ b/00-selftest.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +echo "==============" +echo "00-selftest.sh" +echo "==============" + +infecho () { + echo "[Info] $1" +} + +infecho "Now running selftest, please do not continue running scripts until this completes successfully." + +command -v mkfs.f2fs >/dev/null 2>&1 || { echo >&2 "I require mkfs.f2fs but it's not installed. Aborting."; exit 1; } +command -v qemu-aarch64-static >/dev/null 2>&1 || { echo >&2 "I require qemu-aarch64-static but it's not installed. Aborting."; exit 1; } +command -v rsync >/dev/null 2>&1 || { echo >&2 "I require rsync but it's not installed. Aborting."; exit 1; } +command -v mkimage >/dev/null 2>&1 || { echo >&2 "I require mkimage but it's not installed. Aborting."; exit 1; } + +infecho "Selftest complete!" diff --git a/02-install-rootfs.sh b/02-install-rootfs.sh index 7494705..1f60c03 100644 --- a/02-install-rootfs.sh +++ b/02-install-rootfs.sh @@ -30,7 +30,7 @@ fi # Warning echo "=== WARNING WARNING WARNING ===" -infecho "This script WILL COPY A TON OF FILES TO $PP_PARTB (mounted to $PP_ROOT_DIR)." +infecho "This script WILL COPY A TON OF FILES TO $PP_PARTB." infecho "It will also dry to mount to /dev/loop0. Make sure nothing else is there." 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." diff --git a/03-install-kernel.sh b/03-install-kernel.sh index 6b2840d..5458970 100644 --- a/03-install-kernel.sh +++ b/03-install-kernel.sh @@ -1,16 +1,65 @@ +#!/bin/bash set -e -cd pp-5.6 -mkimage -A arm64 -T script -C none -d boot.cmd boot.scr -dd if=uboot.bin of=$PP_SD_DEVICE bs=1024 seek=8 -mkdir -p bootfs -mkdir -p rootfs -mount $PP_PARTA bootfs -mount $PP_PARTB rootfs -cp boot.scr bootfs/ -cp board.itb bootfs/ -rsync -a --progress modules/lib/modules/* rootfs/lib/modules/ -umount $PP_PARTA -umount $PP_PARTB -rmdir bootfs -rmdir rootfs +echo "====================" +echo "03-install-kernel.sh" +echo "====================" + +# Functions +infecho () { + echo "[Info] $1" +} + +# Notify User +infecho "The env vars that will be used in this script..." +infecho "PP_SD_DEVICE = $PP_SD_DEVICE" +infecho "PP_PARTA = $PP_PARTA" +infecho "PP_PARTB = $PP_PARTB" +echo + +# Automatic Preflight Checks +if [[ $EUID -ne 0 ]]; then + errecho "This script must be run as root!" + exit 1 +fi + +# Warning +echo "=== WARNING WARNING WARNING ===" +infecho "This script USES THE DD COMMAND AS ROOT. If the env vars are wrong, this could do something bad." +infecho "Make sure this script is run from the main dir of the repo, since it assumes that's true." +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 +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + infecho "Changing directory..." + cd pp-5.6 + + infecho "Generating boot.scr..." + mkimage -A arm64 -T script -C none -d boot.cmd boot.scr + + infecho "Writing bootloader..." + dd if=uboot.bin of=$PP_SD_DEVICE bs=1024 seek=8 + + infecho "Mounting SD card partitions..." + mkdir -p bootfs + mkdir -p rootfs + mount $PP_PARTA bootfs + mount $PP_PARTB rootfs + + infecho "Copying boot.scr board.itb..." + cp boot.scr bootfs/ + cp board.itb bootfs/ + + infecho "Installing kernel modules..." + rsync -a --progress modules/lib/modules/* rootfs/lib/modules/ + + infecho "Unmounting SD card partitions..." + umount $PP_PARTA + umount $PP_PARTB + rmdir bootfs + rmdir rootfs +fi diff --git a/04-edit-fstab.sh b/04-edit-fstab.sh index 7e3a1f5..a52080f 100644 --- a/04-edit-fstab.sh +++ b/04-edit-fstab.sh @@ -1,7 +1,44 @@ +#!/bin/bash set -e -mkdir -p rootfs -mount $PP_PARTB rootfs -# TODO: Edit the /etc/fstab with the proper entries. -umount $PP_PARTB -rmdir rootfs +echo "================" +echo "04-edit-fstab.sh" +echo "================" + +# Functions +infecho () { + echo "[Info] $1" +} + +# Notify User +infecho "The env vars that will be used in this script..." +infecho "PP_PARTB = $PP_PARTB" +echo + +# Automatic Preflight Checks +if [[ $EUID -ne 0 ]]; then + errecho "This script must be run as root!" + exit 1 +fi + +# Warning +echo "=== WARNING WARNING WARNING ===" +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 +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + infecho "Mounting root file system..." + mkdir -p rootfs + mount $PP_PARTB rootfs + + infecho "Fixing /etc/fstab..." + # TODO: Edit the /etc/fstab with the proper entries. + + infecho "Unmounting root file system..." + umount $PP_PARTB + rmdir rootfs +fi diff --git a/05-setup-user.sh b/05-setup-user.sh index e789601..50ee095 100644 --- a/05-setup-user.sh +++ b/05-setup-user.sh @@ -1,10 +1,48 @@ +#!/bin/bash set -e -mkdir -p rootfs -mount $PP_PARTB rootfs -cp /usr/bin/qemu-aarch64-static rootfs/usr/bin -cp phone-scripts/* rootfs/root -chroot /tmp/root qemu-aarch64-static /bin/bash all.sh -# TODO: Not sure if this type of command can work. -umount $PP_PARTB -rmdir rootfs +echo "================" +echo "05-setup-user.sh" +echo "================" + +# Functions +infecho () { + echo "[Info] $1" +} + +# Notify User +infecho "The env vars that will be used in this script..." +infecho "PP_PARTB = $PP_PARTB" +echo + +# Automatic Preflight Checks +if [[ $EUID -ne 0 ]]; then + errecho "This script must be run as root!" + exit 1 +fi + +# Warning +echo "=== WARNING WARNING WARNING ===" +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 +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + infecho "Mounting rootfs..." + mkdir -p rootfs + mount $PP_PARTB rootfs + + infecho "Installing qemu in rootfs..." + cp /usr/bin/qemu-aarch64-static rootfs/usr/bin + cp phone-scripts/* rootfs/root + + infecho "Chrooting with qemu into rootfs..." + chroot /tmp/root qemu-aarch64-static /bin/bash all.sh + + infecho "Unmounting rootfs..." + umount $PP_PARTB + rmdir rootfs +fi diff --git a/all.sh b/all.sh index 0236aa8..0917fb7 100644 --- a/all.sh +++ b/all.sh @@ -1,5 +1,6 @@ echo "This script will NOT download the files." echo "Do it yourself: sh 00-download-files.sh" +sh 00-selftest.sh sh 01-partition-drive.sh sh 02-install-rootfs.sh sh 03-install-kernel.sh diff --git a/phone-scripts/01-create-sudo-user.sh b/phone-scripts/01-create-sudo-user.sh index ba1a0e6..bce8bbe 100644 --- a/phone-scripts/01-create-sudo-user.sh +++ b/phone-scripts/01-create-sudo-user.sh @@ -1 +1,15 @@ -# TODO: Create sudo user. \ No newline at end of file +#!/bin/bash +set -e + +echo "======================" +echo "01-create-sudo-user.sh" +echo "======================" + +# Functions +infecho () { + echo "[Info] $1" +} + +infecho "Adding user \"pine\"..." +adduser pine +usermod -aG wheel pine