parent
911381a1a6
commit
cc3512f2d1
@ -1,310 +0,0 @@
|
||||
#! /bin/bash
|
||||
|
||||
# *****************************
|
||||
# Version 1.0
|
||||
# *****************************
|
||||
|
||||
DISKLAYOUT=${2:-"btrfs"}
|
||||
#DISKLAYOUT="ext4"
|
||||
KERNELVER=${3:-"kernel-pbp"}
|
||||
#KERNELVER="linux-manjaro"
|
||||
|
||||
# Fedora image read url as parameter
|
||||
FEDORAURL=${1:-"https://download.fedoraproject.org/pub/fedora/linux/releases/32/Workstation/aarch64/images/Fedora-Workstation-32-1.6.aarch64.raw.xz"}
|
||||
FEDORARAW="$(basename -s .xz "${FEDORAURL}")"
|
||||
FEDORAIMG="$(basename -s .aarch64.raw.xz "${FEDORAURL}")-${DISKLAYOUT}-${KERNELVER}-$(date '+%Y-%m-%d').img"
|
||||
|
||||
# Set globals
|
||||
TMPDIR=/var/tmp/fedora-installer
|
||||
MEDIADIR=/var/tmp/fedora-installer-media
|
||||
ARCH='aarch64'
|
||||
CARCH=$(uname -m)
|
||||
# systemd-nspawn --resolv-conf has been buggy. If you have issues you can try,
|
||||
# --resolv-conf=auto --resolv-conf=copy-host or --bind-ro=/etc/resolv.conf
|
||||
# It all depends how resolv.conf is managed on host and in image.
|
||||
NSPAWN='systemd-nspawn -q --resolv-conf=auto --timezone=off -D'
|
||||
#NSPAWN='systemd-nspawn -q --bind-ro=/etc/resolv.conf --timezone=off -D'
|
||||
|
||||
# set colorscheme
|
||||
export DIALOGRC="./dialogrc_gui"
|
||||
|
||||
# clearing variables
|
||||
DEVICE="Pinebook Pro"
|
||||
EDITION="Fedora Workstation"
|
||||
ROOTPASSWORD="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#$%^&*()' | fold -w 32 | head -n 1)"
|
||||
|
||||
# check if root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "*******************************************************************************************"
|
||||
echo "* *"
|
||||
echo "* This script requires root permissions to run. Please run as root or with sudo! *"
|
||||
echo "* *"
|
||||
echo "*******************************************************************************************"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Sanity checks for dependencies
|
||||
declare -a DEPENDNECIES=( "btrfs" "sed" "rsync" "systemd-nspawn" "wget" "openssl" "awk" )
|
||||
|
||||
for i in "${DEPENDNECIES[@]}"; do
|
||||
if ! [[ -f "/bin/$i" || -f "/sbin/$i" || -f "/usr/bin/$i" || -f "/usr/sbin/$i" ]] ; then
|
||||
echo "$i command is missing! Please install the relevant package."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$CARCH" != "aarch64" ]]; then
|
||||
if ! [[ -f "/usr/lib/binfmt.d/qemu-aarch64-static.conf" || -f "/usr/lib/binfmt.d/qemu-static.conf" ]]; then
|
||||
echo "qemu-aarch64-static.conf file is missing. Please install the relevant package."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
prepare_media() {
|
||||
# "Prepare source media..."
|
||||
|
||||
# fetch and extract fedora image
|
||||
if [ ! -f "$MEDIADIR/$FEDORARAW" ]; then
|
||||
# "Downloading Fedora Image..."
|
||||
wget -q --show-progress --progress=bar:force:noscroll $FEDORAURL --output-document $MEDIADIR/$FEDORARAW.xz || exit
|
||||
# "Decompress Fedora Image..."
|
||||
xz --decompress $MEDIADIR/$FEDORARAW.xz
|
||||
fi
|
||||
}
|
||||
|
||||
install_fedora() {
|
||||
# "Install Fedora from media..."
|
||||
|
||||
LOOP=$(losetup -f)
|
||||
# "Making mount directories..."
|
||||
mkdir -p $TMPDIR/imgfs/{2,3}
|
||||
|
||||
# "Mounting Fedora image..."
|
||||
|
||||
losetup $LOOP $MEDIADIR/$FEDORARAW
|
||||
partprobe -s $LOOP
|
||||
mount "$LOOP"p2 $TMPDIR/imgfs/2
|
||||
mount "$LOOP"p3 $TMPDIR/imgfs/3
|
||||
|
||||
# "Copying Fedora files (progress status sucks)..."
|
||||
if [[ $(blkid -s TYPE -o value "$LOOP"p3) = btrfs ]]; then
|
||||
rsync -a --info=progress2 $TMPDIR/imgfs/3/root/* $TMPDIR/root/
|
||||
else
|
||||
rsync -a --info=progress2 $TMPDIR/imgfs/3/* $TMPDIR/root/
|
||||
fi
|
||||
rsync -a --info=progress2 $TMPDIR/imgfs/2/* $TMPDIR/root/boot/
|
||||
|
||||
# "Unmounting Fedora media..."
|
||||
umount "$LOOP"p2
|
||||
umount "$LOOP"p3
|
||||
losetup -d $LOOP
|
||||
|
||||
# "Deleting temp directories..."
|
||||
rmdir $TMPDIR/imgfs/2
|
||||
rmdir $TMPDIR/imgfs/3
|
||||
rmdir $TMPDIR/imgfs
|
||||
|
||||
}
|
||||
|
||||
upgrade_fedora() {
|
||||
# "Upgrade Fedora and add packages..."
|
||||
|
||||
# "Remove packages not needed..."
|
||||
$NSPAWN $TMPDIR/root dnf remove -y kernel kernel-core kernel-modules grub2-* efi-filesystem bcm283x-firmware 1> /dev/null 2>&1
|
||||
rm -rf $TMPDIR/root/boot/*
|
||||
# "Upgrade Fedora..."
|
||||
mkdir -p $TMPDIR/dnf
|
||||
mount -o bind $TMPDIR/dnf $TMPDIR/root/var/cache/dnf
|
||||
$NSPAWN $TMPDIR/root dnf upgrade -y --refresh
|
||||
|
||||
# "Enable copr/aptupdate/pinebook-pro..."
|
||||
$NSPAWN $TMPDIR/root dnf copr enable -y aptupdate/pinebook-pro
|
||||
$NSPAWN $TMPDIR/root dnf makecache
|
||||
|
||||
# "Install Pinebook Pro copr packages..."
|
||||
if [[ "$KERNELVER" = "kernel-pbp" ]]; then
|
||||
$NSPAWN $TMPDIR/root dnf install -y kernel-pbp uboot-pinebookpro pinebookpro-extlinux ap6256-firmware pbp-keyboard-hwdb pinebookpro-suspend pinebookpro-audio pinebookpro-network
|
||||
else
|
||||
# KERNELVER=linux-majaro
|
||||
$NSPAWN $TMPDIR/root dnf install -y linux-manjaro uboot-pinebookpro pinebookpro-extlinux ap6256-firmware pbp-keyboard-hwdb pinebookpro-suspend pinebookpro-audio pinebookpro-network
|
||||
fi
|
||||
|
||||
# "Enable services from packages..."
|
||||
$NSPAWN $TMPDIR/root systemctl enable acpid.service
|
||||
|
||||
# "Clear dnf cache..."
|
||||
umount $TMPDIR/root/var/cache/dnf
|
||||
$NSPAWN $TMPDIR/root dnf clean all 1> /dev/null 2>&1
|
||||
|
||||
}
|
||||
|
||||
configure_fedora() {
|
||||
# "Configure Fedora..."
|
||||
# "Run SELinux autorelabel first boot..."
|
||||
touch $TMPDIR/root/.autorelabel
|
||||
|
||||
# Get UUID
|
||||
BOOTUUID=$(blkid -s UUID -o value "${SDCARD}${SDDEV}1")
|
||||
ROOTUUID=$(blkid -s UUID -o value "${SDCARD}${SDDEV}2")
|
||||
|
||||
if [[ "$DISKLAYOUT" = "ext4" ]]; then
|
||||
# Configure extlinux.conf
|
||||
# "Update extlinux.conf with UUID..."
|
||||
mkdir ${TMPDIR}/root/boot/extlinux/ -p
|
||||
echo "LABEL Fedora PinebookPro" > ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
echo "KERNEL /Image" >> ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
echo "FDT /dtbs/rockchip/rk3399-pinebook-pro.dtb" >> ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
echo "INITRD /initramfs-linux.img" >> ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
echo "APPEND console=tty1 console=ttyS2,1500000 root=UUID=${ROOTUUID} rw rhgb quiet" >> ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
|
||||
# "Update fstab with UUID..."
|
||||
# Edit fstab
|
||||
echo "UUID=${ROOTUUID} / ext4 defaults 0 1" > $TMPDIR/root/etc/fstab
|
||||
echo "UUID=${BOOTUUID} /boot ext4 defaults 0 2" >> $TMPDIR/root/etc/fstab
|
||||
else
|
||||
# DISKLAYOUT = btrfs
|
||||
# "Update extlinux.conf with UUID..."
|
||||
# Configure extlinux.conf
|
||||
mkdir ${TMPDIR}/root/boot/extlinux/ -p
|
||||
echo "LABEL Fedora PinebookPro" > ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
echo "KERNEL /Image" >> ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
echo "FDT /dtbs/rockchip/rk3399-pinebook-pro.dtb" >> ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
echo "INITRD /initramfs-linux.img" >> ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
echo "APPEND console=tty1 console=ttyS2,1500000 root=UUID=${ROOTUUID} rw rootflags=subvol=root rhgb quiet" >> ${TMPDIR}/root/boot/extlinux/extlinux.conf
|
||||
|
||||
# "Update fstab with UUID..."
|
||||
# Edit fstab
|
||||
echo "UUID=${ROOTUUID} / btrfs subvol=root 0 0" > $TMPDIR/root/etc/fstab
|
||||
echo "UUID=${BOOTUUID} /boot ext4 defaults 1 2" >> $TMPDIR/root/etc/fstab
|
||||
echo "UUID=${ROOTUUID} /home btrfs subvol=home 0 0" >> $TMPDIR/root/etc/fstab
|
||||
fi
|
||||
|
||||
# "Fix update-uboot for pinebook-pro-rk3399"
|
||||
# Fixed in arm-image-installer => 3.0
|
||||
if [ ! -f "$TMPDIR/root/usr/share/arm-image-installer/boards.d/pinebook-pro-rk3399" ]; then
|
||||
ln -s ../socs.d/Rockchips-ARMv8 $TMPDIR/root/usr/share/arm-image-installer/boards.d/pinebook-pro-rk3399
|
||||
fi
|
||||
|
||||
# "Setting up users..."
|
||||
echo "$ROOTPASSWORD" > $TMPDIR/rootpassword
|
||||
|
||||
# "Setting password for root ..."
|
||||
$NSPAWN $TMPDIR/root awk -i inplace -F: "BEGIN {OFS=FS;} \$1 == \"root\" {\$2=\"$(openssl passwd -1 $(cat $TMPDIR/rootpassword))\"} 1" /etc/shadow 1> /dev/null 2>&1
|
||||
|
||||
# Remove temp files on host
|
||||
rm -rf $TMPDIR/rootpassword
|
||||
|
||||
# "$DEVICE $EDITION install complete"
|
||||
}
|
||||
|
||||
prepare_card () {
|
||||
# "Getting img ready..."
|
||||
LOOPIMG=$(losetup -f)
|
||||
fallocate -l 8GiB $MEDIADIR/$FEDORAIMG
|
||||
losetup "${LOOPIMG}" $MEDIADIR/$FEDORAIMG
|
||||
SDCARD="${LOOPIMG}"
|
||||
SDDEV="p"
|
||||
partprobe -s ${SDCARD}
|
||||
echo -e "label:gpt" | sfdisk ${SDCARD} 1> /dev/null 2>&1
|
||||
|
||||
# "Create partitions..."
|
||||
#Clear first 32mb
|
||||
dd if=/dev/zero of=${SDCARD} bs=1M count=32 1> /dev/null 2>&1
|
||||
|
||||
# "Partition $DEV_NAME"
|
||||
# "Partition with boot and root"
|
||||
echo -e "label:gpt\nunit:sectors\nfirst-lba:32768" | sfdisk ${SDCARD} 1> /dev/null 2>&1
|
||||
sleep 1
|
||||
echo -e "n\n1\n32768\n+1G\nn\n2\n\n\nx\nA\n1\nr\nw" | fdisk ${SDCARD} 1> /dev/null 2>&1
|
||||
|
||||
# "List partitions..."
|
||||
partprobe -s ${SDCARD}
|
||||
fdisk -l ${SDCARD} 1> /dev/null 2>&1
|
||||
}
|
||||
|
||||
format_card () {
|
||||
# "Format partitions on $DEV_NAME"
|
||||
if [[ "$DISKLAYOUT" = "ext4" ]]; then
|
||||
mkfs.ext4 -F -O ^metadata_csum,^64bit "${SDCARD}${SDDEV}1" -L "fedora-boot" 1> /dev/null 2>&1
|
||||
mkfs.ext4 -F -O ^metadata_csum,^64bit "${SDCARD}${SDDEV}2" -L "fedora-root" 1> /dev/null 2>&1
|
||||
sleep 1
|
||||
mkdir -p $TMPDIR/root
|
||||
mount ${SDCARD}${SDDEV}2 $TMPDIR/root || exit
|
||||
sleep 1
|
||||
mkdir -p $TMPDIR/root/boot
|
||||
mount ${SDCARD}${SDDEV}1 $TMPDIR/root/boot || exit
|
||||
sleep 1
|
||||
else
|
||||
# DISKLAYOUT = btrfs
|
||||
mkfs.ext4 -F -O ^metadata_csum,^64bit "${SDCARD}${SDDEV}1" -L "fedora-boot" 1> /dev/null 2>&1
|
||||
mkfs.btrfs -f "${SDCARD}${SDDEV}2" -L "<FS_TREE>" 1> /dev/null 2>&1
|
||||
mkdir -p $TMPDIR/root
|
||||
mount ${SDCARD}${SDDEV}2 $TMPDIR/root || exit
|
||||
sleep 1
|
||||
# "Create btrfs subvolumes..."
|
||||
btrfs subvolume create $TMPDIR/root/root 1> /dev/null 2>&1
|
||||
btrfs subvolume create $TMPDIR/root/home 1> /dev/null 2>&1
|
||||
umount $TMPDIR/root || exit
|
||||
sleep 1
|
||||
# "Mount all partitions..."
|
||||
mount -t btrfs -o subvol=root ${SDCARD}${SDDEV}2 $TMPDIR/root || exit
|
||||
sleep 1
|
||||
mkdir -p $TMPDIR/root/home
|
||||
mount -t btrfs -o subvol=home ${SDCARD}${SDDEV}2 $TMPDIR/root/home || exit
|
||||
sleep 1
|
||||
mkdir -p $TMPDIR/root/boot
|
||||
mount ${SDCARD}${SDDEV}1 $TMPDIR/root/boot || exit
|
||||
sleep 1
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup () {
|
||||
# "Writing bootloader and cleaning up after install..."
|
||||
# Flash bootloader
|
||||
dd if=$TMPDIR/root/boot/idbloader.img of=${SDCARD} seek=64 conv=notrunc,fsync 1> /dev/null 2>&1
|
||||
dd if=$TMPDIR/root/boot/u-boot.itb of=${SDCARD} seek=16384 conv=notrunc,fsync 1> /dev/null 2>&1
|
||||
|
||||
# "Apply workaround for poor key import UI in PackageKit"
|
||||
$NSPAWN $TMPDIR/root rm -f /var/lib/rpm/__db* 1> /dev/null 2>&1
|
||||
$NSPAWN $TMPDIR/root rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$(rpm --eval '%{fedora}')-$arch 1> /dev/null 2>&1
|
||||
# "Packages within this ARM disk image"
|
||||
$NSPAWN $TMPDIR/root rpm -qa --qf '%{size}\t%{name}-%{version}-%{release}.%{arch}\n' |sort -rn 1> /dev/null 2>&1
|
||||
# Note that running rpm recreates the rpm db files which aren't needed or wanted
|
||||
$NSPAWN $TMPDIR/root rm -f /var/lib/rpm/__db* 1> /dev/null 2>&1
|
||||
|
||||
# "Remove random seed, the new install should make it's own"
|
||||
$NSPAWN $TMPDIR/root rm -f /var/lib/systemd/random-seed 1> /dev/null 2>&1
|
||||
|
||||
# "Disabling tmpfs for /tmp."
|
||||
$NSPAWN $TMPDIR/root systemctl mask tmp.mount 1> /dev/null 2>&1
|
||||
|
||||
# "Reset machine-id"
|
||||
$NSPAWN $TMPDIR/root rm -f /etc/machine-id 1> /dev/null 2>&1
|
||||
touch /etc/machine-id 1> /dev/null 2>&1
|
||||
|
||||
#clean up
|
||||
umount $TMPDIR/root/home 1> /dev/null 2>&1
|
||||
umount $TMPDIR/root/boot
|
||||
umount $TMPDIR/root
|
||||
partprobe $SDCARD 1> /dev/null 2>&1
|
||||
|
||||
losetup -d "${LOOPIMG}"
|
||||
rm -rf $TMPDIR
|
||||
# "Not removing installation media $MEDIADIR"
|
||||
}
|
||||
|
||||
if [ ! -f "$TMPDIR" ]; then
|
||||
rm -rf $TMPDIR
|
||||
fi
|
||||
|
||||
mkdir -p $MEDIADIR
|
||||
mkdir -p $TMPDIR
|
||||
|
||||
prepare_media
|
||||
prepare_card
|
||||
format_card
|
||||
install_fedora
|
||||
upgrade_fedora
|
||||
configure_fedora
|
||||
cleanup
|
||||
sync
|
Loading…
Reference in new issue