First commit
This commit is contained in:
commit
6ed0fcbb7e
|
@ -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.
|
|
@ -0,0 +1,27 @@
|
|||
Prerequisites:
|
||||
* linux-utils
|
||||
* 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 same value
|
||||
|
||||
Running:
|
||||
* Syntax: unshare-helper <command>
|
||||
|
||||
Commands:
|
||||
* help
|
||||
Show this help.
|
||||
|
||||
* prefix-start </path/to/prefix> <command>
|
||||
Start a program within a prefix. If UNSHH_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.
|
||||
|
||||
* app-unexport </path/to/prefix> <application>
|
||||
Remove a desktop launcher of a prefix from the host.
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
export UNSHH_DIR="$(dirname "$(realpath "$BASH_SOURCE")")"
|
||||
if [[ "${@}" == "" ]]; then
|
||||
"$UNSHH_DIR/cmd/help"
|
||||
exit 1
|
||||
fi
|
||||
exec "$UNSHH_DIR/cmd"/"${@}"
|
|
@ -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/=/=\"$UNSHH_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"
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
FULL_PREFIX="$(realpath -s "$1")"
|
||||
HASH_PREFIX=($(echo "$FULL_PREFIX" | md5sum))
|
||||
DESKTOP_FILE="$2"
|
||||
|
||||
if ! [ -f "$DESKTOP_FILE" ]; then
|
||||
if [ -f "$HOME/.local/share/applications/$HASH_PREFIX-$2.desktop" ]; then
|
||||
DESKTOP_FILE="$HOME/.local/share/applications/$HASH_PREFIX-$2.desktop"
|
||||
fi
|
||||
fi
|
||||
|
||||
while IFS="" read -r p || [ -n "$p" ]
|
||||
do
|
||||
shopt -s nullglob
|
||||
if [[ "$p" == "Icon="* ]]; then
|
||||
ICON="${p/Icon=/}"
|
||||
for ICON_FILE in "$HOME/.icons/hicolor/"*"/"*"/$ICON."*; do
|
||||
rm -f "$ICON_FILE"
|
||||
done
|
||||
fi
|
||||
shopt -u nullglob
|
||||
done < "$DESKTOP_FILE"
|
||||
rm -f "$DESKTOP_FILE"
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
echo "\
|
||||
* help
|
||||
Show this help.
|
||||
|
||||
* prefix-start </path/to/prefix> <command>
|
||||
Start a program within a prefix.
|
||||
|
||||
* app-export </path/to/prefix> <application name or /path/to/application.desktop> <name-suffix>
|
||||
Add a desktop launcher from the prefix to the host.
|
||||
|
||||
* app-unexport </path/to/prefix> <application>
|
||||
Remove a desktop launcher of a prefix from the host.\
|
||||
"
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
export UNSHH_CHROOT="$1"
|
||||
UNSHH_COMMAND=("${@}")
|
||||
unset "UNSHH_COMMAND[0]"
|
||||
|
||||
if ! [ -d "$1" ]; then
|
||||
echo "'$1' is not a directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [ -f "$1/etc/resolv.conf" ]; then
|
||||
cp "/etc/resolv.conf" "$1/etc/resolv.conf"
|
||||
fi
|
||||
|
||||
if ! [ -d "$1/opt/unshh" ]; then
|
||||
mkdir -p "$1/opt"
|
||||
cp -r "$UNSHH_DIR/skel" "$1/opt/unshh"
|
||||
fi
|
||||
|
||||
export UNSHH_GROUP_NAME="$(id -n -g)"
|
||||
export UNSHH_GROUP_ID="$(id -g)"
|
||||
export UNSHH_USER_NAME="$(id -n -u)"
|
||||
export UNSHH_USER_ID="$(id -u)"
|
||||
unshare --mount --map-root-user "$UNSHH_CHROOT/opt/unshh/init" "${UNSHH_COMMAND[@]}"
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
UNSHH_SKELDIR="$(dirname "$(realpath "$BASH_SOURCE")")"
|
||||
UNSHH_COMMAND="${@}"
|
||||
for UNSHH_SCRIPTFILE in "$UNSHH_SKELDIR/scripts/"*; do
|
||||
source "$UNSHH_SCRIPTFILE"
|
||||
done
|
|
@ -0,0 +1,8 @@
|
|||
UNSHH_PATH_ROOT="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
UNSHH_PATH_USER="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
|
||||
export PATH="$UNSHH_SKELDIR/bin:$UNSHH_PATH_ROOT"
|
||||
while IFS='=' read -r -d '' n v; do
|
||||
if [ "$n" = "UNSHH_"* ]; then
|
||||
export -n "$n"
|
||||
fi
|
||||
done < <(env -0)
|
|
@ -0,0 +1,8 @@
|
|||
mkdir -p "$UNSHH_CHROOT/proc"
|
||||
mount --rbind /proc "$UNSHH_CHROOT/proc"
|
||||
mkdir -p "$UNSHH_CHROOT/sys"
|
||||
mount --rbind /sys "$UNSHH_CHROOT/sys"
|
||||
mkdir -p "$UNSHH_CHROOT/dev"
|
||||
mount --rbind /dev "$UNSHH_CHROOT/dev"
|
||||
mkdir -p "$UNSHH_CHROOT/tmp"
|
||||
mount --rbind /dev "$UNSHH_CHROOT/tmp"
|
|
@ -0,0 +1,6 @@
|
|||
set +e
|
||||
unshare --mount --map-root-user -R "$UNSHH_CHROOT" groupadd -g "$UNSHH_GROUP_ID" "$UNSHH_GROUP_NAME"
|
||||
unshare --mount --map-root-user -R "$UNSHH_CHROOT" useradd -m --uid "$UNSHH_USER_ID" --gid "$UNSHH_GROUP_ID" "$UNSHH_USER_NAME"
|
||||
set -e
|
||||
mkdir -p "$UNSHH_CHROOT/home/$UNSHH_USER_NAME/host"
|
||||
mount --bind "/home/$UNSHH_USER_NAME" "$UNSHH_CHROOT/home/$UNSHH_USER_NAME/host"
|
|
@ -0,0 +1 @@
|
|||
export PATH="$UNSHH_PATH_USER"
|
|
@ -0,0 +1,2 @@
|
|||
unshare --mount --map-user="$UNSHH_USER_ID" --map-group="$UNSHH_GROUP_ID" -R "$UNSHH_CHROOT" "${UNSHH_COMMAND[@]}"
|
||||
#unshare --mount --map-root-user -R "$UNSHH_CHROOT" "${UNSHH_COMMAND[@]}"
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
INSTALLER_DIR="$(dirname "$(realpath "$BASH_SOURCE")")"
|
||||
DISTRO="${DISTRO:=unshare-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"
|
Loading…
Reference in New Issue