Skip to content

Commit

Permalink
Merge pull request #918 from ivan-hc/dev
Browse files Browse the repository at this point in the history
Update sandboxes.am: refactoring
  • Loading branch information
ivan-hc authored Sep 2, 2024
2 parents 3c1a1e8 + dcfa283 commit 210a47e
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions modules/sandboxes.am
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ _check_aisap() {
return 1
elif ! command -v aisap 1>/dev/null; then
printf '\n%s\n\n' " Error: You need aisap for this script work"
read -p " ◆ DO YOU WISH TO INSTALL AISAP? Install size <5 MiB? (Y/n) " yn
read -r -p " ◆ DO YOU WISH TO INSTALL AISAP? Install size <5 MiB? (Y/n) " yn
if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
echo " OPERATION ABORTED!"
return 1
Expand Down Expand Up @@ -177,33 +177,33 @@ _generate_sandbox_script() {

_configure_dirs_access() {
printf '\033[33m\n'
read -p " Do you want configure access to directories? (Y/n): " yn
read -r -p " Do you want configure access to directories? (Y/n): " yn
if echo "$yn" | grep -i '^n' >/dev/null 2>&1; then
return 0
fi
printf '\033[36m'
for DIR in DESKTOP DOCUMENTS DOWNLOAD GAMES MUSIC PICTURES VIDEOS; do
eval XDG_DIR=\$$DIR
read -p " Allow $1 access to \"$XDG_DIR\"? (y/N) " yn
read -r -p " Allow $1 access to \"$XDG_DIR\"? (y/N) " yn
if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
tmpscript=$(echo "$tmpscript" \
| sed "s#--rm-file \"\$$DIR\"#--add-file \"\$$DIR\":rw#g" )
fi
done
sleep 0.5
printf '\033[31m'
read -p " Allow $1 access to a specific directory? (y/N) " yn
read -r -p " Allow $1 access to a specific directory? (y/N) " yn
if echo "$yn" | grep -i '^y' >/dev/null 2>&1; then
echo " WARNING: Giving access to all of $HOME or / and similar is not safe"
echo " Also aisap might not let $1 start when such paths are given"
printf '\033[33m%s\n' " Type the path to the directory"
read -p " Example: /media/external-drive or ~/Backups: " NEWDIR
read -r -p " Example: /media/external-drive or ~/Backups: " NEWDIR
case "$NEWDIR" in
'$HOME'|'$HOME/'|"$HOME"|"$HOME/"|"/"|"~"|"~/"|"/home"|"/home/"|\
"$DATADIR"|'$XDG_DATA_HOME'|"$CONFIGDIR"|'$XDG_CONFIG_HOME'|"$BINDIR")
"\$HOME"|"\$HOME/"|"$HOME"|"$HOME/"|"/"|"~"|~/|"/home"|"/home/"|\
"$DATADIR"|"\$XDG_DATA_HOME"|"$CONFIGDIR"|"\$XDG_CONFIG_HOME"|"$BINDIR")
notify-send -u critical "DO YOU WANT THE FBI TO GET YA?"
printf '\033[31m\n'
read -p " SPOOKY LOCATION! ARE YOU SURE? IF SO TYPE \"YES\": " YES
read -r -p " SPOOKY LOCATION! ARE YOU SURE? IF SO TYPE \"YES\": " YES
[ "$YES" != "YES" ] && echo " That's not \"YES\", aborting" && return 1
;;
'')
Expand Down Expand Up @@ -231,7 +231,7 @@ _install_sandbox_script() {
printf '\033[32m\n%s\n\033[0m' " \"$1\" successfully sandboxed!"
printf '\n%s\n' " $1 will be sandboxed in \"$SANDBOXDIR\""
printf '%s\n\n' " once launched"
printf '%s\n' ' Set the $SANDBOXDIR env variable to move the location'
printf '%s\n' " Set the \$SANDBOXDIR env variable to move the location"
printf '\n%s' ' Use '
printf '\033[33m%s' '--disable-sandbox'
printf '\033[0m%s\033[33m\n' " to revert the changes, in this case that is:"
Expand All @@ -243,36 +243,36 @@ _install_sandbox_script() {
[ -z "$2" ] && echo " USAGE: $AMCLI $1 [ARGUMENT]" && exit 1
case "$1" in
'--sandbox')
shift
for arg in ${@}; do
_check_appimage "${@}" && _check_aisap "${@}" \
&& _generate_sandbox_script "${@}" \
&& _configure_dirs_access "${@}" \
&& _install_sandbox_script "${@}"
ARGS="$(echo "$@" | cut -f2- -d ' ')"
for arg in $ARGS; do
_check_appimage "$arg" && _check_aisap "$arg" \
&& _generate_sandbox_script "$arg" \
&& _configure_dirs_access "$arg" \
&& _install_sandbox_script "$arg"
shift
done
;;

'--disable-sandbox')
shift
for arg in ${@}; do
_disable_sandbox "${@}"
ARGS="$(echo "$@" | cut -f2- -d ' ')"
for arg in $ARGS; do
_disable_sandbox "$arg"
shift
done
;;

'-H'|'--home')
shift
for arg in ${@}; do
_check_appimage "${@}" && _home "${@}"
ARGS="$(echo "$@" | cut -f2- -d ' ')"
for arg in $ARGS; do
_check_appimage "$arg" && _home "$arg"
shift
done
;;

'-C'|'--config')
shift
for arg in ${@}; do
_check_appimage "${@}" && _config "${@}"
ARGS="$(echo "$@" | cut -f2- -d ' ')"
for arg in $ARGS; do
_check_appimage "$arg" && _config "$arg"
shift
done
;;
Expand Down

0 comments on commit 210a47e

Please sign in to comment.