2020-12-08 12:14:43 -05:00
|
|
|
#! /bin/bash
|
2020-12-08 12:26:37 -05:00
|
|
|
#
|
2024-06-01 22:15:37 -04:00
|
|
|
# Copyright 2020, Stormux, <storm_dragon@stormux.org>
|
2020-12-08 12:26:37 -05:00
|
|
|
#
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 3, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# This software is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this package; see the file COPYING. If not, write to the Free
|
|
|
|
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
# 02110-1301, USA.
|
|
|
|
#
|
2020-12-08 12:14:43 -05:00
|
|
|
|
2020-12-09 10:39:57 -05:00
|
|
|
# keep track of mounted status for exit function
|
|
|
|
mounted=1
|
|
|
|
|
2020-12-08 12:14:43 -05:00
|
|
|
set -e # Don't want to destroy stuff if this goes majorly wrong.
|
2020-12-09 10:39:57 -05:00
|
|
|
trap cleanup EXIT # make sure the script cleans up after itself before closing.
|
|
|
|
|
2020-12-08 21:58:13 -05:00
|
|
|
|
2020-12-09 10:39:57 -05:00
|
|
|
cleanup() {
|
|
|
|
if [[ $mounted -eq 0 ]]; then
|
|
|
|
umount -R /mnt
|
2020-12-09 19:40:39 -05:00
|
|
|
partx -d "${loopdev}"
|
|
|
|
losetup --detach "${loopdev}"
|
2020-12-09 10:39:57 -05:00
|
|
|
fi
|
2022-03-02 09:21:37 -05:00
|
|
|
if [[ -n "${imageFileName}" ]]; then
|
|
|
|
rm "${imageFileName}"
|
|
|
|
fi
|
2020-12-09 10:39:57 -05:00
|
|
|
exit 0
|
|
|
|
}
|
2020-12-08 21:58:13 -05:00
|
|
|
|
|
|
|
help() {
|
|
|
|
echo -e "Usage:\n"
|
2020-12-09 08:24:34 -05:00
|
|
|
echo "With no arguments, build with default parameters."
|
2020-12-08 21:58:13 -05:00
|
|
|
for i in "${!command[@]}" ; do
|
2020-12-12 14:56:20 -05:00
|
|
|
echo "-${i/:/ <parameter>}: ${command[${i}]}"
|
2020-12-08 21:58:13 -05:00
|
|
|
done | sort
|
|
|
|
exit 0
|
|
|
|
}
|
2022-03-25 03:04:09 -04:00
|
|
|
|
2020-12-08 21:58:13 -05:00
|
|
|
# Array of command line arguments
|
|
|
|
declare -A command=(
|
|
|
|
[h]="This help screen."
|
2020-12-12 14:56:20 -05:00
|
|
|
[l:]="Language default is en_US."
|
2022-04-02 16:47:27 -04:00
|
|
|
[n:]="Image name, default is stormux-pi<32|64>-<yyyy-mm-dd>.img"
|
2020-12-12 14:56:20 -05:00
|
|
|
[s:]="image size in GB, default is 4."
|
2022-04-02 16:47:27 -04:00
|
|
|
[v:]="Version of the Raspberry Pi for which you are building. (32|64) default is 64."
|
2020-12-08 21:58:13 -05:00
|
|
|
)
|
2022-03-25 03:04:09 -04:00
|
|
|
|
2020-12-08 21:58:13 -05:00
|
|
|
# Convert the keys of the associative array to a format usable by getopts
|
|
|
|
args="${!command[*]}"
|
|
|
|
args="${args//[[:space:]]/}"
|
|
|
|
while getopts "${args}" i ; do
|
|
|
|
case "$i" in
|
2022-03-25 03:04:09 -04:00
|
|
|
h) help ;;
|
2020-12-12 14:56:20 -05:00
|
|
|
l)
|
|
|
|
imageLanguage="${OPTARG}.UTF-8"
|
2022-03-25 03:04:09 -04:00
|
|
|
;;
|
2020-12-08 21:58:13 -05:00
|
|
|
n)
|
2020-12-12 14:56:20 -05:00
|
|
|
imageName="${OPTARG}"
|
2022-03-25 03:04:09 -04:00
|
|
|
;;
|
2020-12-08 21:58:13 -05:00
|
|
|
s)
|
2020-12-12 14:56:20 -05:00
|
|
|
if [[ "${OPTARG}" =~ ^[[:digit:]]+$ ]]; then
|
|
|
|
imageSize="${OPTARG}G"
|
2020-12-08 21:58:13 -05:00
|
|
|
else
|
|
|
|
echo "Image size must be numeric."
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-25 03:04:09 -04:00
|
|
|
;;
|
2020-12-08 21:58:13 -05:00
|
|
|
v)
|
2022-04-02 16:47:27 -04:00
|
|
|
if [[ "${OPTARG}" =~ ^32|64$ ]]; then
|
2020-12-12 14:56:20 -05:00
|
|
|
imageVersion="${OPTARG}"
|
2020-12-08 21:58:13 -05:00
|
|
|
else
|
2022-04-02 16:47:27 -04:00
|
|
|
echo "Image version must be 32 for 32 bit (armv7h), or 64 for 64 bit (aarch64 default)."
|
2020-12-08 21:58:13 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-25 03:04:09 -04:00
|
|
|
;;
|
2020-12-12 14:56:20 -05:00
|
|
|
*)
|
|
|
|
exit 1
|
2022-03-25 03:04:09 -04:00
|
|
|
;;
|
2020-12-08 21:58:13 -05:00
|
|
|
esac
|
|
|
|
done
|
2022-03-25 03:04:09 -04:00
|
|
|
|
2020-12-08 21:58:13 -05:00
|
|
|
# make sure variables are set, or use defaults.
|
2022-04-02 16:47:27 -04:00
|
|
|
export imageVersion="${imageVersion:-64}"
|
2024-11-03 02:17:03 -05:00
|
|
|
export imageSize="${imageSize:-6G}"
|
2022-04-02 16:47:27 -04:00
|
|
|
imageName="${imageName:-stormux-pi4-${imageVersion}-$(date '+%Y-%m-%d').img}"
|
|
|
|
imageName="${imageName/-64-/-aarch64-}"
|
|
|
|
imageName="${imageName/-32-/-armv7h-}"
|
|
|
|
export imageName
|
2020-12-12 14:56:20 -05:00
|
|
|
export imageLanguage="${imageLanguage:-en_US.UTF-8}"
|
2020-12-08 21:58:13 -05:00
|
|
|
|
|
|
|
# Make sure the image file doesn't exist.
|
|
|
|
if [[ -e "$imageName" ]]; then
|
|
|
|
echo "${imageName} exists, please remove or move it for this script to continue."
|
|
|
|
exit 1
|
2020-12-08 12:14:43 -05:00
|
|
|
fi
|
2020-12-08 21:58:13 -05:00
|
|
|
|
|
|
|
# Make sure this script is ran as root.
|
2020-12-08 12:14:43 -05:00
|
|
|
if [ "$(whoami)" != "root" ] ; then
|
2020-12-08 21:58:13 -05:00
|
|
|
echo "Error: This script must be run as root."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# make sure the needed tools are installed
|
|
|
|
if [[ "$(uname -m)" == "x86_64" ]]; then
|
|
|
|
if ! pacman -Q qemu-user-static &> /dev/null ; then
|
2023-01-01 14:55:07 -05:00
|
|
|
echo "Please install qemu-user-static and qemu-user-static-binfmt before continuing."
|
2022-02-05 12:25:52 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-01-01 14:55:07 -05:00
|
|
|
if ! pacman -Q qemu-user-static-binfmt &> /dev/null ; then
|
|
|
|
echo "Please install qemu-user-static and qemu-user-static-binfmt before continuing."
|
2020-12-08 21:58:13 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-12-08 12:14:43 -05:00
|
|
|
fi
|
2023-06-25 22:27:43 -04:00
|
|
|
for i in arch-install-scripts dosfstools parted wget ; do
|
2020-12-08 21:58:13 -05:00
|
|
|
if ! pacman -Q $i &> /dev/null ; then
|
|
|
|
echo "Please install $i before continuing."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2020-12-09 08:24:34 -05:00
|
|
|
# Url for the image to be downloaded.
|
2022-04-02 16:47:27 -04:00
|
|
|
url[32]="http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-armv7-latest.tar.gz"
|
|
|
|
url[64]="http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-aarch64-latest.tar.gz"
|
2020-12-09 08:24:34 -05:00
|
|
|
|
2020-12-24 13:15:37 -05:00
|
|
|
fallocate -l "$imageSize" "$imageName"
|
2020-12-08 21:58:13 -05:00
|
|
|
loopdev="$(losetup --find --show "${imageName}")"
|
2022-03-30 04:37:45 -04:00
|
|
|
parted --script "${loopdev}" mklabel msdos mkpart primary fat32 0% 200M mkpart primary ext4 200M 100%
|
2020-12-09 19:40:39 -05:00
|
|
|
mkfs.vfat -F32 "${loopdev}p1"
|
|
|
|
mkfs.ext4 -F "${loopdev}p2"
|
|
|
|
mount "${loopdev}p2" /mnt
|
2020-12-08 12:14:43 -05:00
|
|
|
mkdir /mnt/boot
|
2020-12-09 19:40:39 -05:00
|
|
|
mount "${loopdev}p1" /mnt/boot
|
2020-12-09 10:39:57 -05:00
|
|
|
# Things are mounted now, so set mounted to 0 (bash true)
|
|
|
|
mounted=0
|
2022-03-02 09:21:37 -05:00
|
|
|
imageFileName=$(mktemp)
|
|
|
|
wget "${url[$imageVersion]}" -O "${imageFileName}"
|
2023-01-21 01:31:45 -05:00
|
|
|
if [[ $imageVersion -eq 32 ]]; then
|
|
|
|
# Workaround for bsdtar errors when extracting 32 bit image.
|
|
|
|
set +e
|
|
|
|
fi
|
2022-03-02 09:21:37 -05:00
|
|
|
bsdtar -xpf "${imageFileName}" -C /mnt
|
2023-01-21 01:31:45 -05:00
|
|
|
# Set -e in case it got unset for 32 bit image
|
|
|
|
set -e
|
2020-12-09 08:53:05 -05:00
|
|
|
arch-chroot /mnt << EOF
|
2020-12-08 21:58:13 -05:00
|
|
|
# set up pacman
|
2020-12-08 12:14:43 -05:00
|
|
|
pacman-key --init
|
|
|
|
pacman-key --populate archlinuxarm
|
2022-04-02 16:47:27 -04:00
|
|
|
pacman -Syy
|
|
|
|
# Change kernels for aarch64
|
|
|
|
if [[ "$imageVersion" == "64" ]]; then
|
|
|
|
pacman -R --noconfirm linux-aarch64 uboot-raspberrypi
|
|
|
|
pacman -S --noconfirm linux-rpi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install packages
|
|
|
|
pacman -Su --needed --noconfirm \
|
2022-03-02 09:27:48 -05:00
|
|
|
alsa-firmware \
|
|
|
|
alsa-utils \
|
|
|
|
base \
|
|
|
|
base-devel \
|
|
|
|
bash-completion \
|
|
|
|
bluez \
|
|
|
|
bluez-utils \
|
|
|
|
brltty \
|
2023-01-17 19:41:17 -05:00
|
|
|
cloud-utils \
|
2022-03-02 09:27:48 -05:00
|
|
|
cronie \
|
|
|
|
espeak-ng \
|
2023-01-17 19:41:17 -05:00
|
|
|
fake-hwclock \
|
2023-12-29 11:44:19 -05:00
|
|
|
firmware-raspberrypi \
|
2022-03-02 09:27:48 -05:00
|
|
|
git \
|
2023-01-17 19:41:17 -05:00
|
|
|
go \
|
2022-03-02 09:27:48 -05:00
|
|
|
magic-wormhole \
|
|
|
|
man \
|
|
|
|
man-pages \
|
|
|
|
networkmanager \
|
2022-03-25 03:04:09 -04:00
|
|
|
pipewire \
|
|
|
|
pipewire-alsa \
|
|
|
|
pipewire-jack \
|
|
|
|
pipewire-pulse \
|
2023-08-19 08:42:51 -04:00
|
|
|
poppler \
|
2023-01-17 19:41:17 -05:00
|
|
|
python-pyudev \
|
|
|
|
python-daemonize \
|
|
|
|
python-evdev \
|
|
|
|
python-dbus \
|
|
|
|
python-pyte \
|
2024-02-16 01:14:10 -05:00
|
|
|
raspberrypi-utils \
|
2022-04-21 00:25:25 -04:00
|
|
|
realtime-privileges \
|
2022-03-02 09:27:48 -05:00
|
|
|
rhvoice-voice-bdl \
|
|
|
|
rng-tools \
|
|
|
|
rsync \
|
2023-08-19 18:04:24 -04:00
|
|
|
screen \
|
2022-03-02 09:27:48 -05:00
|
|
|
sox \
|
|
|
|
w3m \
|
|
|
|
wget \
|
|
|
|
wireless-regdb \
|
2022-03-25 03:04:09 -04:00
|
|
|
wireplumber \
|
2022-03-02 09:27:48 -05:00
|
|
|
xdg-user-dirs \
|
|
|
|
xdg-utils
|
|
|
|
|
2020-12-12 14:56:20 -05:00
|
|
|
# set the language
|
|
|
|
sed -i "s/#$imageLanguage/$imageLanguage/" /etc/locale.gen
|
|
|
|
echo "LANG=$imageLanguage" > /etc/locale.conf
|
|
|
|
locale-gen
|
2021-10-23 15:19:49 -04:00
|
|
|
# Configure and enable Hardware Random Number Generator
|
|
|
|
echo 'RNGD_OPTS="-o /dev/random -r /dev/hwrng"' > /etc/conf.d/rngd
|
|
|
|
systemctl enable rngd.service
|
2020-12-08 21:58:13 -05:00
|
|
|
# Set the distribution name.
|
|
|
|
echo 'Stormux \r (\l)' > /etc/issue
|
|
|
|
echo >> /etc/issue
|
|
|
|
# Change the alarm user to be stormux
|
2022-04-21 00:25:25 -04:00
|
|
|
usermod -a -g users -G wheel,realtime,audio,video,network,brlapi -m -d /home/stormux -l stormux alarm
|
2020-12-09 15:34:03 -05:00
|
|
|
# Grant sudo privileges to the stormux user for package installation.
|
|
|
|
echo 'stormux ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/wheel
|
2020-12-12 14:56:20 -05:00
|
|
|
# Set the password for the root user
|
|
|
|
echo -e "root\nroot" | passwd "root"
|
2020-12-09 15:34:03 -05:00
|
|
|
# Set the password for the stormux user
|
|
|
|
echo -e "stormux\nstormux" | passwd "stormux"
|
2020-12-08 21:58:13 -05:00
|
|
|
# Change to the stormux user and install some packages
|
2021-10-06 23:04:00 -04:00
|
|
|
sudo -iu stormux
|
|
|
|
# Create desktop, downloads, music, and other directories.
|
|
|
|
xdg-user-dirs-update
|
2023-01-17 19:41:17 -05:00
|
|
|
# Build AUR packages
|
|
|
|
export aurPackages=(fenrir-git \
|
|
|
|
growpartfs \
|
|
|
|
log2ram \
|
|
|
|
yay)
|
|
|
|
export PKGDEST=~/packages
|
|
|
|
for p in "\${aurPackages[@]}" ; do
|
|
|
|
git clone https://aur.archlinux.org/\${p}.git
|
|
|
|
cd ~/\${p}
|
|
|
|
makepkg -A
|
|
|
|
cd ~
|
|
|
|
rm -rf \${p}
|
|
|
|
done
|
2020-12-08 21:58:13 -05:00
|
|
|
exit
|
2023-01-17 19:41:17 -05:00
|
|
|
# Install built packages
|
|
|
|
for p in /home/stormux/packages/* ; do
|
|
|
|
pacman -U --noconfirm \${p}
|
|
|
|
done
|
|
|
|
rm -rf /home/stormux/packages/
|
2022-03-25 03:04:09 -04:00
|
|
|
# Enable linger so that hopefully sound will start at login.
|
2022-03-25 03:42:05 -04:00
|
|
|
mkdir -p /var/lib/systemd/linger
|
2022-03-25 03:04:09 -04:00
|
|
|
touch /var/lib/systemd/linger/stormux
|
2024-03-21 02:40:02 -04:00
|
|
|
systemctl --global enable pipewire.service pipewire-pulse.service
|
2022-03-25 03:04:09 -04:00
|
|
|
/usr/share/fenrirscreenreader/tools/configure_pipewire.sh
|
2023-01-17 19:41:17 -05:00
|
|
|
sudo -u stormux /usr/share/fenrirscreenreader/tools/configure_pipewire.sh
|
2020-12-09 08:24:34 -05:00
|
|
|
# Configure sudo for group wheel, remove nopasswd for the stormux user
|
2021-10-19 20:46:54 -04:00
|
|
|
echo '%wheel ALL=(ALL) ALL' > /etc/sudoers.d/wheel
|
2020-12-09 15:17:51 -05:00
|
|
|
# Set the hostname
|
|
|
|
echo stormux > /etc/hostname
|
2022-04-02 16:47:27 -04:00
|
|
|
# Configure services
|
2024-03-21 11:21:51 -04:00
|
|
|
systemctl disable systemd-networkd.service systemd-networkd.socket
|
2024-03-21 02:40:02 -04:00
|
|
|
systemctl enable brltty.path cronie.service fake-hwclock.service fenrirscreenreader.service log2ram.service NetworkManager.service
|
2022-04-02 16:47:27 -04:00
|
|
|
# Cleanup packages
|
|
|
|
pacman -Sc --noconfirm
|
2023-01-17 19:41:17 -05:00
|
|
|
pacman -R --noconfirm go
|
2022-02-19 23:04:14 -05:00
|
|
|
|
2022-04-02 16:47:27 -04:00
|
|
|
# Update fstab for Raspberry Pi 4. Not needed until linux-aarch64 works.
|
2022-03-30 04:38:47 -04:00
|
|
|
# [[ $imageVersion -eq 4 ]] && sed -i 's/mmcblk0/mmcblk1/g' /etc/fstab
|
2020-12-08 12:14:43 -05:00
|
|
|
EOF
|
2020-12-09 10:39:57 -05:00
|
|
|
|
2020-12-24 12:25:33 -05:00
|
|
|
# Copy override files into place.
|
2021-06-22 01:23:57 -04:00
|
|
|
cp -rv ../files/boot/* /mnt/boot
|
2020-12-24 12:25:33 -05:00
|
|
|
cp -rv ../files/etc/* /mnt/etc
|
2021-06-22 01:23:57 -04:00
|
|
|
cp -rv ../files/var/* /mnt/var
|
2021-10-26 12:04:35 -04:00
|
|
|
cp -rv ../files/usr/* /mnt/usr
|
2023-08-19 18:04:24 -04:00
|
|
|
find ../files/etc/skel/ -mindepth 1 -exec cp -rv "{}" /mnt/home/stormux/ \;
|
2020-12-24 12:25:33 -05:00
|
|
|
|
|
|
|
# Exiting calls the cleanup function to unmount.
|
2020-12-09 10:39:57 -05:00
|
|
|
exit 0
|