├── .gitignore ├── 00-sanity_check.sh ├── 01-download.sh ├── 02-format_sdcard.sh ├── 03-flash_rootfs.sh ├── 04-flash_kernel.sh ├── 10-usb_network.sh ├── 99-cleanup.sh ├── LICENSE ├── README.md ├── common.sh └── config.sh.default /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | 3 | *.bak 4 | *.gz 5 | 6 | kernel 7 | root 8 | 9 | config.sh 10 | 11 | -------------------------------------------------------------------------------- /00-sanity_check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Installation Scripts Sanity Check 4 | # 5 | # Checks the current environment before doing any real work. 6 | # 7 | 8 | echo "Sanity check starting..." 9 | 10 | [ -f common.sh ] \ 11 | && echo "common.sh ... found" \ 12 | || { echo "File 'common.sh' not found in this directory. Change directory and try again." ; exit 1; } 13 | 14 | source common.sh 15 | 16 | printInfo 17 | printInfo "Checking the environment:" 18 | 19 | FREE_SPACE=`df -P . | tail -1 | awk '{print $4}'` 20 | [ $FREE_SPACE -gt 4000000 ] \ 21 | && printInfo "free disk space > 4 GB ... OK" \ 22 | || failure "Not enough disk space. Have at least 4 GB." 23 | 24 | ping -c 1 github.com >> /dev/null 25 | [ $? -eq 0 ] \ 26 | && printInfo "Internet connection ... OK" \ 27 | || failure "Internet connection failed." 28 | 29 | rm -rf test.txt && touch test.txt && rm test.txt 30 | [ $? -eq 0 ] \ 31 | && printInfo "Local directory Read/Write permissions ... OK" \ 32 | || failure "Could not read or write to this directory. Check your permissions." 33 | 34 | [ -e $SD_CARD_DEVICE ] \ 35 | && printInfo "SD Card device '$SD_CARD_DEVICE' exists ... OK" \ 36 | || failure "SD Card device '$SD_CARD_DEVICE' not found. Check that it is connected or update the config.sh file." 37 | 38 | if mount | grep $SD_CARD_ROOT > /dev/null; then 39 | failure "SD Card root partition '$SD_CARD_ROOT' is mounted. Unmount it first!" 40 | fi 41 | 42 | if mount | grep $SD_CARD_BOOT > /dev/null; then 43 | failure "SD Card boot partition '$SD_CARD_BOOT' is mounted. Unmount it first!" 44 | fi 45 | 46 | 47 | printInfo 48 | printInfo "Checking commands:" 49 | 50 | command -v bash >> /dev/null \ 51 | && printInfo "bash exists ... OK" \ 52 | || failure "bash not found." 53 | 54 | command -v dd >> /dev/null \ 55 | && printInfo "dd exists ... OK" \ 56 | || failure "dd not found. All hope is lost." 57 | 58 | command -v blockdev >> /dev/null \ 59 | && printInfo "blockdev exists ... OK" \ 60 | || failure "blockdev not found. All hope is lost." 61 | 62 | command -v mkimage >> /dev/null \ 63 | && printInfo "mkimage exists ... OK" \ 64 | || failure "mkimage not found. Install uboot-tools package." 65 | 66 | command -v sudo >> /dev/null \ 67 | && printInfo "sudo exists ... OK" \ 68 | || failure "sudo not found. Install sudo package." 69 | 70 | command -v sync >> /dev/null \ 71 | && printInfo "sync exists ... OK" \ 72 | || failure "sync not found." 73 | 74 | command -v lsblk >> /dev/null \ 75 | && printInfo "lsblk exists ... OK" \ 76 | || failure "lsblk not found." 77 | 78 | command -v bsdtar >> /dev/null \ 79 | && printInfo "bsdtar exists ... OK" \ 80 | || failure "bsdtar not found." 81 | 82 | command -v wget >> /dev/null \ 83 | && printInfo "wget exists ... OK" \ 84 | || failure "wget not found. Install wget package." 85 | 86 | command -v mkfs.vfat >> /dev/null \ 87 | && printInfo "mkfs.vfat exists ... OK" \ 88 | || failure "mkfs.vfat not found. Install dosfstools package." 89 | 90 | command -v mkfs.f2fs >> /dev/null \ 91 | && printInfo "mkfs.f2fs exists ... OK" \ 92 | || failure "mkfs.f2fs not found. Install f2fs-tools package." 93 | 94 | printInfo 95 | printInfo "All tests passed. You're ready to go!" 96 | 97 | stageFinished "Execute the first script (starting with '01') and follow the instructions." 98 | 99 | -------------------------------------------------------------------------------- /01-download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Download 4 | # 5 | # Fetches Arch Linux ARM root filesystem, bootloader and kernel. 6 | # 7 | # Source: https://xnux.eu/howtos/install-arch-linux-arm.html 8 | # 9 | 10 | source common.sh 11 | 12 | printInfo "Time to download all the required components:" 13 | printInfo " - root filesystem" 14 | printInfo " - bootloader and kernel" 15 | printInfo 16 | 17 | if [ -f $ROOTFS_ARCHIVE ] 18 | then 19 | printInfo "Found Arch Linux ARM rootfs, skipping download." 20 | printInfo " (You can run 99-cleanup.sh or delete the file '$ROOTFS_ARCHIVE' to force an update.)" 21 | else 22 | printInfo "Downloading Arch Linux ARM from $ROOTFS_URL:" 23 | wget $ROOTFS_URL -O $ROOTFS_ARCHIVE 24 | [ $? -eq 0 ] \ 25 | && printInfo "Done." \ 26 | || failure "Failed to download." 27 | fi 28 | 29 | printInfo 30 | 31 | if [ -f $KERNEL_ARCHIVE ] 32 | then 33 | printInfo "Found PinePhone Kernel, skipping download." 34 | printInfo " (You can run 99-cleanup.sh or delete the file '$KERNEL_ARCHIVE' to force an update.)" 35 | else 36 | printInfo "Downloading PinePhone Kernel from $KERNEL_URL:" 37 | wget $KERNEL_URL -O $KERNEL_ARCHIVE 38 | [ $? -eq 0 ] \ 39 | && printInfo "Done." \ 40 | || failure "Failed to download." 41 | fi 42 | 43 | stageFinished "Run step 02 to continue." 44 | 45 | -------------------------------------------------------------------------------- /02-format_sdcard.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Format SD Card 4 | # 5 | # Prepares SD Card partition table and formats it. 6 | # 7 | # Source: https://xnux.eu/howtos/install-arch-linux-arm.html 8 | # 9 | 10 | source common.sh 11 | 12 | printInfo "Time to prepare the SD Card." 13 | 14 | printInfo 15 | printInfo "Running lsblk for your convenience:" 16 | lsblk 17 | 18 | printInfo 19 | printInfo "Target device: $SD_CARD_DEVICE" 20 | [ ! -e $SD_CARD_DEVICE ] && failure "Target device not found. Did you update the config file? Is the device connected?" 21 | printInfo "...boot partition: $SD_CARD_BOOT" 22 | printInfo "...root partition: $SD_CARD_ROOT" 23 | 24 | read -p "Do you want to continue and format this device? [y/N]: " 25 | if [[ ! $REPLY =~ ^[yY]$ ]]; then 26 | failure "Terminating." 27 | fi 28 | 29 | read -p "This will ERASE the device completely. Are you sure? [y/N]: " 30 | if [[ ! $REPLY =~ ^[yY]$ ]]; then 31 | failure "Terminating." 32 | fi 33 | 34 | printInfo 35 | printInfo "Clearing start of device..." # to remove previous MBR and U-Boot data 36 | sudo dd if=/dev/zero of=$SD_CARD_DEVICE bs=512 count=1024 \ 37 | || failure "Could not clear the start of $SD_CARD_DEVICE." 38 | printInfo "Clearing end of device..." # to remove previous GPT data 39 | sudo dd if=/dev/zero of=$SD_CARD_DEVICE bs=512 seek=$(( $(blockdev --getsz $SD_CARD_DEVICE) - 1024 )) count=1024 \ 40 | || failure "Could not clear the end of $SD_CARD_DEVICE." 41 | printInfo "Done." 42 | 43 | printInfo 44 | printInfo "Partitioning started..." 45 | sudo sfdisk $SD_CARD_DEVICE < ./root/etc/fstab 54 | echo /dev/mmcblk0p2 / f2fs rw,relatime 0 0 >> ./root/etc/fstab 55 | EOF 56 | if [ $? -ne 0 ]; then 57 | failure "Could not populate fstab." 58 | fi 59 | printInfo "Done." 60 | 61 | printInfo 62 | printInfo "Unmounting..." 63 | sudo umount ./root/boot || failure "Could not unmount ./root/boot" 64 | sudo umount ./root || failure "Could not unmount ./root" 65 | printInfo "Done." 66 | 67 | sync 68 | 69 | stageFinished "Run the step 04 to flash a kernel and a bootloader." 70 | 71 | -------------------------------------------------------------------------------- /04-flash_kernel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Flash Kernel to SD Card 4 | # 5 | # Prepares SD Card contents by installing the kernel on it. 6 | # 7 | # Source: https://xnux.eu/howtos/install-arch-linux-arm.html 8 | # 9 | 10 | source common.sh 11 | 12 | printInfo "Time to flash the kernel onto the SD Card." 13 | printInfo 14 | 15 | printInfo "Extracting kernel archive:" 16 | [ -f $KERNEL_ARCHIVE ] || failure "Could not find kernel archive $KERNEL_ARCHIVE. Did you run all the previous steps?" 17 | 18 | [ -e $KERNEL_DIR ] && rm -rf $KERNEL_DIR 19 | mkdir -p $KERNEL_DIR || failure "Could not create a directory '$KERNEL_DIR' to extract the archive into." 20 | tar xfz $KERNEL_ARCHIVE --strip-components=1 -C $KERNEL_DIR || failure "Could not extract the kernel archive." 21 | 22 | printInfo "Done." 23 | printInfo 24 | printInfo "Entering $KERNEL_DIR directory" 25 | cd $KERNEL_DIR 26 | printInfo 27 | printInfo "You can now modify the boot config." 28 | printInfo "E.g. remove 'quiet' and 'loglevel' parameters to make the boot more verbose." 29 | 30 | read -p "Do you want to edit boot config now? [y/N]: " 31 | if [[ $REPLY =~ ^[yY]$ ]]; then 32 | printInfo "Opening editor $EDITOR" 33 | $EDITOR boot.cmd 34 | printInfo "Editor closed." 35 | fi 36 | 37 | printInfo 38 | printInfo "Building boot script:" 39 | mkimage -A arm64 -T script -C none -d boot.cmd boot.scr 40 | [ $? -eq 0 ] \ 41 | && printInfo "Done." \ 42 | || failure "Failed generating boot.scr" 43 | 44 | printInfo 45 | printInfo "Flashing bootloader to SD Card $SD_CARD_DEVICE:" 46 | read -p "Are you sure you want to continue? [Y/n]: " 47 | [[ $REPLY =~ ^[nN]$ ]] && failure "Terminating." 48 | printInfo "Flashing..." 49 | sudo dd if=uboot.bin of=$SD_CARD_DEVICE bs=1024 seek=8 \ 50 | && printInfo "Done." \ 51 | || failure "Could not flash the bootloader." 52 | 53 | printInfo 54 | printInfo "Syncing..." 55 | sync 56 | sleep 2 57 | 58 | printInfo 59 | printInfo "Mounting SD Card root $SD_CARD_ROOT and boot $SD_CARD_BOOT partitions:" 60 | if [ -e ../root ]; then 61 | rm -rf ../root || failure "Could not remove preexisting root directory. Is it still mounted? Is it yours?" 62 | fi 63 | mkdir ../root || failure "Could not create root directory mounting point." 64 | sudo mount $SD_CARD_ROOT ../root \ 65 | && printInfo "root done." \ 66 | || failure "Could not mount $SD_CARD_ROOT." 67 | sudo mount $SD_CARD_BOOT ../root/boot \ 68 | && printInfo "boot done." \ 69 | || failure "Could not mount $SD_CARD_BOOT." 70 | 71 | printInfo 72 | printInfo "Copying bootloader to boot partition $SD_CARD_BOOT:" 73 | read -p "Are you sure you want to continue? [Y/n]: " 74 | [[ $REPLY =~ ^[nN]$ ]] && failure "Terminating." 75 | sudo cp boot.scr ../root/boot/ && sudo cp board.itb ../root/boot/ \ 76 | && printInfo "Done." \ 77 | || failure "Copy failed. Is the SD Card mounted correctly?" 78 | 79 | printInfo 80 | printInfo "Copying kernel modules to root partition $SD_CARD_ROOT into /lib:" 81 | sudo cp -R -n modules/lib/modules ../root/lib \ 82 | && printInfo "Done." \ 83 | || failure "Copy failed. Is the SD Card mounted correctly?" 84 | 85 | printInfo 86 | printInfo "Unmounting SD Card:" 87 | sudo umount ../root/boot \ 88 | && printInfo "boot done." \ 89 | || failure "Could not umount $SD_CARD_BOOT." 90 | sudo umount ../root \ 91 | && printInfo "root done." \ 92 | || failure "Could not umount $SD_CARD_ROOT." 93 | rm -rf ../root || failure "Could not remove root mount point." 94 | 95 | stageFinished "You are ready to start using the SD Card! Optionally you can continue with the next steps." 96 | 97 | -------------------------------------------------------------------------------- /10-usb_network.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Install support for USB networking 4 | # 5 | # Adds a module for USB networking and sets up a local network. 6 | # 7 | # Source: https://xnux.eu/howtos/install-arch-linux-arm.html 8 | # 9 | 10 | source common.sh 11 | 12 | printInfo "USB Networking" 13 | printInfo 14 | 15 | 16 | read -p "Do you want to install the network to the device? [Y/n]: " 17 | if [[ ! $REPLY =~ ^[nN]$ ]]; then 18 | [ ! -e $SD_CARD_ROOT ] && failure "Root $SD_CARD_ROOT partition not found. Is the device connected? Did you partition it?" 19 | if [ -e ./root ]; then 20 | rm -rf ./root || failure "Could not remove preexisting root directory. Is it still mounted? Is it yours?" 21 | fi 22 | mkdir ./root || failure "Could not create root directory mounting point." 23 | 24 | printInfo "Mounting $SD_CARD_ROOT into ./root" 25 | sudo mount $SD_CARD_ROOT ./root || failure "Could not mount the root partition." 26 | printInfo "Done." 27 | 28 | printInfo 29 | printInfo "Adding autoloading of g_cdc to ./root/etc/modules-load.d/usb0.conf" 30 | read -p "Do you want to continue? [Y/n]: " 31 | if [[ $REPLY =~ ^[nN]$ ]]; then 32 | sudo umount ./root 33 | failure "Terminating." 34 | fi 35 | sudo bash < ./root/etc/modules-load.d/usb0.conf 37 | EOF 38 | if [ $? -ne 0 ]; then 39 | sudo umount ./root 40 | failure "Could not add the g_cdc module config file." 41 | fi 42 | printInfo "Done." 43 | 44 | printInfo 45 | printInfo "Adding usb0 network config file ./root/etc/systemd/network/usb0.network" 46 | sudo bash < ./root/etc/systemd/network/usb0.network < /etc/systemd/network/pp.network <> /dev/stderr 11 | } 12 | 13 | printWarning() { 14 | echo "WARNING: $*" 15 | } 16 | 17 | printNotice() { 18 | echo "NOTICE: $*" 19 | } 20 | 21 | printInfo() { 22 | echo "$*" 23 | } 24 | 25 | failure() { 26 | printError $* 27 | exit 1 28 | } 29 | 30 | stageFinished() { 31 | printInfo 32 | printInfo " STAGE CLEAR!" 33 | printInfo $@ 34 | } 35 | 36 | # 37 | # Common definitions 38 | # 39 | ROOTFS_URL=http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz 40 | ROOTFS_ARCHIVE=rootfs.tar.gz 41 | 42 | # 5.8 kernel 43 | #KERNEL_URL=https://xff.cz/kernels/5.8/pp1.tar.gz # PP 1.1 44 | KERNEL_URL=https://xff.cz/kernels/5.8/pp2.tar.gz # PP 1.2 45 | 46 | KERNEL_ARCHIVE=kernel.tar.gz 47 | KERNEL_DIR=kernel 48 | 49 | [ -z ${EDITOR+x} ] && command -v vim >> /dev/null && EDITOR=vim 50 | [ -z ${EDITOR+x} ] && command -v nano >> /dev/null && EDITOR=nano 51 | [ -z ${EDITOR+x} ] && command -v pico >> /dev/null && EDITOR=pico 52 | [ -z ${EDITOR+x} ] && command -v vi >> /dev/null && EDITOR=vi 53 | [ -z ${EDITOR+x} ] && EDITOR=cat 54 | 55 | [ -f config.sh ] || failure "File 'config.sh' not found. Create it from the template 'config.sh.default' and try again." 56 | source config.sh 57 | 58 | export ROOTFS_URL 59 | export ROOTFS_ARCHIVE 60 | export KERNEL_URL 61 | export KERNEL_ARCHIVE 62 | export KERNEL_DIR 63 | export EDITOR 64 | 65 | -------------------------------------------------------------------------------- /config.sh.default: -------------------------------------------------------------------------------- 1 | # 2 | # Configuration 3 | # 4 | # To be sourced into the individual installation scripts. 5 | # 6 | 7 | if [[ $_ == $0 ]]; then 8 | echo "config.sh should be sourced and not executed" >> /dev/stderr 9 | exit 1 10 | fi 11 | 12 | ## SD CARD 13 | # SD Card Device, e.g. /dev/sdb (the whole device, not a partition!) 14 | SD_CARD_DEVICE=/dev/sdx 15 | # SD Card boot partition, e.g. /dev/sdb1 16 | SD_CARD_BOOT=${SD_CARD_DEVICE}1 17 | # SD Card root partition, e.g. /dev/sdb2 18 | SD_CARD_ROOT=${SD_CARD_DEVICE}2 19 | 20 | # export all the variables 21 | export SD_CARD_DEVICE 22 | export SD_CARD_BOOT 23 | export SD_CARD_ROOT 24 | 25 | --------------------------------------------------------------------------------