POSIX rewrite: archbox.bash
This commit is contained in:
parent
28b1123a0c
commit
2191eeea79
@ -43,7 +43,7 @@ PREFIX="${PREFIX:-/usr/local}"
|
||||
|
||||
mkdir -p $PREFIX/share/archbox/bin
|
||||
mkdir -p $ETC_DIR
|
||||
install -v -D -m 755 ./src/archbox.bash $PREFIX/bin/archbox
|
||||
install -v -D -m 755 ./src/archbox $PREFIX/bin/archbox
|
||||
install -v -D -m 755 ./src/archbox-desktop.bash $PREFIX/bin/archbox-desktop
|
||||
[[ ! -e /etc/archbox.conf || ! -z $FORCE_INSTALL_CONFIG ]] && genconfig > $ETC_DIR/archbox.conf
|
||||
install -v -D -m 755 ./src/exec.bash $PREFIX/share/archbox/bin/exec
|
||||
|
135
src/archbox
Normal file
135
src/archbox
Normal file
@ -0,0 +1,135 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /etc/archbox.conf
|
||||
|
||||
# Text colors/formatting
|
||||
red="\033[38;5;1"
|
||||
green="\033[38;5;2"
|
||||
bold="\033[1m"
|
||||
reset="\033[m"
|
||||
|
||||
err(){
|
||||
printf "${red}${bold}%s${reset}\n" "==> $*" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
msg(){
|
||||
printf "${green}${bold}%s${reset}\n" "==> $*" 1>&2
|
||||
}
|
||||
|
||||
checkdep(){
|
||||
command -v $1 2>/dev/null || err "Install $1!"
|
||||
}
|
||||
|
||||
asroot(){
|
||||
[ $(id -u) -eq 0 ] || err "Run this as root!"
|
||||
}
|
||||
|
||||
storeenv() {
|
||||
printf "%s\n" "# This will be sourced when entering Archbox" > /tmp/archbox_env
|
||||
$PRIV ${PREFIX}/share/archbox/bin/uth chownvar $USER
|
||||
[ ! -z $WAYLAND_DISPLAY ] && \
|
||||
printf "%s\n" "WAYLAND_DISPLAY=${WAYLAND_DISPLAY}" >> /tmp/archbox_env
|
||||
if [ ! -z $DISPLAY ]; then
|
||||
command -v xhost >/dev/null 2>&1 && xhost +local: > /dev/null
|
||||
printf "%s\n" "DISPLAY=${DISPLAY}" >> /tmp/archbox_env
|
||||
fi
|
||||
[ ! -z $DBUS_SESSION_BUS_ADDRESS ] && eval "$(dbus-launch)"
|
||||
printf "%s\n" "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}" >> /tmp/archbox_env
|
||||
printf "%s\n" "XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp}" >> /tmp/archbox_env
|
||||
}
|
||||
|
||||
help_text(){
|
||||
printf "%s" "
|
||||
USAGE: $0 <arguments>
|
||||
|
||||
OPTIONS:
|
||||
-c, --create URL Creates a chroot enviroment.
|
||||
-e, --enter Enters chroot enviroment.
|
||||
-h, --help Displays this help message.
|
||||
-m, --mount Mount Archbox directories.
|
||||
-u, --umount Unmount Archbox directories.
|
||||
--remount-run Remount /run in chroot enviroment.
|
||||
--mount-runtime-only Mount XDG_RUNTIME_DIR to chroot enviroment.
|
||||
|
||||
"
|
||||
}
|
||||
|
||||
fetch_tarball(){
|
||||
if command -v aria2c 2>/dev/null; then
|
||||
aria2c -o archlinux.tar.gz $1
|
||||
elif command -v wget 2>/dev/null; then
|
||||
wget -O archlinux.tar.gz $1
|
||||
elif command -v curl 2>/dev/null; then
|
||||
curl -o archlinux.tar.gz $1
|
||||
else
|
||||
err "No supported downloader found."
|
||||
fi
|
||||
}
|
||||
|
||||
case $1 in
|
||||
-c|--create)
|
||||
asroot
|
||||
[ -z $2 ] && err "Specify the link of Arch Linux bootstrap tarball!"
|
||||
msg "Creating chroot directory..."
|
||||
mkdir -p $INSTALL_PATH
|
||||
cd $INSTALL_PATH
|
||||
msg "Downloading Arch Linux tarball..."
|
||||
while true; do fetch_tarball $2 && break; done
|
||||
msg "Extracting the tarball..."
|
||||
checkdep tar
|
||||
tar xzf archlinux.tar.gz
|
||||
msg "Enabling internet connection in chroot enviroment..."
|
||||
cp /etc/resolv.conf "${CHROOT}"/etc/resolv.conf
|
||||
msg "You will need to edit which mirror you want to use, uncomment needed mirrors and save it."
|
||||
echo "Editor of your choice:"
|
||||
read MIRROR_EDITOR
|
||||
$MIRROR_EDITOR "${CHROOT}"/etc/pacman.d/mirrorlist || exit 1
|
||||
msg "Disabling Pacman's CheckSpace..."
|
||||
checkdep sed
|
||||
sed -i "s/CheckSpace/#CheckSpace/g" "${CHROOT}"/etc/pacman.conf
|
||||
msg "Mounting necessary filesystems..."
|
||||
"${PREFIX}"/share/archbox/bin/init start
|
||||
cp "${PREFIX}"/share/archbox/chroot_setup.bash "${CHROOT}"/chroot_setup
|
||||
echo $ARCHBOX_USER > /tmp/archbox_user
|
||||
chroot $CHROOT /bin/bash -c "/chroot_setup"
|
||||
exit $?
|
||||
;;
|
||||
-e|--enter)
|
||||
storeenv
|
||||
$PRIV "${PREFIX}"/share/archbox/bin/uth copyresolv
|
||||
$PRIV "${PREFIX}"/share/archbox/bin/enter
|
||||
exit $?
|
||||
;;
|
||||
-m|--mount)
|
||||
$PRIV "${PREFIX}"/share/archbox/bin/init start
|
||||
;;
|
||||
-u|--umount)
|
||||
$PRIV "${PREFIX}"/share/archbox/bin/init stop
|
||||
;;
|
||||
--remount-run)
|
||||
$PRIV "${PREFIX}"/share/archbox/bin/uth remountrun
|
||||
exit $?
|
||||
;;
|
||||
--mount-runtime-only)
|
||||
$PRIV "${PREFIX}"/share/archbox/bin/uth runtimeonly
|
||||
exit $?
|
||||
;;
|
||||
-h|--help)
|
||||
help_text
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
help_text
|
||||
exit 1
|
||||
;;
|
||||
-*)
|
||||
err "Unknown option: $1"
|
||||
;;
|
||||
*)
|
||||
storeenv
|
||||
$PRIV ${PREFIX}/share/archbox/bin/uth copyresolv
|
||||
$PRIV ${PREFIX}/share/archbox/bin/exec $@
|
||||
exit $?
|
||||
;;
|
||||
esac
|
127
src/archbox.bash
127
src/archbox.bash
@ -1,127 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source /etc/archbox.conf
|
||||
|
||||
checkdep(){
|
||||
hash $1 2>/dev/null || err "Install $1!"
|
||||
}
|
||||
|
||||
asroot(){
|
||||
[[ $EUID -ne 0 ]] && err "Run this as root!"
|
||||
}
|
||||
|
||||
storeenv() {
|
||||
echo "# This will be sourced when entering Archbox" > /tmp/archbox_env
|
||||
$PRIV $PREFIX/share/archbox/bin/uth chownvar $USER
|
||||
[[ ! -z $WAYLAND_DISPLAY ]] && echo "WAYLAND_DISPLAY=$WAYLAND_DISPLAY" >> /tmp/archbox_env
|
||||
if [[ ! -z $DISPLAY ]]; then
|
||||
hash xhost >/dev/null 2>&1 && xhost +local: > /dev/null
|
||||
echo "DISPLAY=$DISPLAY" >> /tmp/archbox_env
|
||||
fi
|
||||
echo "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" >> /tmp/archbox_env
|
||||
echo "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR" >> /tmp/archbox_env
|
||||
}
|
||||
|
||||
help_text(){
|
||||
cat << EOF
|
||||
USAGE: $0 <arguments>
|
||||
|
||||
OPTIONS:
|
||||
-c, --create URL Creates a chroot enviroment.
|
||||
-e, --enter Enters chroot enviroment.
|
||||
-h, --help Displays this help message.
|
||||
-m, --mount Mount Archbox directories.
|
||||
-u, --umount Unmount Archbox directories.
|
||||
--remount-run Remount /run in chroot enviroment.
|
||||
--mount-runtime-only Mount XDG_RUNTIME_DIR to chroot enviroment.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
fetch_tarball(){
|
||||
if hash aria2c 2>/dev/null; then
|
||||
aria2c -o archlinux.tar.gz $1
|
||||
elif hash wget 2>/dev/null; then
|
||||
wget -O archlinux.tar.gz $1
|
||||
elif hash curl 2>/dev/null; then
|
||||
curl -o archlinux.tar.gz $1
|
||||
else
|
||||
err "No supported downloader found."
|
||||
fi
|
||||
}
|
||||
|
||||
err(){
|
||||
echo "$(tput bold)$(tput setaf 1)==> $@ $(tput sgr0)" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
msg(){
|
||||
echo "$(tput bold)$(tput setaf 2)==> $@ $(tput sgr0)"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
-c|--create)
|
||||
asroot
|
||||
[[ -z $2 ]] && err "Specify the link of Arch Linux bootstrap tarball!"
|
||||
msg "Creating chroot directory..."
|
||||
mkdir -p $INSTALL_PATH
|
||||
cd $INSTALL_PATH
|
||||
msg "Downloading Arch Linux tarball..."
|
||||
while true; do fetch_tarball $2 && break; done
|
||||
msg "Extracting the tarball..."
|
||||
checkdep tar
|
||||
tar xzf archlinux.tar.gz
|
||||
msg "Enabling internet connection in chroot enviroment..."
|
||||
cp /etc/resolv.conf $CHROOT/etc/resolv.conf
|
||||
msg "You will need to edit which mirror you want to use, uncomment needed mirrors and save it."
|
||||
echo "Editor of your choice:"
|
||||
read MIRROR_EDITOR
|
||||
$MIRROR_EDITOR $CHROOT/etc/pacman.d/mirrorlist || exit 1
|
||||
msg "Disabling Pacman's CheckSpace..."
|
||||
checkdep sed
|
||||
sed -i 's/CheckSpace/#CheckSpace/g' $CHROOT/etc/pacman.conf
|
||||
msg "Mounting necessary filesystems..."
|
||||
$PREFIX/share/archbox/bin/init start
|
||||
cp $PREFIX/share/archbox/chroot_setup.bash $CHROOT/chroot_setup
|
||||
echo $ARCHBOX_USER > /tmp/archbox_user
|
||||
chroot $CHROOT /bin/bash -c "/chroot_setup"
|
||||
exit $?
|
||||
;;
|
||||
-e|--enter)
|
||||
storeenv
|
||||
$PRIV $PREFIX/share/archbox/bin/uth copyresolv
|
||||
$PRIV $PREFIX/share/archbox/bin/enter
|
||||
exit $?
|
||||
;;
|
||||
-m|--mount)
|
||||
$PRIV $PREFIX/share/archbox/bin/init start
|
||||
;;
|
||||
-u|--umount)
|
||||
$PRIV $PREFIX/share/archbox/bin/init stop
|
||||
;;
|
||||
--remount-run)
|
||||
$PRIV $PREFIX/share/archbox/bin/uth remountrun
|
||||
exit $?
|
||||
;;
|
||||
--mount-runtime-only)
|
||||
$PRIV $PREFIX/share/archbox/bin/uth runtimeonly
|
||||
exit $?
|
||||
;;
|
||||
-h|--help)
|
||||
help_text
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
help_text
|
||||
exit 1
|
||||
;;
|
||||
-*)
|
||||
err "Unknown option: $1"
|
||||
;;
|
||||
*)
|
||||
storeenv
|
||||
$PRIV $PREFIX/share/archbox/bin/uth copyresolv
|
||||
$PRIV $PREFIX/share/archbox/bin/exec $@
|
||||
exit $?
|
||||
;;
|
||||
esac
|
Loading…
Reference in New Issue
Block a user