archbox/archbox.bash

107 lines
2.8 KiB
Bash
Raw Normal View History

2020-10-27 06:12:14 +00:00
#!/bin/bash
source /etc/archbox.conf
checkdep(){
2020-10-27 12:54:58 +00:00
which $1 >/dev/null 2>&1 || err "Install $1!"
2020-10-27 06:12:14 +00:00
}
copyresolv(){
$PRIV /usr/local/share/archbox/bin/copyresolv
}
asroot(){
2020-10-27 12:54:58 +00:00
[[ $EUID -ne 0 ]] && err "Run this as root!"
2020-10-27 06:12:14 +00:00
}
storeenv(){
echo $DBUS_SESSION_BUS_ADDRESS > /tmp/archbox_dbus_session_address
echo $XDG_RUNTIME_DIR > /tmp/archbox_xdg_runtime_dir
}
2020-10-27 07:30:02 +00:00
help_text(){
cat << EOF
USAGE: $0 <arguments>
2020-10-27 08:45:11 +00:00
2020-10-27 07:30:02 +00:00
OPTIONS:
2020-10-29 15:01:19 +00:00
-c, --create URL Creates a chroot enviroment.
-e, --enter Enters chroot enviroment.
-h, --help Displays this help message.
--remount-run Remount /run in chroot enviroment.
2020-10-27 08:23:42 +00:00
2020-10-27 07:30:02 +00:00
EOF
}
2020-10-27 08:23:42 +00:00
err(){
2020-10-27 12:54:58 +00:00
echo "$(tput bold)$(tput setaf 1)==> $@ $(tput sgr0)"
2020-10-27 08:23:42 +00:00
exit 1
}
msg(){
2020-10-27 12:54:58 +00:00
echo "$(tput bold)$(tput setaf 2)==> $@ $(tput sgr0)"
2020-10-27 08:23:42 +00:00
}
2020-10-27 06:12:14 +00:00
case $1 in
2020-10-29 15:01:19 +00:00
-c|--create)
2020-10-27 06:12:14 +00:00
asroot
2020-10-27 12:54:58 +00:00
[[ -z $2 ]] && err "Specify the link of Arch Linux bootstrap tarball!"
2020-10-27 08:23:42 +00:00
msg "Creating chroot directory..."
2020-10-27 12:54:58 +00:00
mkdir -p $INSTALL_PATH
2020-10-27 06:12:14 +00:00
cd $INSTALL_PATH
2020-10-27 08:23:42 +00:00
msg "Downloading Arch Linux tarball..."
2020-10-27 06:12:14 +00:00
checkdep wget
2020-11-25 12:21:30 +00:00
while true; do wget -O archlinux.tar.gz $2 && break; done
2020-10-27 08:23:42 +00:00
msg "Extracting the tarball..."
checkdep tar
2020-10-27 06:12:14 +00:00
tar xzf archlinux.tar.gz
2020-10-27 08:23:42 +00:00
msg "Enabling internet connection in chroot enviroment..."
2020-10-27 06:12:14 +00:00
cp /etc/resolv.conf $CHROOT/etc/resolv.conf
2020-10-27 08:23:42 +00:00
msg "You will need to edit which mirror you want to use, uncomment needed mirrors and save it."
2020-10-27 06:12:14 +00:00
echo "Editor of your choice:"
read MIRROR_EDITOR
$MIRROR_EDITOR $CHROOT/etc/pacman.d/mirrorlist || exit 1
2020-10-27 12:54:58 +00:00
msg "Disabling Pacman's CheckSpace..."
2020-10-27 06:12:14 +00:00
checkdep sed
sed -i 's/CheckSpace/#CheckSpace/g' $CHROOT/etc/pacman.conf
2020-10-27 12:54:58 +00:00
msg "Mounting necessary filesystems..."
mount -R /home $CHROOT/home
mount -t proc /proc $CHROOT/proc
mount -R /tmp $CHROOT/tmp
mount -R /sys $CHROOT/sys
mount -R /dev $CHROOT/dev
mount -R /run $CHROOT/run
mount --make-rslave $CHROOT/dev
mount --make-rslave $CHROOT/sys
mkdir -p $CHROOT/var/lib/dbus
mount -R /var/lib/dbus $CHROOT/var/lib/dbus
mkdir -p $CHROOT/lib/modules
mount -R /lib/modules $CHROOT/lib/modules
mount -R /boot $CHROOT/boot
2020-10-28 03:02:56 +00:00
cp /usr/local/share/archbox/chroot_setup.bash $CHROOT/chroot_setup
2020-11-08 15:36:35 +00:00
echo $USER > /tmp/archbox_user
2020-10-28 03:02:56 +00:00
chroot $CHROOT /bin/bash -c "sh /chroot_setup"
2020-10-27 12:54:58 +00:00
;;
2020-10-29 15:01:19 +00:00
-e|--enter)
storeenv
copyresolv
$PRIV /usr/local/share/archbox/bin/archbox enter
2020-10-27 06:12:14 +00:00
;;
--remount-run)
$PRIV /usr/local/share/archbox/bin/remount_run
;;
2020-10-29 15:01:19 +00:00
-h|--help)
2020-10-27 07:30:02 +00:00
help_text
;;
2020-10-27 06:12:14 +00:00
"")
2020-10-27 07:30:02 +00:00
help_text
2020-10-27 06:12:14 +00:00
;;
2020-10-29 15:01:19 +00:00
-*)
2020-10-27 08:23:42 +00:00
err "Unknown option: $1"
;;
2020-10-27 06:12:14 +00:00
*)
storeenv
2020-10-27 06:12:14 +00:00
copyresolv
$PRIV /usr/local/share/archbox/bin/archbox $@
2020-10-27 06:12:14 +00:00
;;
esac