2020-12-28 05:27:02 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-10-27 06:12:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-10-29 05:37:16 +00:00
|
|
|
storeenv(){
|
2020-10-29 05:33:19 +00:00
|
|
|
echo $DBUS_SESSION_BUS_ADDRESS > /tmp/archbox_dbus_session_address
|
2020-10-29 05:37:16 +00:00
|
|
|
echo $XDG_RUNTIME_DIR > /tmp/archbox_xdg_runtime_dir
|
2020-10-29 03:56:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 07:30:02 +00:00
|
|
|
help_text(){
|
|
|
|
cat << EOF
|
2020-10-29 03:56:55 +00:00
|
|
|
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.
|
2020-12-15 07:11:47 +00:00
|
|
|
--remount-run Remount /run in chroot enviroment.
|
2020-12-28 12:15:21 +00:00
|
|
|
--mount-runtime-only Mount XDG_RUNTIME_DIR to 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..."
|
2020-12-31 16:16:31 +00:00
|
|
|
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
|
2020-12-28 12:15:21 +00:00
|
|
|
[[ $MOUNT_RUN = "yes" ]] && mount -R /run $CHROOT/run
|
2020-10-27 12:54:58 +00:00
|
|
|
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-12-31 16:16:31 +00:00
|
|
|
cp /usr/local/share/archbox/chroot_setup.bash $CHROOT/chroot_setup
|
|
|
|
echo $USER > /tmp/archbox_user
|
|
|
|
chroot $CHROOT /bin/bash -c "/chroot_setup"
|
|
|
|
exit $?
|
2020-10-27 12:54:58 +00:00
|
|
|
;;
|
2020-10-29 15:01:19 +00:00
|
|
|
-e|--enter)
|
2020-12-31 16:16:31 +00:00
|
|
|
storeenv
|
|
|
|
copyresolv
|
2020-10-29 03:56:55 +00:00
|
|
|
$PRIV /usr/local/share/archbox/bin/archbox enter
|
2020-12-31 16:16:31 +00:00
|
|
|
exit $?
|
|
|
|
;;
|
2020-11-02 09:51:43 +00:00
|
|
|
--remount-run)
|
2020-12-31 16:16:31 +00:00
|
|
|
$PRIV /usr/local/share/archbox/bin/remount_run
|
|
|
|
exit $?
|
|
|
|
;;
|
2020-12-28 12:15:21 +00:00
|
|
|
--mount-runtime-only)
|
2020-12-31 16:16:31 +00:00
|
|
|
$PRIV /usr/local/share/archbox/bin/remount_run runtimeonly
|
|
|
|
exit $?
|
|
|
|
;;
|
2020-10-29 15:01:19 +00:00
|
|
|
-h|--help)
|
2020-10-27 07:30:02 +00:00
|
|
|
help_text
|
2020-12-31 16:16:31 +00:00
|
|
|
exit 0
|
2020-10-27 07:30:02 +00:00
|
|
|
;;
|
2020-10-27 06:12:14 +00:00
|
|
|
"")
|
2020-10-27 07:30:02 +00:00
|
|
|
help_text
|
2020-12-31 16:16:31 +00:00
|
|
|
exit 1
|
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
|
|
|
*)
|
2020-12-31 16:16:31 +00:00
|
|
|
storeenv
|
|
|
|
copyresolv
|
|
|
|
$PRIV /usr/local/share/archbox/bin/archbox $@
|
|
|
|
exit $?
|
2020-10-27 06:12:14 +00:00
|
|
|
;;
|
|
|
|
esac
|