#!/bin/bash
# Archtoarmtix alpha by Jack.
# This scripts converts Arch Linux Arm minimal image to Armtix with Dinit.
# Born to convert Danct alarm (barebone) to armtix on the pinephone. Boot and kernel
# should not change.
# GUIDE:
# - review the script.
# If its not Danct distro comment / uncomment the lines in the script, or remove
# its repo after the script.
# For a better (but slower) installation, uncomment the lines to reinstall all the
# packages.
# - flash and boot a minimal alarm image
# - conntect to internet and become root
# - run the script
# - review the patched pacman.conf.
# - reboot
#
printf "Arch Linux Arm to Armtix script\nInternet required."
read -n 1 -s -r -p "press any key to continue or ctrl+c..."
# update and time sync
echo "Updating arch..."
pacman -Syyu --noconfirm
if [ $? -gt 0 ]; then read -p "Update failed! Continue ? (y/n): " ireply; if [ "$ireply" != "y" ]; then exit 1; fi fi
pacman -S ntp wget --noconfirm
echo "Updating time..."
ntpdate pool.ntp.org && hwclock -w
# fix pacman.conf and mirrorlist
mv -f /etc/pacman.conf /etc/pacman.conf.arch
wget -O /etc/pacman.conf https://gitlab.com/phkr/artixarm/-/raw/master/system/pacman/pacman.conf?inline=false
if [ $? -gt 0 ]; then echo "Error downloading pacman.conf! Using the local one..."; cp -f oldpacman.conf /etc/pacman.conf; fi
sed -i 's/@CARCH@/aarch64/' /etc/pacman.conf
sed -i 's|\[system\].*|\[danctnix\]\nServer = https://p64.arikawa-hi.me/danctnix/aarch64/\n\n\[system\]\nSigLevel=Never|' /etc/pacman.conf
#sed -i 's|\[system\].*|\[system\]\nSigLevel=Never|' /etc/pacman.conf
sed -i 's|\[world\].*|\[world\]\nSigLevel=Never|' /etc/pacman.conf
sed -i 's|\[galaxy\].*|\[galaxy\]\nSigLevel=Never|' /etc/pacman.conf
sed -i '/\[extra\]/s/^#//' /etc/pacman.conf
sed -i '/\[community\]/s/^#//' /etc/pacman.conf
sed -i '/\[alarm\]/s/^#//' /etc/pacman.conf
sed -i '/\[aur\]/s/^#//' /etc/pacman.conf
sed -i '/mirrorlist-archlinuxarm/s/^#//' /etc/pacman.conf
mv -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist-archlinuxarm
wget -O /etc/pacman.d/mirrorlist https://gitlab.com/phkr/artixarm/-/raw/master/system/artix-mirrorlist/mirrorlist?inline=false
if [ $? -gt 0 ]; then echo "Error downloading mirrorlist! Using the local one..."; cp -f oldmirrorlist /etc/pacman.d/mirrorlist; fi
cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist-armtix
# refresh repos
# clear cache and sync
pacman -Scc << EOF
y
n
EOF
echo "Updating repositories..."
pacman -Syy --noconfirm
if [ $? -gt 0 ]; then read -p "Repositories update failed! Continue ? (y/n): " ireply; if [ "$ireply" != "y" ]; then exit 1; fi fi
pacman -S artix-keyring --noconfirm
pacman-key --populate artix
# backup enabled services on arch
systemctl list-units --state=running | grep -v systemd | awk '{print $1}' | grep service > arch-autostarted-services
# download Dinit and tools
echo "Installing the init and software..."
pacman -Sw base base-devel dinit dinit-system udev elogind dbus networkmanager samba archlinuxarm-mirrorlist openssh net-tools rsync nano lsb-release esysusers etmpfiles --noconfirm
if [ $? -gt 0 ]; then read -p "Download failed! Continue ? (y/n): " ireply; if [ "$ireply" != "y" ]; then exit 1; fi fi
# remove systemd
pacman -Rdd --noconfirm systemd systemd-libs systemd-sysvcompat pacman-mirrorlist --noconfirm
rm -fv /etc/resolv.conf
cp -vf /etc/pacman.d/mirrorlist-armtix /etc/pacman.d/mirrorlist
rm /usr/share/libalpm/hooks/dbus-reload.hook
dhcpcd
# install Dinit and tools
pacman -S base base-devel dinit dinit-system udev elogind dbus networkmanager samba archlinuxarm-mirrorlist openssh net-tools rsync nano lsb-release esysusers etmpfiles --noconfirm
if [ $? -gt 0 ]; then read -p "Update failed! Continue ? (y/n): " ireply; if [ "$ireply" != "y" ]; then exit 1; fi fi
export LC_ALL=C
# install services scripts
pacman -S elogind-dinit dbus-dinit networkmanager-dinit alsa-utils alsa-utils-dinit haveged haveged-dinit openssh-dinit --noconfirm # autofs-dinit?
if [ $? -gt 0 ]; then read -p "Update failed! Continue ? (y/n): " ireply; if [ "$ireply" != "y" ]; then exit 1; fi fi
pacman -Syu --noconfirm
# enable important services
#dinitctl enable udevd
#dinitctl enable NetworkManager
#dinitctl enable dbus
#dinitctl enable sshd
ln -s /etc/dinit.d/udevd /etc/dinit.d/boot.d/
ln -s /etc/dinit.d/NetworkManager /etc/dinit.d/boot.d/
ln -s /etc/dinit.d/dbus /etc/dinit.d/boot.d/
ln -s /etc/dinit.d/sshd /etc/dinit.d/boot.d/
# reinstall packages - skipped
#pacman -Sl system | grep installed | cut -d" " -f2 | pacman -S -
#pacman -Sl world | grep installed | cut -d" " -f2 | pacman -S -
#pacman -Sl galaxy | grep installed | cut -d" " -f2 | pacman -S -
# remove more systemd files
echo "Removing more systemd files..."
for user in journal journal-gateway timesync network bus-proxy journal-remote journal-upload resolve coredump; do
userdel systemd-$user
done
rm -vfr /{etc,var/lib}/systemd
echo "All done!"
read -p "Reboot ? (y/n): " ireply
if [ "$ireply" = "y" ]; then
reboot
fi
exit 0