From d025be66e6645e346fb0f90a619bc0e40b150a66 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Mon, 17 May 2021 14:41:58 +0700 Subject: [PATCH 01/18] Create NIXOS_INSTALL.md --- NIXOS_INSTALL.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 NIXOS_INSTALL.md diff --git a/NIXOS_INSTALL.md b/NIXOS_INSTALL.md new file mode 100644 index 0000000..864acab --- /dev/null +++ b/NIXOS_INSTALL.md @@ -0,0 +1,55 @@ +# Installation (NixOS) +## Install methods +### Declarative Nix +To install with nix, create a `.nix` file like this and import it to your `configuration.nix` : +```nix +{ config, pkgs, ... }: + +let + archbox = pkgs.stdenv.mkDerivation rec { + name = "archbox"; + src = pkgs.fetchFromGitHub { + owner = "your_user_here"; + repo = "archbox"; + rev = "rev_here"; + sha256 = "rev_sha256_here"; + }; + sourceRoot = "."; + installPhase = '' + mkdir -p $out + cd source + export FORCE_INSTALL_CONFIG=1 + export ETC_DIR=$out/etc + export PREFIX=$out + export ARCHBOX_USER=your_user_here + export MOUNT_RUN=no + ${pkgs.bash}/bin/bash install.sh + ''; + }; +in +{ + environment.systemPackages = [ archbox ]; + environment.etc = { + "archbox.conf" = { + source = "${archbox}/etc/archbox.conf"; + }; + }; +} +``` +Configuration can be done by modifying `installPhase` e.g. : +```sh +mkdir -p $out +cd source +export FORCE_INSTALL_CONFIG=1 +export ETC_DIR=$out/etc +export PREFIX=$out +export ARCHBOX_USER=lemni +export MOUNT_RUN=no +export ENV_VAR="TERM=foot" +export SHARED_FOLDER=( /home /var/www ) +${pkgs.bash}/bin/bash install.sh +``` +### Regular Installation +See [INSTALL.md](INSTALL.md) +## Issues +See [issues](https://github.com/lemniskett/archbox/#nixos-specific-issues) From 91623a06fd8e46765495171ba816ac1e2c6ec0fd Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Mon, 17 May 2021 14:44:51 +0700 Subject: [PATCH 02/18] Update NIXOS_INSTALL.md --- NIXOS_INSTALL.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NIXOS_INSTALL.md b/NIXOS_INSTALL.md index 864acab..49e8de1 100644 --- a/NIXOS_INSTALL.md +++ b/NIXOS_INSTALL.md @@ -36,6 +36,12 @@ in }; } ``` +Replace `your_user_here`, `rev_here`, and `rev_sha256_here`. to get rev and sha256 you can do : +```sh +nix-shell -p nix-prefetch-git +nix-prefetch-git --url https://github.com/lemniskett/archbox.git +``` + Configuration can be done by modifying `installPhase` e.g. : ```sh mkdir -p $out From 985441cb8ae0d659f45f1f4608f2291b8069fff8 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Mon, 17 May 2021 14:45:33 +0700 Subject: [PATCH 03/18] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index df24f11..1965922 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Ever since I'm running some niche distros like Void, Solus, I had a problem find ## Installation See [INSTALL.md](INSTALL.md) +For NixOS users, [NIXOS_INSTALL.md](NIXOS_INSTALL.md) For ChromeOS users, [CROS_INSTALL.md](CROS_INSTALL.md) ## Using Archbox ### Installing chroot environment From 730019afc8918282e09970cb8257f05b5ac65c54 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Mon, 17 May 2021 14:45:57 +0700 Subject: [PATCH 04/18] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1965922..310f0f7 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Ever since I'm running some niche distros like Void, Solus, I had a problem find See [INSTALL.md](INSTALL.md) For NixOS users, [NIXOS_INSTALL.md](NIXOS_INSTALL.md) + For ChromeOS users, [CROS_INSTALL.md](CROS_INSTALL.md) ## Using Archbox ### Installing chroot environment From 9dcaf7378943b4fd5a95c1607828ec2e1d829e16 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Mon, 17 May 2021 20:28:31 +0700 Subject: [PATCH 05/18] Update NIXOS_INSTALL.md --- NIXOS_INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NIXOS_INSTALL.md b/NIXOS_INSTALL.md index 49e8de1..7c014de 100644 --- a/NIXOS_INSTALL.md +++ b/NIXOS_INSTALL.md @@ -9,7 +9,7 @@ let archbox = pkgs.stdenv.mkDerivation rec { name = "archbox"; src = pkgs.fetchFromGitHub { - owner = "your_user_here"; + owner = "lemniskett"; repo = "archbox"; rev = "rev_here"; sha256 = "rev_sha256_here"; From 2191eeea79ec5048aefd64599d8b3ffebe566cff Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Tue, 18 May 2021 18:54:49 +0700 Subject: [PATCH 06/18] POSIX rewrite: archbox.bash --- install.sh | 2 +- src/archbox | 135 +++++++++++++++++++++++++++++++++++++++++++++++ src/archbox.bash | 127 -------------------------------------------- 3 files changed, 136 insertions(+), 128 deletions(-) create mode 100644 src/archbox delete mode 100644 src/archbox.bash diff --git a/install.sh b/install.sh index 2cd1b0a..ffc9383 100755 --- a/install.sh +++ b/install.sh @@ -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 diff --git a/src/archbox b/src/archbox new file mode 100644 index 0000000..12bdbd4 --- /dev/null +++ b/src/archbox @@ -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 + +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 diff --git a/src/archbox.bash b/src/archbox.bash deleted file mode 100644 index 7a7d91e..0000000 --- a/src/archbox.bash +++ /dev/null @@ -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 - -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 From b7a3af216757eb7f6829f745358f1190fa9ca1ae Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Tue, 18 May 2021 19:01:30 +0700 Subject: [PATCH 07/18] Quote PRIV variable --- src/archbox | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/archbox b/src/archbox index 12bdbd4..68d2f46 100644 --- a/src/archbox +++ b/src/archbox @@ -27,7 +27,7 @@ asroot(){ storeenv() { printf "%s\n" "# This will be sourced when entering Archbox" > /tmp/archbox_env - $PRIV ${PREFIX}/share/archbox/bin/uth chownvar $USER + "$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 @@ -82,7 +82,7 @@ case $1 in 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:" + printf "%s" "Editor of your choice:" read MIRROR_EDITOR $MIRROR_EDITOR "${CHROOT}"/etc/pacman.d/mirrorlist || exit 1 msg "Disabling Pacman's CheckSpace..." @@ -91,28 +91,28 @@ case $1 in 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 + printf "%s" $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 + "$PRIV" "${PREFIX}"/share/archbox/bin/uth copyresolv + "$PRIV" "${PREFIX}"/share/archbox/bin/enter exit $? ;; -m|--mount) - $PRIV "${PREFIX}"/share/archbox/bin/init start + "$PRIV" "${PREFIX}"/share/archbox/bin/init start ;; -u|--umount) - $PRIV "${PREFIX}"/share/archbox/bin/init stop + "$PRIV" "${PREFIX}"/share/archbox/bin/init stop ;; --remount-run) - $PRIV "${PREFIX}"/share/archbox/bin/uth remountrun + "$PRIV" "${PREFIX}"/share/archbox/bin/uth remountrun exit $? ;; --mount-runtime-only) - $PRIV "${PREFIX}"/share/archbox/bin/uth runtimeonly + "$PRIV" "${PREFIX}"/share/archbox/bin/uth runtimeonly exit $? ;; -h|--help) @@ -128,8 +128,8 @@ case $1 in ;; *) storeenv - $PRIV ${PREFIX}/share/archbox/bin/uth copyresolv - $PRIV ${PREFIX}/share/archbox/bin/exec $@ + "$PRIV" "${PREFIX}"/share/archbox/bin/uth copyresolv + "$PRIV" "${PREFIX}"/share/archbox/bin/exec $@ exit $? ;; esac From 3719a80f5da67aa2b42892d014f5248a9c722ac9 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Tue, 18 May 2021 20:07:14 +0700 Subject: [PATCH 08/18] Set DBUS_SESSION_BUS_ADDRESS to disabled when it's not set. --- src/archbox | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/archbox b/src/archbox index 68d2f46..351fd74 100644 --- a/src/archbox +++ b/src/archbox @@ -34,8 +34,7 @@ storeenv() { 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" "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS:-disabled:}" >> /tmp/archbox_env printf "%s\n" "XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp}" >> /tmp/archbox_env } From 62bcdc8a98c284b0089285c206060e1fcb402763 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Wed, 19 May 2021 11:56:36 +0700 Subject: [PATCH 09/18] POSIX rewrite: archbox-desktop.bash --- src/archbox | 10 ++++--- src/archbox-desktop.bash | 64 +++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/archbox b/src/archbox index 351fd74..a1b476a 100644 --- a/src/archbox +++ b/src/archbox @@ -2,6 +2,8 @@ . /etc/archbox.conf +set -- + # Text colors/formatting red="\033[38;5;1" green="\033[38;5;2" @@ -28,9 +30,9 @@ asroot(){ 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 ] && \ + [ $WAYLAND_DISPLAY ] && \ printf "%s\n" "WAYLAND_DISPLAY=${WAYLAND_DISPLAY}" >> /tmp/archbox_env - if [ ! -z $DISPLAY ]; then + if [ $DISPLAY ]; then command -v xhost >/dev/null 2>&1 && xhost +local: > /dev/null printf "%s\n" "DISPLAY=${DISPLAY}" >> /tmp/archbox_env fi @@ -69,7 +71,7 @@ fetch_tarball(){ case $1 in -c|--create) asroot - [ -z $2 ] && err "Specify the link of Arch Linux bootstrap tarball!" + [ $2 ] && err "Specify the link of Arch Linux bootstrap tarball!" msg "Creating chroot directory..." mkdir -p $INSTALL_PATH cd $INSTALL_PATH @@ -81,7 +83,7 @@ case $1 in 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." - printf "%s" "Editor of your choice:" + printf "%s " "Editor of your choice:" read MIRROR_EDITOR $MIRROR_EDITOR "${CHROOT}"/etc/pacman.d/mirrorlist || exit 1 msg "Disabling Pacman's CheckSpace..." diff --git a/src/archbox-desktop.bash b/src/archbox-desktop.bash index bff055a..fba0672 100644 --- a/src/archbox-desktop.bash +++ b/src/archbox-desktop.bash @@ -1,29 +1,41 @@ -#!/usr/bin/env bash +#!/bin/sh -source /etc/archbox.conf &>/dev/null +. /etc/archbox.conf >/dev/null 2>&1 + +set -- + +# 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 +} install_desktop(){ mkdir -p ~/.local/share/applications/archbox for i in $@; do archbox readlink /usr/share/applications/$i >/dev/null 2>&1 \ - && cp $CHROOT/$(archbox readlink /usr/share/applications/$i) ~/.local/share/applications/archbox \ - || cp $CHROOT/usr/share/applications/$i ~/.local/share/applications/archbox + && cp "${CHROOT}"/$(archbox readlink /usr/share/applications/$i) ~/.local/share/applications/archbox \ + || cp "${CHROOT}"/usr/share/applications/$i "~/.local/share/applications/archbox" sed -i 's/Exec=/Exec=archbox\ /g' ~/.local/share/applications/archbox/$i sed -i '/TryExec=/d' ~/.local/share/applications/archbox/$i done } checkdep(){ - hash $1 2>/dev/null || err "Install $1!" -} - -err(){ - echo "$(tput bold)$(tput setaf 1)==> $@ $(tput sgr0)" 1>&2 - exit 1 + command -v $1 2>/dev/null || err "Install $1!" } help_text(){ -cat << EOF + printf "%s" " USAGE: $0 OPTIONS: @@ -33,19 +45,25 @@ OPTIONS: -s, --list-installed List installed desktop entries -h, --help Displays this help message -EOF +" +} + +list(){ + for i in $*/*; do + printf "%s\n" "$i" + done } case $1 in -i|--install) checkdep update-desktop-database - install_desktop ${@:2} + install_desktop ${@#$1} update-desktop-database exit $? ;; -r|--remove) checkdep update-desktop-database - selected_entry=${@:2} + selected_entry=${@#$1} for i in $selected_entry; do rm ~/.local/share/applications/archbox/$i done @@ -57,12 +75,11 @@ case $1 in exit 0 ;; -l|--list) - archbox ls -1 --color=none /usr/share/applications - exit $? + list "${CHROOT}"/usr/share/applications ;; -s|--list-installed) - ls -1 --color=none ~/.local/share/applications/archbox - exit $? + mkdir -p ~/.local/share/applications/archbox + list ~/.local/share/applications/archbox ;; *) checkdep zenity @@ -74,23 +91,22 @@ case $1 in FALSE 'Install desktop entries' FALSE 'Remove desktop entries')" case $action in 'Install desktop entries') - list_desktop="$(archbox ls --color=none -1 /usr/share/applications)" - zenity_entry="$(echo $list_desktop | sed 's/\ /\ FALSE\ /g')" + zenity_entry="$(list "${CHROOT}"/usr/share/applications | sed 's/\ /\ FALSE\ /g')" selected_entry=$(zenity --list --checklist --height=500 --width=450 \ --title="Archbox Desktop Manager" \ --text "Select .desktop entries those you want to install" \ --column "Select" --column "Applications" \ FALSE $zenity_entry | sed 's/|/\ /g') - [[ -z $selected_entry ]] && exit 1 + [ $selected_entry ] || exit 1 install_desktop $selected_entry update-desktop-database exit 0 ;; 'Remove desktop entries') - list_desktop="$(ls --color=none -1 ~/.local/share/applications/archbox)" - [[ -z $list_desktop ]] && zenity --info --title "Archbox Desktop Manager" \ + list_desktop="$(list ~/.local/share/applications/archbox)" + [ $list_desktop = "*" ] && zenity --info --title "Archbox Desktop Manager" \ --text "No .desktop files installed" --width=300 && exit 1 - zenity_entry="$(echo $list_desktop | sed 's/\ /\ FALSE\ /g')" + zenity_entry="$(printf "%s" "$list_desktop" | sed 's/\ /\ FALSE\ /g')" selected_entry=$(zenity --list --checklist --height=500 --width=450 \ --title="Archbox Desktop Manager" \ --text "Select .desktop entries those you want to remove" \ From b7a8e12c6bc7aad14ce3537ded8f1c9ecd5b8b16 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Thu, 27 May 2021 17:15:27 +0700 Subject: [PATCH 10/18] Some changes --- install.sh | 2 +- src/archbox | 2 +- src/{archbox-desktop.bash => archbox-desktop} | 0 src/chroot_setup.bash | 17 ++++++++++++++--- 4 files changed, 16 insertions(+), 5 deletions(-) rename src/{archbox-desktop.bash => archbox-desktop} (100%) diff --git a/install.sh b/install.sh index ffc9383..90a2f5b 100755 --- a/install.sh +++ b/install.sh @@ -44,7 +44,7 @@ PREFIX="${PREFIX:-/usr/local}" mkdir -p $PREFIX/share/archbox/bin mkdir -p $ETC_DIR install -v -D -m 755 ./src/archbox $PREFIX/bin/archbox -install -v -D -m 755 ./src/archbox-desktop.bash $PREFIX/bin/archbox-desktop +install -v -D -m 755 ./src/archbox-desktop $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 install -v -D -m 755 ./src/enter.bash $PREFIX/share/archbox/bin/enter diff --git a/src/archbox b/src/archbox index a1b476a..054d0eb 100644 --- a/src/archbox +++ b/src/archbox @@ -93,7 +93,7 @@ case $1 in "${PREFIX}"/share/archbox/bin/init start cp "${PREFIX}"/share/archbox/chroot_setup.bash "${CHROOT}"/chroot_setup printf "%s" $ARCHBOX_USER > /tmp/archbox_user - chroot $CHROOT /bin/bash -c "/chroot_setup" + chroot $CHROOT /bin/bash /chroot_setup exit $? ;; -e|--enter) diff --git a/src/archbox-desktop.bash b/src/archbox-desktop similarity index 100% rename from src/archbox-desktop.bash rename to src/archbox-desktop diff --git a/src/chroot_setup.bash b/src/chroot_setup.bash index f1340b6..d741caf 100644 --- a/src/chroot_setup.bash +++ b/src/chroot_setup.bash @@ -1,15 +1,26 @@ -#!/usr/bin/env bash +#!/bin/sh + +. /etc/archbox.conf >/dev/null 2>&1 + +set -- + +# Text colors/formatting +red="\033[38;5;1" +green="\033[38;5;2" +bold="\033[1m" +reset="\033[m" err(){ - echo "$(tput bold)$(tput setaf 1)==> $@ $(tput sgr0)" 1>&2 + printf "${red}${bold}%s${reset}\n" "==> $*" 1>&2 exit 1 } msg(){ - echo "$(tput bold)$(tput setaf 2)==> $@ $(tput sgr0)" + printf "${green}${bold}%s${reset}\n" "==> $*" 1>&2 } PATH=/usr/bin + msg "Initializing pacman keyrings..." pacman-key --init pacman-key --populate archlinux From 4f5e1144dfe8b09aa82e861dad8f8dd4293df5e9 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Thu, 27 May 2021 17:23:25 +0700 Subject: [PATCH 11/18] POSIX rewrite: chroot_setup.bash --- src/archbox | 2 +- src/{chroot_setup.bash => chroot_setup} | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) rename src/{chroot_setup.bash => chroot_setup} (71%) diff --git a/src/archbox b/src/archbox index 054d0eb..8f0fb0a 100644 --- a/src/archbox +++ b/src/archbox @@ -93,7 +93,7 @@ case $1 in "${PREFIX}"/share/archbox/bin/init start cp "${PREFIX}"/share/archbox/chroot_setup.bash "${CHROOT}"/chroot_setup printf "%s" $ARCHBOX_USER > /tmp/archbox_user - chroot $CHROOT /bin/bash /chroot_setup + chroot $CHROOT /bin/sh /chroot_setup exit $? ;; -e|--enter) diff --git a/src/chroot_setup.bash b/src/chroot_setup similarity index 71% rename from src/chroot_setup.bash rename to src/chroot_setup index d741caf..a269d73 100644 --- a/src/chroot_setup.bash +++ b/src/chroot_setup @@ -1,5 +1,3 @@ -#!/bin/sh - . /etc/archbox.conf >/dev/null 2>&1 set -- @@ -31,30 +29,30 @@ mkdir -p /usr/local/bin curl https://raw.githubusercontent.com/lemniskett/archboxctl/master/archboxctl.bash > /usr/local/bin/archboxctl chmod 755 /usr/local/bin/archboxctl msg "Setting up locale..." -echo "Uncomment needed locale, enter to continue" +printf "%s\n" "Uncomment needed locale, enter to continue" read nano /etc/locale.gen locale-gen msg "Setting up timezone..." -echo "Enter your timezone, for example : \"Asia/Jakarta\"" +printf "%s\n" "Enter your timezone, for example : \"Asia/Jakarta\"" while true; do read TIMEZONE \ - && [[ -e /usr/share/zoneinfo/$TIMEZONE ]] \ + && [ -e /usr/share/zoneinfo/$TIMEZONE ] \ && ln -s /usr/share/zoneinfo/$TIMEZONE /etc/localtime \ && break \ - || echo "Timezone not found, enter it again." + || printf "%s\n" "Timezone not found, enter it again." done msg "Creating user account..." -CHROOT_USER="$(cat /tmp/archbox_user)" +read CHROOT_USER < /tmp/archbox_user useradd -m $CHROOT_USER -gpasswd -a $CHROOT_USER wheel -echo "Enter root password" +usermod -aG wheel $CHROOT_USER +printf "%s\n" "Enter root password" while true; do passwd && break done -echo "Enter $CHROOT_USER password" +printf "%s\n" "Enter $CHROOT_USER password" while true; do passwd $CHROOT_USER && break done sed -i 's/# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/g' /etc/sudoers -echo "Don't forget to run \"archbox --mount\" in host on boot" +printf "%s\n" "Don't forget to run \"archbox --mount\" in host on boot" From cdaa7c8aca304bcd73d04b8aeb14f5722d964b07 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Thu, 27 May 2021 17:25:30 +0700 Subject: [PATCH 12/18] POSIX rewrite: enter.bash --- install.sh | 2 +- src/enter.bash | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 90a2f5b..532cc0b 100755 --- a/install.sh +++ b/install.sh @@ -48,7 +48,7 @@ install -v -D -m 755 ./src/archbox-desktop $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 install -v -D -m 755 ./src/enter.bash $PREFIX/share/archbox/bin/enter -install -v -D -m 755 ./src/chroot_setup.bash $PREFIX/share/archbox/chroot_setup.bash +install -v -D -m 755 ./src/chroot_setup $PREFIX/share/archbox/chroot_setup install -v -D -m 755 ./src/init.bash $PREFIX/share/archbox/bin/init install -v -D -m 755 ./src/uth.bash $PREFIX/share/archbox/bin/uth diff --git a/src/enter.bash b/src/enter.bash index d0b389e..225a088 100644 --- a/src/enter.bash +++ b/src/enter.bash @@ -1,12 +1,9 @@ #!/usr/bin/env bash -source /etc/archbox.conf &>/dev/null -source /tmp/archbox_env &>/dev/null +. /etc/archbox.conf >/dev/null 2>&1 +. /tmp/archbox_env >/dev/null 2>&1 -REQ_ENV="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS " -REQ_ENV+="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR " -[[ ! -z $DISPLAY ]] && REQ_ENV+="DISPLAY=$DISPLAY " -[[ ! -z $WAYLAND_DISPLAY ]] && REQ_ENV+="WAYLAND_DISPLAY=$WAYLAND_DISPLAY " +REQ_ENV="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY" ENV="$REQ_ENV $ENV_VAR" COMMAND="$@" From 5b732eba04605611643078000922a32189c270fa Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Thu, 27 May 2021 17:27:10 +0700 Subject: [PATCH 13/18] POSIX rewrite: exec.bash --- install.sh | 4 ++-- src/{enter.bash => enter} | 2 +- src/exec | 10 ++++++++++ src/exec.bash | 13 ------------- 4 files changed, 13 insertions(+), 16 deletions(-) rename src/{enter.bash => enter} (93%) create mode 100644 src/exec delete mode 100644 src/exec.bash diff --git a/install.sh b/install.sh index 532cc0b..a4b84cf 100755 --- a/install.sh +++ b/install.sh @@ -46,8 +46,8 @@ mkdir -p $ETC_DIR install -v -D -m 755 ./src/archbox $PREFIX/bin/archbox install -v -D -m 755 ./src/archbox-desktop $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 -install -v -D -m 755 ./src/enter.bash $PREFIX/share/archbox/bin/enter +install -v -D -m 755 ./src/exec $PREFIX/share/archbox/bin/exec +install -v -D -m 755 ./src/enter $PREFIX/share/archbox/bin/enter install -v -D -m 755 ./src/chroot_setup $PREFIX/share/archbox/chroot_setup install -v -D -m 755 ./src/init.bash $PREFIX/share/archbox/bin/init install -v -D -m 755 ./src/uth.bash $PREFIX/share/archbox/bin/uth diff --git a/src/enter.bash b/src/enter similarity index 93% rename from src/enter.bash rename to src/enter index 225a088..852d80c 100644 --- a/src/enter.bash +++ b/src/enter @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh . /etc/archbox.conf >/dev/null 2>&1 . /tmp/archbox_env >/dev/null 2>&1 diff --git a/src/exec b/src/exec new file mode 100644 index 0000000..e92e563 --- /dev/null +++ b/src/exec @@ -0,0 +1,10 @@ +#!/bin/sh + +. /etc/archbox.conf >/dev/null 2>&1 +. /tmp/archbox_env >/dev/null 2>&1 + +REQ_ENV="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY" + +ENV="$REQ_ENV $ENV_VAR" +COMMAND="$@" +chroot $CHROOT /bin/su -c "env $ENV $COMMAND" $ARCHBOX_USER diff --git a/src/exec.bash b/src/exec.bash deleted file mode 100644 index 092bab0..0000000 --- a/src/exec.bash +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -source /etc/archbox.conf &>/dev/null -source /tmp/archbox_env &>/dev/null - -REQ_ENV="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS " -REQ_ENV+="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR " -[[ ! -z $DISPLAY ]] && REQ_ENV+="DISPLAY=$DISPLAY " -[[ ! -z $WAYLAND_DISPLAY ]] && REQ_ENV+="WAYLAND_DISPLAY=$WAYLAND_DISPLAY " - -ENV="$REQ_ENV $ENV_VAR" -COMMAND="$@" -chroot $CHROOT /bin/su -c "env $ENV $COMMAND" $ARCHBOX_USER From 01f0cb9923c15633bbf3255d18929f3d83fadfac Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Thu, 27 May 2021 18:02:13 +0700 Subject: [PATCH 14/18] POSIX rewrite: init.bash --- install.sh | 2 +- src/enter | 2 +- src/exec | 2 +- src/init | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/init.bash | 94 --------------------------------------- 5 files changed, 124 insertions(+), 97 deletions(-) create mode 100644 src/init delete mode 100644 src/init.bash diff --git a/install.sh b/install.sh index a4b84cf..27b97e0 100755 --- a/install.sh +++ b/install.sh @@ -49,7 +49,7 @@ install -v -D -m 755 ./src/archbox-desktop $PREFIX/bin/archbox-desktop install -v -D -m 755 ./src/exec $PREFIX/share/archbox/bin/exec install -v -D -m 755 ./src/enter $PREFIX/share/archbox/bin/enter install -v -D -m 755 ./src/chroot_setup $PREFIX/share/archbox/chroot_setup -install -v -D -m 755 ./src/init.bash $PREFIX/share/archbox/bin/init +install -v -D -m 755 ./src/init $PREFIX/share/archbox/bin/init install -v -D -m 755 ./src/uth.bash $PREFIX/share/archbox/bin/uth grep 'PREFIX=' $ETC_DIR/archbox.conf >/dev/null 2>&1 || cat << EOF >> $ETC_DIR/archbox.conf diff --git a/src/enter b/src/enter index 852d80c..dd49350 100644 --- a/src/enter +++ b/src/enter @@ -3,7 +3,7 @@ . /etc/archbox.conf >/dev/null 2>&1 . /tmp/archbox_env >/dev/null 2>&1 -REQ_ENV="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY" +REQ_ENV="DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR} DISPLAY=${DISPLAY} WAYLAND_DISPLAY=${WAYLAND_DISPLAY}" ENV="$REQ_ENV $ENV_VAR" COMMAND="$@" diff --git a/src/exec b/src/exec index e92e563..c46ee3c 100644 --- a/src/exec +++ b/src/exec @@ -3,7 +3,7 @@ . /etc/archbox.conf >/dev/null 2>&1 . /tmp/archbox_env >/dev/null 2>&1 -REQ_ENV="DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY" +REQ_ENV="DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR} DISPLAY=${DISPLAY} WAYLAND_DISPLAY=${WAYLAND_DISPLAY}" ENV="$REQ_ENV $ENV_VAR" COMMAND="$@" diff --git a/src/init b/src/init new file mode 100644 index 0000000..81ee364 --- /dev/null +++ b/src/init @@ -0,0 +1,121 @@ +#!/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 +} + +rbind(){ + if mount | grep "${CHROOT}"${1} >/dev/null 2>&1; then + msg "${CHROOT}${1} already mounted." + else + mount -R $1 "${CHROOT}"${1} + msg "${CHROOT}${1} mounted!" + fi + if [ $2 = "make-rslave" ]; then + mount --make-rslave ${CHROOT}${1} + fi +} + +rbind_diff() { + if mount | grep "${CHROOT}"${2}; then + msg "$CHROOT$2 already mounted." + else + mount -R $1 "${CHROOT}"${2} + msg "${CHROOT}${2} mounted!" + fi +} + +bindproc() { + if mount | grep "${CHROOT}"/proc; then + msg "${CHROOT}/proc already mounted." + else + mount -t proc /proc "${CHROOT}"/proc + msg "${CHROOT}/proc mounted!") + fi +} + +rmbind() { + umount_args=-R + [ $LAZY_UMOUNT = "yes" ] && umount_args=-Rl + if mount | grep "${CHROOT}"${1}; then + umount $umount_args "${CHROOT}"${1} + msg "${CHROOT}${1} unmounted!" + fi +} + +case $1 in + start) + bindproc + rbind /tmp + rbind /sys make-rslave + rbind /dev make-rslave + [ $MOUNT_RUN = "yes" ] && rbind /run + if [ $MOUNT_MOD = "yes" ]; then + rbind "$(readlink -f /lib/modules)" + rbind /boot + fi + [ -d /var/lib/dbus ] && rbind /var/lib/dbus + for i in $SHARED_FOLDER; do + if [ $i = *:* ]; then + source=$(printf "%s" "$i" | sed 's/:.*//') + target=$(printf "%s" "$i" | sed 's/.*://') + mkdir -p "${CHROOT}"${target} + rbind_diff $source $target; + else + rbind $i; + fi + done + msg "Starting services" + for j in $SERVICES; do + if [ $j = *:* ]; then + delay=$(printf "%s" "$j" | sed 's/.*://') + service=$(printf "%s" "$j" | sed 's/:.*//') + chroot "$CHROOT" /bin/su -c "/usr/local/bin/archboxctl exec $service" > /dev/null 2>&1 & + sleep $delay + else + chroot "$CHROOT" /bin/su -c "/usr/local/bin/archboxctl exec $j" > /dev/null 2>&1 & + fi + done + if [ -e /etc/archbox.rc ]; then + cp /etc/archbox.rc /tmp/archbox.rc + chmod +x /tmp/archbox.rc + chroot "$CHROOT" /bin/su -c '/tmp/archbox.rc' > /tmp/archbox.rc.log 2>&1 + rm /tmp/archbox.rc + fi + exit 0 + ;; + stop) + rmbind /proc + rmbind /tmp + rmbind /sys + rmbind /dev + [ $MOUNT_RUN = "yes" ] && rmbind /run + if [ $MOUNT_MOD = "yes" ]; then + rmbind $(readlink -f /lib/modules) + rmbind /boot + fi + rmbind /var/lib/dbus + for i in $SHARED_FOLDER; do + if [ $i = *:* ]; then + target=$(printf "%s" "$i" | sed 's/.*://') + rmbind $target; + else + rmbind $i; + fi + done + exit 0 + ;; +esac diff --git a/src/init.bash b/src/init.bash deleted file mode 100644 index bb3e570..0000000 --- a/src/init.bash +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bash - -source /etc/archbox.conf - -msg(){ - echo "$(tput bold)$(tput setaf 2)==> $@ $(tput sgr0)" -} - -rbind() { - [[ $(mount | grep $CHROOT$1) ]] && msg "$CHROOT$1 already mounted." \ - || (mount -R $1 $CHROOT$1 && msg "$CHROOT$1 mounted!") - [[ $2 = "make-rslave" ]] && mount --make-rslave $CHROOT$1 -} - -rbind_diff() { - [[ $(mount | grep $CHROOT$2) ]] && msg "$CHROOT$2 already mounted." \ - || (mount -R $1 $CHROOT$2 && msg "$CHROOT$2 mounted!") -} - -bindproc() { - [[ $(mount | grep $CHROOT/proc) ]] && msg "$CHROOT/proc already mounted." \ - || (mount -t proc /proc $CHROOT/proc && msg "$CHROOT/proc mounted!") -} - -rmbind() { - umount_args=-R - [[ $LAZY_UMOUNT = "yes" ]] && umount_args=-Rl - [[ $(mount | grep $CHROOT$1) ]] && umount $umount_args $CHROOT$1 \ - && msg "$CHROOT$1 unmounted!" -} - -case $1 in - start) - bindproc - rbind /tmp - rbind /sys make-rslave - rbind /dev make-rslave - [[ $MOUNT_RUN = "yes" ]] && rbind /run - if [[ $MOUNT_MOD = "yes" ]]; then - rbind $(readlink -f /lib/modules) - rbind /boot - fi - [[ -d /var/lib/dbus ]] && rbind /var/lib/dbus - for i in ${SHARED_FOLDER[@]}; do - if [[ $i = *:* ]]; then - source=$(echo $i | sed 's/:.*//') - target=$(echo $i | sed 's/.*://') - mkdir -p $CHROOT$target - rbind_diff $source $target; - else - rbind $i; - fi - done - msg "Starting services" - for j in ${SERVICES[@]}; do - if [[ $j = *:* ]]; then - delay=$(echo $j | sed 's/.*://') - service=$(echo $j | sed 's/:.*//') - chroot $CHROOT /bin/su -c "/usr/local/bin/archboxctl exec $service" > /dev/null 2>&1 & - sleep $delay - else - chroot $CHROOT /bin/su -c "/usr/local/bin/archboxctl exec $j" > /dev/null 2>&1 & - fi - done - if [[ -e /etc/archbox.rc ]]; then - cp /etc/archbox.rc /tmp/archbox.rc - chmod +x /tmp/archbox.rc - chroot $CHROOT /bin/su -c '/tmp/archbox.rc' > /tmp/archbox.rc.log 2>&1 - rm /tmp/archbox.rc - fi - exit 0 - ;; - stop) - rmbind /proc - rmbind /tmp - rmbind /sys - rmbind /dev - [[ $MOUNT_RUN = "yes" ]] && rmbind /run - if [[ $MOUNT_MOD = "yes" ]]; then - rmbind $(readlink -f /lib/modules) - rmbind /boot - fi - rmbind /var/lib/dbus - for i in ${SHARED_FOLDER[@]}; do - if [[ $i = *:* ]]; then - target=$(echo $i | sed 's/.*://') - rmbind $target; - else - rmbind $i; - fi - done - exit 0 - ;; -esac From 72ab95d4bfffb1d0d206f9dd37e14f4e86b13707 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Thu, 27 May 2021 18:07:36 +0700 Subject: [PATCH 15/18] POSIX rewrite: uth.bash --- install.sh | 2 +- src/uth | 31 +++++++++++++++++++++++++++++++ src/uth.bash | 31 ------------------------------- 3 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 src/uth delete mode 100644 src/uth.bash diff --git a/install.sh b/install.sh index 27b97e0..c0cbf20 100755 --- a/install.sh +++ b/install.sh @@ -50,7 +50,7 @@ install -v -D -m 755 ./src/exec $PREFIX/share/archbox/bin/exec install -v -D -m 755 ./src/enter $PREFIX/share/archbox/bin/enter install -v -D -m 755 ./src/chroot_setup $PREFIX/share/archbox/chroot_setup install -v -D -m 755 ./src/init $PREFIX/share/archbox/bin/init -install -v -D -m 755 ./src/uth.bash $PREFIX/share/archbox/bin/uth +install -v -D -m 755 ./src/uth $PREFIX/share/archbox/bin/uth grep 'PREFIX=' $ETC_DIR/archbox.conf >/dev/null 2>&1 || cat << EOF >> $ETC_DIR/archbox.conf diff --git a/src/uth b/src/uth new file mode 100644 index 0000000..836d536 --- /dev/null +++ b/src/uth @@ -0,0 +1,31 @@ +#!/bin/sh + +. /etc/archbox.conf >/dev/null 2>&1 +. /tmp/archbox_env >/dev/null 2>&1 + +case $1 in + copyresolv) + cp /etc/resolv.conf "${CHROOT}"/etc/resolv.conf + ;; + killxdg) + umount -l "${CHROOT}"/run + fuser -km $XDG_RUNTIME_DIR + exit $? + ;; + runtimeonly) + mkdir -p "${CHROOT}"${XDG_RUNTIME_DIR} + umount -Rl "${CHROOT}"${XDG_RUNTIME_DIR} 2>/dev/null + mount | grep "${CHROOT}"${XDG_RUNTIME_DIR} || \ + mount --rbind $XDG_RUNTIME_DIR "${CHROOT}"${XDG_RUNTIME_DIR} + exit $? + ;; + remountrun) + umount -l "${CHROOT}"/run 2>/dev/null + mount --rbind /run "${CHROOT}"/run + exit $? + ;; + chownvar) + chown $2 /tmp/archbox_env + chmod 755 /tmp/archbox_env + ;; +esac diff --git a/src/uth.bash b/src/uth.bash deleted file mode 100644 index b190f57..0000000 --- a/src/uth.bash +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -source /etc/archbox.conf &>/dev/null -source /tmp/archbox_env &>/dev/null - -case $1 in - copyresolv) - cp /etc/resolv.conf $CHROOT/etc/resolv.conf - ;; - killxdg) - umount -l $CHROOT/run - fuser -km $XDG_RUNTIME_DIR - exit $? - ;; - runtimeonly) - mkdir -p $CHROOT$XDG_RUNTIME_DIR - umount -Rl $CHROOT$XDG_RUNTIME_DIR 2>/dev/null - mount | grep $CHROOT$XDG_RUNTIME_DIR || \ - mount --rbind $XDG_RUNTIME_DIR $CHROOT$XDG_RUNTIME_DIR - exit $? - ;; - remountrun) - umount -l $CHROOT/run 2>/dev/null - mount --rbind /run $CHROOT/run - exit $? - ;; - chownvar) - chown $2 /tmp/archbox_env - chmod 755 /tmp/archbox_env - ;; -esac From 8344baa7862a0471d94d1368f78c3b2506c2defe Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Fri, 28 May 2021 15:17:42 +0700 Subject: [PATCH 16/18] Some fixes --- README.md | 10 ++++++++-- install.sh | 6 +++--- src/archbox | 11 +++++------ src/archbox-desktop | 4 +--- src/chroot_setup | 12 ++++++------ src/enter | 2 +- src/exec | 2 +- src/init | 18 +++++++++--------- 8 files changed, 34 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 310f0f7..b9c484e 100644 --- a/README.md +++ b/README.md @@ -86,14 +86,14 @@ This isn't actually using systemd to start services, rather it parses systemd .s ##### Autostart services To enable service on host boot, edit `/etc/archbox.conf` : ``` -SERVICES=( vmware-networks-configuration vmware-networks vmware-usbarbitrator nginx ) +SERVICES="vmware-networks-configuration vmware-networks vmware-usbarbitrator nginx" ``` Keep in mind that this doesn't resolve service dependencies, so you may need to enable the dependencies manually. you can use ```archboxctl desc ``` to read the .service file ##### Post-exec delay Services are asynchronously started, if some services have some issues when starting together you may want to add post-exec delay. ``` -SERVICES=( php-fpm:3 nginx ) +SERVICES="php-fpm:3 nginx" ``` This will add 3 seconds delay after executing php-fpm. @@ -163,6 +163,12 @@ sudo ln -s /usr /run/current-system/sw ``` make sure /run isn't mounted. +##### Archbox didn't recognize commands +Add ```PATH``` variable to ```/etc/archbox.conf```, for example: +``` +ENV_VAR="PATH=/usr/bin:/usr/local/bin" +``` + #### PulseAudio refused to connect This can be caused by different dbus machine-id between chroot and host, copying ```/etc/machine-id``` from host to chroot should do the job. #### XDG_RUNTIME_DIR is not visible in Archbox diff --git a/install.sh b/install.sh index c0cbf20..c4623f3 100755 --- a/install.sh +++ b/install.sh @@ -27,14 +27,14 @@ ENV_VAR="${ENV_VAR:-}" # Parse a Systemd service and executes it on boot, order matters, for example: # -# SERVICES=( vmware-networks-configuration vmware-networks vmware-usbarbitrator php-fpm:3 nginx ) +# SERVICES="vmware-networks-configuration vmware-networks vmware-usbarbitrator php-fpm:3 nginx" # # Keep in mind that this doesn't resolve service dependencies, so you may need to # enable the dependencies manually. -SERVICES=( ${SERVICES:-} ) +SERVICES="${SERVICES:-}" # Share other host directories into Archbox, absolute path needed. -SHARED_FOLDER=( ${SHARED_FOLDERS:-/home} ) +SHARED_FOLDER="${SHARED_FOLDERS:-/home}" EOF } diff --git a/src/archbox b/src/archbox index 8f0fb0a..5fd3d05 100644 --- a/src/archbox +++ b/src/archbox @@ -2,8 +2,6 @@ . /etc/archbox.conf -set -- - # Text colors/formatting red="\033[38;5;1" green="\033[38;5;2" @@ -16,11 +14,11 @@ err(){ } msg(){ - printf "${green}${bold}%s${reset}\n" "==> $*" 1>&2 + printf "${green}${bold}%s${reset}\n" "==> $*" } checkdep(){ - command -v $1 2>/dev/null || err "Install $1!" + command -v $1 >/dev/null 2>&1 || err "Install $1!" } asroot(){ @@ -71,7 +69,8 @@ fetch_tarball(){ case $1 in -c|--create) asroot - [ $2 ] && err "Specify the link of Arch Linux bootstrap tarball!" + echo $2 + [ ! $2 ] && err "Specify the link of Arch Linux bootstrap tarball!" msg "Creating chroot directory..." mkdir -p $INSTALL_PATH cd $INSTALL_PATH @@ -91,7 +90,7 @@ case $1 in 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 + cp "${PREFIX}"/share/archbox/chroot_setup "${CHROOT}"/chroot_setup printf "%s" $ARCHBOX_USER > /tmp/archbox_user chroot $CHROOT /bin/sh /chroot_setup exit $? diff --git a/src/archbox-desktop b/src/archbox-desktop index fba0672..1a47fe0 100644 --- a/src/archbox-desktop +++ b/src/archbox-desktop @@ -2,8 +2,6 @@ . /etc/archbox.conf >/dev/null 2>&1 -set -- - # Text colors/formatting red="\033[38;5;1" green="\033[38;5;2" @@ -31,7 +29,7 @@ install_desktop(){ } checkdep(){ - command -v $1 2>/dev/null || err "Install $1!" + command -v $1 >/dev/null 2>&1 || err "Install $1!" } help_text(){ diff --git a/src/chroot_setup b/src/chroot_setup index a269d73..ee080e7 100644 --- a/src/chroot_setup +++ b/src/chroot_setup @@ -1,7 +1,3 @@ -. /etc/archbox.conf >/dev/null 2>&1 - -set -- - # Text colors/formatting red="\033[38;5;1" green="\033[38;5;2" @@ -23,13 +19,16 @@ msg "Initializing pacman keyrings..." pacman-key --init pacman-key --populate archlinux msg "Installing essential packages..." -pacman -Syu base base-devel xorg pulseaudio nano --noconfirm +pacman -Syu base base-devel nano --noconfirm +printf "%s" "Do you want to use GUI apps? (y/n) " +read INSTALL_GUI +[ "$INSTALL_GUI" = "y" ] && pacman -Syu xorg pulseaudio --noconfirm msg "Installing archboxctl..." mkdir -p /usr/local/bin curl https://raw.githubusercontent.com/lemniskett/archboxctl/master/archboxctl.bash > /usr/local/bin/archboxctl chmod 755 /usr/local/bin/archboxctl msg "Setting up locale..." -printf "%s\n" "Uncomment needed locale, enter to continue" +printf "%s" "Uncomment needed locale, enter to continue" read nano /etc/locale.gen locale-gen @@ -38,6 +37,7 @@ printf "%s\n" "Enter your timezone, for example : \"Asia/Jakarta\"" while true; do read TIMEZONE \ && [ -e /usr/share/zoneinfo/$TIMEZONE ] \ + && rm -f /etc/localtime \ && ln -s /usr/share/zoneinfo/$TIMEZONE /etc/localtime \ && break \ || printf "%s\n" "Timezone not found, enter it again." diff --git a/src/enter b/src/enter index dd49350..ba71e66 100644 --- a/src/enter +++ b/src/enter @@ -7,4 +7,4 @@ REQ_ENV="DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} XDG_RUNTIME_DIR=${ ENV="$REQ_ENV $ENV_VAR" COMMAND="$@" -chroot $CHROOT /sbin/env $ENV /bin/su $ARCHBOX_USER +chroot $CHROOT /usr/bin/env $ENV /bin/su $ARCHBOX_USER diff --git a/src/exec b/src/exec index c46ee3c..fa33147 100644 --- a/src/exec +++ b/src/exec @@ -7,4 +7,4 @@ REQ_ENV="DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} XDG_RUNTIME_DIR=${ ENV="$REQ_ENV $ENV_VAR" COMMAND="$@" -chroot $CHROOT /bin/su -c "env $ENV $COMMAND" $ARCHBOX_USER +chroot $CHROOT /bin/su -c "/usr/bin/env $ENV $COMMAND" $ARCHBOX_USER diff --git a/src/init b/src/init index 81ee364..1f2e07b 100644 --- a/src/init +++ b/src/init @@ -18,19 +18,19 @@ msg(){ } rbind(){ - if mount | grep "${CHROOT}"${1} >/dev/null 2>&1; then + if [ "$(mount | grep "${CHROOT}"${1} >/dev/null 2>&1)" ]; then msg "${CHROOT}${1} already mounted." else mount -R $1 "${CHROOT}"${1} msg "${CHROOT}${1} mounted!" fi - if [ $2 = "make-rslave" ]; then + if [ "$2" = "make-rslave" ]; then mount --make-rslave ${CHROOT}${1} fi } rbind_diff() { - if mount | grep "${CHROOT}"${2}; then + if [ "$(mount | grep "${CHROOT}"${2})" ]; then msg "$CHROOT$2 already mounted." else mount -R $1 "${CHROOT}"${2} @@ -39,18 +39,18 @@ rbind_diff() { } bindproc() { - if mount | grep "${CHROOT}"/proc; then + if [ "$(mount | grep "${CHROOT}"/proc)" ]; then msg "${CHROOT}/proc already mounted." else mount -t proc /proc "${CHROOT}"/proc - msg "${CHROOT}/proc mounted!") + msg "${CHROOT}/proc mounted!" fi } rmbind() { umount_args=-R - [ $LAZY_UMOUNT = "yes" ] && umount_args=-Rl - if mount | grep "${CHROOT}"${1}; then + [ "$LAZY_UMOUNT" = "yes" ] && umount_args=-Rl + if [ "$(mount | grep "${CHROOT}"${1})" ]; then umount $umount_args "${CHROOT}"${1} msg "${CHROOT}${1} unmounted!" fi @@ -62,8 +62,8 @@ case $1 in rbind /tmp rbind /sys make-rslave rbind /dev make-rslave - [ $MOUNT_RUN = "yes" ] && rbind /run - if [ $MOUNT_MOD = "yes" ]; then + [ "$MOUNT_RUN" = "yes" ] && rbind /run + if [ "$MOUNT_MOD" = "yes" ]; then rbind "$(readlink -f /lib/modules)" rbind /boot fi From 689a7e712e03e98eab31123f39095bf19ba959f2 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Fri, 28 May 2021 16:35:01 +0700 Subject: [PATCH 17/18] Some fixes (again) --- NIXOS_INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NIXOS_INSTALL.md b/NIXOS_INSTALL.md index 7c014de..10bbeab 100644 --- a/NIXOS_INSTALL.md +++ b/NIXOS_INSTALL.md @@ -52,7 +52,7 @@ export PREFIX=$out export ARCHBOX_USER=lemni export MOUNT_RUN=no export ENV_VAR="TERM=foot" -export SHARED_FOLDER=( /home /var/www ) +export SHARED_FOLDER="/home /var/www" ${pkgs.bash}/bin/bash install.sh ``` ### Regular Installation From 4b9575cb07865183dc1be799ceeded50482c24d0 Mon Sep 17 00:00:00 2001 From: Syahrial Agni Prasetya Date: Fri, 28 May 2021 16:40:20 +0700 Subject: [PATCH 18/18] POSIX-rewrite: startx-killxdg.bash --- src/exp/startx-killxdg.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exp/startx-killxdg.bash b/src/exp/startx-killxdg.bash index 8ec6443..34ea6df 100755 --- a/src/exp/startx-killxdg.bash +++ b/src/exp/startx-killxdg.bash @@ -1,6 +1,6 @@ -#!/bin/bash +#!/bin/sh -source /etc/archbox.conf +. /etc/archbox.conf startx $PRIV $PREFIX/share/archbox/bin/uth killxdg