archbox/archbox.bash

81 lines
1.8 KiB
Bash
Raw Normal View History

2020-10-27 06:12:14 +00:00
#!/bin/bash
source /etc/archbox.conf
checkdep(){
which $1 >/dev/null 2>&1 || echo "Install $1." && exit 1
}
copyresolv(){
$PRIV /usr/local/share/archbox/bin/copyresolv
}
asroot(){
[[ $EUID -ne 0 ]] && echo "Run this as root!" && exit 1
}
2020-10-27 07:30:02 +00:00
help_text(){
cat << EOF
2020-10-27 08:23:42 +00:00
2020-10-27 07:30:02 +00:00
USAGE $0 <arguments>
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(){
echo "$(tput bold)$(tput setaf 1)==> $@"
exit 1
}
msg(){
echo "$(tput bold)$(tput setaf 2)==> $@"
}
2020-10-27 06:12:14 +00:00
case $1 in
--create)
asroot
[[ -z $2 ]] && echo "Specify the link of Arch Linux bootstrap tarball." \
&& exit 1
2020-10-27 08:23:42 +00:00
msg "Creating chroot directory..."
2020-10-27 06:12:14 +00:00
mkdir $INSTALL_PATH
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 08:23:42 +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
;;
--enter)
copyresolv
2020-10-27 08:23:42 +00:00
$PRIV /usr/local/share/archbox/bin/archboxenter
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
*)
copyresolv
COMMAND=$(echo $@ | tr ' ' '\ ')
$PRIV /usr/local/share/archbox/bin/archboxcommand $COMMAND
;;
esac