archbox/archbox.bash

115 lines
3.1 KiB
Bash
Raw Normal View History

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(){
2021-01-10 06:01:43 +00:00
hash $1 2>/dev/null || 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
#}
storeenv() {
echo "# This will be sourced when entering Archbox" > /tmp/archbox_env
[[ ! -z $WAYLAND_DISPLAY ]] && echo "WAYLAND_DISPLAY=$WAYLAND_DISPLAY" >> /tmp/archbox_env
[[ ! -z $DISPLAY ]] && checkdep xhost && xhost +local: > /dev/null \
&& echo "DISPLAY=$DISPLAY" >> /tmp/archbox_env
echo "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" >> /tmp/archbox_env
echo "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR" >> /tmp/archbox_env
}
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.
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(){
echo "$(tput bold)$(tput setaf 1)==> $@ $(tput sgr0)" 1>&2
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..."
/usr/local/share/archbox/bin/archboxinit start
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
$PRIV /usr/local/share/archbox/bin/archbox enter
2020-12-31 16:16:31 +00:00
exit $?
;;
--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