From a51ed6f0d439a0d2ccbc12bd81eb71ba5d8f10c6 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Sat, 7 Oct 2023 16:01:03 +0200 Subject: [PATCH] Initial commit --- LICENSE | 9 +++++++ README.txt | 24 ++++++++++++++++++ app/app | 8 ++++++ app/cmd/app-export | 58 ++++++++++++++++++++++++++++++++++++++++++++ app/cmd/help | 12 +++++++++ app/cmd/prefix-start | 58 ++++++++++++++++++++++++++++++++++++++++++++ install | 27 +++++++++++++++++++++ 7 files changed, 196 insertions(+) create mode 100644 LICENSE create mode 100644 README.txt create mode 100755 app/app create mode 100755 app/cmd/app-export create mode 100755 app/cmd/help create mode 100755 app/cmd/prefix-start create mode 100755 install diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..67fe97b --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..54f6c79 --- /dev/null +++ b/README.txt @@ -0,0 +1,24 @@ +Prerequisites: +* proot +* sed + +Installation: +* Run sudo ./install +* If you want to alter the settings, do sudo bash. From there, set DISTRO to change the program's name. Eg. DISTRO=foobar ./install + +Uninstallation: +* Run sudo bash and run UNINSTALL=1 ./install +* If you altered your DISTRO value before, you have to set it to the sme value + +Running: +* Syntax: proot-helper + +Commands: +* help +Show this help. + +* prefix-start +Start a program within a prefix. If PROOTH_ROOT is set to 1, it will use settings that emulate root rights. + +* app-export +Add a desktop launcher from the prefix to the host. diff --git a/app/app b/app/app new file mode 100755 index 0000000..b9560bd --- /dev/null +++ b/app/app @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e +export PROOTH_DIR="$(dirname "$(realpath "$BASH_SOURCE")")" +if [[ "${@}" == "" ]]; then + "$PROOTH_DIR/cmd/help" + exit 1 +fi +exec "$PROOTH_DIR/cmd"/"${@}" diff --git a/app/cmd/app-export b/app/cmd/app-export new file mode 100755 index 0000000..e6eb909 --- /dev/null +++ b/app/cmd/app-export @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +set -e +FULL_PREFIX="$(realpath -s "$1")" +HASH_PREFIX=($(echo "$FULL_PREFIX" | md5sum)) +DESKTOP_FILE="$1/$2" + +if ! [ -f "$DESKTOP_FILE" ]; then + if [ -f "$1/$HOME/.local/share/applications/$2.desktop" ]; then + DESKTOP_FILE="$1/$HOME/.local/share/applications/$2.desktop" + elif [ -f "$1/usr/local/share/applications/$2.desktop" ]; then + DESKTOP_FILE="$1/usr/local/share/applications/$2.desktop" + elif [ -f "$1/usr/share/applications/$2.desktop" ]; then + DESKTOP_FILE="$1/usr/share/applications/$2.desktop" + fi +fi + +OUTPUT="$HOME/.local/share/applications/$HASH_PREFIX-$(basename "$DESKTOP_FILE")" + +if [ -f "$OUTPUT" ]; then + rm "$OUTPUT" +fi + +while IFS="" read -r p || [ -n "$p" ] +do + USELINE=1 + if ! [ "$3" = "" ] && [[ "$p" == "Name="* ]] || [[ "$p" == "Name["*"]="* ]] || [[ "$p" == "GenericName="* ]] || [[ "$p" == "GenericName["*"]="* ]] || [[ "$p" == "X-GNOME-FullName="* ]] || [[ "$p" == "X-GNOME-FullName["*"]="* ]]; then + p="$p [$3]" + fi + + if [[ "$p" == "Exec="* ]]; then + p="${p/=/=\"$PROOTH_DIR/app\" prefix-start \"$FULL_PREFIX\" }" + fi + + shopt -s nullglob + if [[ "$p" == "Icon="* ]]; then + ICON="${p/Icon=/}" + for ICON_FILE in "$1/usr/share/icons/"*"/"*"/"*"/$ICON."*; do + NEW_ICON_FILE="${ICON_FILE/$1\/usr\/share\/icons\//}" + NEW_ICON_FILE="$(echo "$NEW_ICON_FILE" | sed 's/[^\/]*\///')" + NEW_ICON_DIR="$HOME/.icons/hicolor/$(dirname "$NEW_ICON_FILE")" + NEW_ICON_FILE="$NEW_ICON_DIR/$HASH_PREFIX-$(basename "$NEW_ICON_FILE")" + mkdir -p "$NEW_ICON_DIR" + cp "$ICON_FILE" "$NEW_ICON_FILE" + done + p="Icon=$HASH_PREFIX-$ICON" + fi + shopt -u nullglob + + if [[ "$p" == "TryExec="* ]]; then + USELINE=0 + fi + + if [ "$USELINE" = "1" ]; then + echo "$p" >> "$OUTPUT" + fi +done < "$DESKTOP_FILE" + +chmod +x "$OUTPUT" diff --git a/app/cmd/help b/app/cmd/help new file mode 100755 index 0000000..93f9160 --- /dev/null +++ b/app/cmd/help @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e +echo "\ +* help +Show this help. + +* prefix-start +Start a program within a prefix. If PROOTH_ROOT is set to 1, it will use settings that emulate root rights. + +* app-export +Add a desktop launcher from the prefix to the host.\ +" diff --git a/app/cmd/prefix-start b/app/cmd/prefix-start new file mode 100755 index 0000000..ce0b2f0 --- /dev/null +++ b/app/cmd/prefix-start @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +set -e +export PROOTH_COMMAND=("${@}") +unset "PROOTH_COMMAND[0]" + +if ! [ -f "$1/etc/resolv.conf" ]; then + cp "/etc/resolv.conf" "$1/etc/resolv.conf" +fi + +if [ "$PROOTH_ROOT" = "1" ]; then + export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + export PROOTH_COMMAND=( + exec proot -r "$1" + -b /etc/host.conf + -b /etc/hosts + -b /etc/nsswitch.conf + -b /dev/ + -b /sys/ + -b /proc/ + -b /tmp/ + -w / + -0 + "${PROOTH_COMMAND[@]}" + ) +else + export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" + export PROOTH_COMMAND=( + exec proot -r "$1" + -b /etc/host.conf + -b /etc/hosts + -b /etc/hosts.equiv + -b /etc/mtab + -b /etc/netgroup + -b /etc/networks + -b /etc/passwd + -b /etc/group + -b /etc/nsswitch.conf + -b /etc/resolv.conf + -b /etc/localtime + -b /dev/ + -b /sys/ + -b /proc/ + -b /tmp/ + -b /run/ + -b /usr/share/themes + -b /usr/share/icons + -b "$HOME/.themes" + -b "$HOME/.icons" + -b "$HOME:$HOME/host" + "${PROOTH_COMMAND[@]}" + ) +fi + +if [ -x "$1/opt/proot-helper/start" ]; then + eval "$("$1/opt/proot-helper/start")" +fi + +"${PROOTH_COMMAND[@]}" diff --git a/install b/install new file mode 100755 index 0000000..fa5ab27 --- /dev/null +++ b/install @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -e +INSTALLER_DIR="$(dirname "$(realpath "$BASH_SOURCE")")" +DISTRO="${DISTRO:=proot-helper}" +UNINSTALL="${UNINSTALL:=0}" + +if [ "$UNINSTALL" == "1" ]; then + echo "Uninstalling $DISTRO ..." +else + echo "Installing $DISTRO ..." +fi + +if [ -d "/opt/$DISTRO" ]; then + rm -r "/opt/$DISTRO" +fi + +if [ -L "/usr/local/bin/$DISTRO" ]; then + rm "/usr/local/bin/$DISTRO" +fi + +if [ "$UNINSTALL" == "1" ]; then + exit 0 +fi + +cp -r "$INSTALLER_DIR/app" "/opt/$DISTRO" +ln -s "/opt/$DISTRO/app" "/usr/local/bin/$DISTRO" +chmod +x "/usr/local/bin/$DISTRO"