Skip to content

Instantly share code, notes, and snippets.

@echawk
Last active September 1, 2023 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save echawk/bfc85d5ba858456f7cf3966f5ac82544 to your computer and use it in GitHub Desktop.
Save echawk/bfc85d5ba858456f7cf3966f5ac82544 to your computer and use it in GitHub Desktop.
An old Arch to Artix conversion script that might be of use to someone
#!/bin/bash
# LICENSE: MIT
#TODO:
# - need to check and make sure this script is up to date with the migration process [ ]
# - the script doesn't seem to work when I have been testing it. it does most of the stuff
# properly, however it doesn't seem to get the install *quite* right. I need to do
# much, much more testing before I can properly use this
#run this script as root
#also checkout the new migration article on artix's website, they added in init specific documentation
#url=https://wiki.artixlinux.org/Main/Migration
artix_mirrorlist="https://gitea.artixlinux.org/artixlinux/packages/raw/branch/master/artix-mirrorlist/trunk/mirrorlist"
artix_pacman_conf="https://gitea.artixlinux.org/artixlinux/packages/raw/branch/master/pacman/trunk/pacman.conf"
arch_pacman_conf_backup="/etc/pacman-conf-backup"
arch_mirrorlist_backup="/etc/pacman.d/mirrorlist-backup"
cache_dir="$HOME/.cache"
init="openrc" #runit, s6, or openrc
disk="/dev/sda"
die(){
printf "$1 Exiting...\n"
exit 1
}
give_warning(){
echo "This script can cause potentially unwanted changes to your arch based system.
Please inspect this script yourself before running it!!!
Now's your last chance to turn back!\n"
printf "Continue with conversion? (y/n):"
read -r answer
answer=$(printf $answer | tr [:upper:] [:lower:]) # clean up answer
[ "$answer" = "y" ] && return 0 || return 1 # 0 if yes, 1 if no
}
# no root needed
backup(){
# if backup files dont exist, create them
[ -f ${arch_pacman_conf_backup} ] || cp /etc/pacman.conf "$arch_pacman_conf_backup" && echo "Copied /etc/pacman.conf to ${arch_pacman_conf_backup}"
[ -f ${arch_mirrorlist_backup} ] || cp /etc/pacman.d/mirrorlist "$arch_mirrorlist_backup" && echo "Copied /etc/pacman.d/mirrorlist to ${arch_mirrorlist_backup}"
}
# no root needed
fetch_artix_files(){
[ -d $cache_dir ] || mkdir -p $cache_dir
cd $cache_dir
curl -LO "$artix_mirrorlist"
curl -LO "$artix_pacman_conf"
}
# root needed
move_arch_mirrors(){
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist-arch
}
# root needed
move_artix_files_to_place(){
cp -f "$cache_dir/pacman.conf" /etc/pacman.conf
cp -f "$cache_dir/mirrorlist" /etc/pacman.d/mirrorlist
}
# root needed
remove_pacman_cache(){
pacman -Scc && pacman -Syy
}
remove_sig_req(){
# improve regex
sed -i 's/Required DatabaseOptional/Never/' /etc/pacman.conf
}
install_artix_key(){
pacman -S artix-keyring
pacman-key --populate artix
pacman-key --lsign-key 95AEC5D0C1E294FC9F82B253573A673A53C01BC2
}
restore_sig_req(){
# improve regex
sed -i 's/Never/Required DatabaseOptional/' /etc/pacman.conf
}
backup_daemons(){
systemctl list-units --state=running |
grep -v systemd |
awk '{print $1}' |
grep service > daemon.list
}
down_artix_pkgs(){
pacman -Sw --noconfirm base \
base-devel \
${init}-system \
grub \
linux \
linux-headers \
elogind-${init} \
${init} \
netifrc \
grub \
mkinitcpio \
archlinux-mirrorlist \
net-tools \
rsync \
nano \
lsb-release \
opensysusers \
opentmpfiles
}
rem_sysd(){
pacman -Rdd --noconfirm systemd systemd-libs systemd-sysvcompat pacman-mirrorlist dbus
rm -fv /etc/resolv.conf
# restore artix mirrorlist
cp -vf /etc/pacman.d/mirrorlist.pacsave /etc/pacman.d/mirrorlist
}
install_artix_pkgs(){
pacman -S --needed --noconfirm base \
base-devel \
${init}-system \
grub \
linux \
linux-headers \
elogind-${init} \
${init} \
netifrc \
grub \
mkinitcpio \
archlinux-mirrorlist \
net-tools \
rsync \
nano \
lsb-release \
opensysusers \
opentmpfiles
}
reinstall_pkgs(){
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 -
}
# use the backed up init services
#install_init_scripts(){
enable_init_scripts(){
echo "Enabling Init scripts..."
if [ $init = openrc ]
then
for daemon in acpid alsasound autofs cronie cupsd xdm fuse haveged hdparm smb sshd syslog-ng; do rc-update add $daemon default; done
rc-update add udev sysinit
elif [ $init = runit ]
then
for daemon in acpid alsasound autofs cronie cupsd dbus elogind xdm fuse haveged hdparm smb sshd syslog-ng; do ln -s /etc/runit/sv/$daemon /etc/runit/runsvdir/default; done
elif [ $init = s6 ]
then
s6-rc-bundle -c /etc/s6/rc/compiled add default acpid alsasound autofs cronie cupsd elogind xdm fuse haveged hdparm smb sshd syslog-ng
fi
}
conf_networking(){
echo "Configuring Networking..."
echo "8.8.8.8" > /etc/resolv.conf
}
lvm_enable(){
if [ $init = openrc ]
then
rc-update add lvm boot
rc-update add device-mapper boot
elif [ $init = runit ]
then
ln -s /etc/runit/sv/lvm2 /etc/runit/runsvdir/default
ln -s /etc/runit/sv/device-mapper /etc/runit/runsvdir/default
elif [ $init = s6 ]
then
s6-rc-bundle-update add default lvm2
s6-rc-bundle-update add default device-mapper
fi
}
remove_sysd_cruft(){
for user in systemd-journal systemd-journal-gateway systemd-timesync systemd-network systemd-bus-proxy systemd-journal-remote systemd-journal-upload
do userdel $user
done
rm -vfr /{etc,var/lib}/systemd
}
update_bootloader_initramfs(){
cp /etc/mkinitcpio.pacnew /etc/mkinitcpio
cp /etc/default/grub.pacnew /etc/default/grub
# merge any changes in mkinitcpio.conf to new one
mkinitcpio -P
update-grub
}
reinstall_grub(){
#check if uefi or bios system
# potentially change the efi-directory=...
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub
grub-install $disk
# bios
#grub-install $disk #/dev/sd
}
reboot_directions(){
echo "Enter these commands to reboot:
sync
umount -a
mount -f / -o remount,ro
echo s >| /proc/sysrq-trigger
echo u >| /proc/sysrq-trigger
echo b >| /proc/sysrq-trigger
"
}
main(){
[ $(whoami) = root ] || die "You need to be root!"
give_warning || die "Conversion Cancelled."
backup
fetch_artix_files
move_arch_mirrors
move_artix_files_to_place
remove_pacman_cache
remove_sig_req
install_artix_key
restore_sig_req
backup_daemons
down_artix_pkgs
rem_sysd
install_artix_pkgs
reinstall_pkgs
enable_init_scripts
lvm_enable
remove_sysd_cruft
update_bootloader_initramfs
reinstall_grub
reboot_directions
}
#main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment