Initial commit

This commit is contained in:
Fierelier 2023-10-07 16:01:03 +02:00
commit a51ed6f0d4
7 changed files with 196 additions and 0 deletions

9
LICENSE Normal file
View File

@ -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.

24
README.txt Normal file
View File

@ -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 <command>
Commands:
* help
Show this help.
* prefix-start </path/to/prefix> <command>
Start a program within a prefix. If PROOTH_ROOT is set to 1, it will use settings that emulate root rights.
* app-export </path/to/prefix> <application or /path/to/application.desktop> <name-suffix>
Add a desktop launcher from the prefix to the host.

8
app/app Executable file
View File

@ -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"/"${@}"

58
app/cmd/app-export Executable file
View File

@ -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"

12
app/cmd/help Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
echo "\
* help
Show this help.
* prefix-start </path/to/prefix> <command>
Start a program within a prefix. If PROOTH_ROOT is set to 1, it will use settings that emulate root rights.
* app-export </path/to/prefix> <application or /path/to/application.desktop> <name-suffix>
Add a desktop launcher from the prefix to the host.\
"

58
app/cmd/prefix-start Executable file
View File

@ -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[@]}"

27
install Executable file
View File

@ -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"