archbox/archbox.bash

102 lines
2.6 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=$DBUS_SESSION_BUS_ADDRESS" > /tmp/env_archbox
echo "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR" >> /tmp/env_archbox
}
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:
--create LINK Creates a chroot enviroment.
--enter Enters chroot enviroment.
--help Displays this help message.
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
--create)
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
wget -q --show-progress -O archlinux.tar.gz $2
2020-10-27 08:23:42 +00:00
msg "Extracting the tarball..."
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
chroot $CHROOT /bin/bash -c "sh /chroot_setup"
2020-10-27 12:54:58 +00:00
;;
2020-10-27 06:12:14 +00:00
--enter)
storeenv
copyresolv
$PRIV /usr/local/share/archbox/bin/archbox enter
2020-10-27 06:12:14 +00:00
;;
2020-10-27 07:30:02 +00:00
--help)
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-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
COMMAND=$(echo $@ | tr ' ' '\ ')
$PRIV /usr/local/share/archbox/bin/archbox $COMMAND
2020-10-27 06:12:14 +00:00
;;
esac