POSIX rewrite: archbox-desktop.bash

This commit is contained in:
Syahrial Agni Prasetya 2021-05-19 11:56:36 +07:00
parent 3719a80f5d
commit 62bcdc8a98
No known key found for this signature in database
GPG Key ID: 46F88749C8C79383
2 changed files with 46 additions and 28 deletions

View File

@ -2,6 +2,8 @@
. /etc/archbox.conf . /etc/archbox.conf
set --
# Text colors/formatting # Text colors/formatting
red="\033[38;5;1" red="\033[38;5;1"
green="\033[38;5;2" green="\033[38;5;2"
@ -28,9 +30,9 @@ asroot(){
storeenv() { storeenv() {
printf "%s\n" "# This will be sourced when entering Archbox" > /tmp/archbox_env 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 ] && \ [ $WAYLAND_DISPLAY ] && \
printf "%s\n" "WAYLAND_DISPLAY=${WAYLAND_DISPLAY}" >> /tmp/archbox_env 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 command -v xhost >/dev/null 2>&1 && xhost +local: > /dev/null
printf "%s\n" "DISPLAY=${DISPLAY}" >> /tmp/archbox_env printf "%s\n" "DISPLAY=${DISPLAY}" >> /tmp/archbox_env
fi fi
@ -69,7 +71,7 @@ fetch_tarball(){
case $1 in case $1 in
-c|--create) -c|--create)
asroot 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..." msg "Creating chroot directory..."
mkdir -p $INSTALL_PATH mkdir -p $INSTALL_PATH
cd $INSTALL_PATH cd $INSTALL_PATH

View File

@ -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(){ install_desktop(){
mkdir -p ~/.local/share/applications/archbox mkdir -p ~/.local/share/applications/archbox
for i in $@; do for i in $@; do
archbox readlink /usr/share/applications/$i >/dev/null 2>&1 \ archbox readlink /usr/share/applications/$i >/dev/null 2>&1 \
&& cp $CHROOT/$(archbox readlink /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 || cp "${CHROOT}"/usr/share/applications/$i "~/.local/share/applications/archbox"
sed -i 's/Exec=/Exec=archbox\ /g' ~/.local/share/applications/archbox/$i sed -i 's/Exec=/Exec=archbox\ /g' ~/.local/share/applications/archbox/$i
sed -i '/TryExec=/d' ~/.local/share/applications/archbox/$i sed -i '/TryExec=/d' ~/.local/share/applications/archbox/$i
done done
} }
checkdep(){ checkdep(){
hash $1 2>/dev/null || err "Install $1!" command -v $1 2>/dev/null || err "Install $1!"
}
err(){
echo "$(tput bold)$(tput setaf 1)==> $@ $(tput sgr0)" 1>&2
exit 1
} }
help_text(){ help_text(){
cat << EOF printf "%s" "
USAGE: $0 <arguments> USAGE: $0 <arguments>
OPTIONS: OPTIONS:
@ -33,19 +45,25 @@ OPTIONS:
-s, --list-installed List installed desktop entries -s, --list-installed List installed desktop entries
-h, --help Displays this help message -h, --help Displays this help message
EOF "
}
list(){
for i in $*/*; do
printf "%s\n" "$i"
done
} }
case $1 in case $1 in
-i|--install) -i|--install)
checkdep update-desktop-database checkdep update-desktop-database
install_desktop ${@:2} install_desktop ${@#$1}
update-desktop-database update-desktop-database
exit $? exit $?
;; ;;
-r|--remove) -r|--remove)
checkdep update-desktop-database checkdep update-desktop-database
selected_entry=${@:2} selected_entry=${@#$1}
for i in $selected_entry; do for i in $selected_entry; do
rm ~/.local/share/applications/archbox/$i rm ~/.local/share/applications/archbox/$i
done done
@ -57,12 +75,11 @@ case $1 in
exit 0 exit 0
;; ;;
-l|--list) -l|--list)
archbox ls -1 --color=none /usr/share/applications list "${CHROOT}"/usr/share/applications
exit $?
;; ;;
-s|--list-installed) -s|--list-installed)
ls -1 --color=none ~/.local/share/applications/archbox mkdir -p ~/.local/share/applications/archbox
exit $? list ~/.local/share/applications/archbox
;; ;;
*) *)
checkdep zenity checkdep zenity
@ -74,23 +91,22 @@ case $1 in
FALSE 'Install desktop entries' FALSE 'Remove desktop entries')" FALSE 'Install desktop entries' FALSE 'Remove desktop entries')"
case $action in case $action in
'Install desktop entries') 'Install desktop entries')
list_desktop="$(archbox ls --color=none -1 /usr/share/applications)" zenity_entry="$(list "${CHROOT}"/usr/share/applications | sed 's/\ /\ FALSE\ /g')"
zenity_entry="$(echo $list_desktop | sed 's/\ /\ FALSE\ /g')"
selected_entry=$(zenity --list --checklist --height=500 --width=450 \ selected_entry=$(zenity --list --checklist --height=500 --width=450 \
--title="Archbox Desktop Manager" \ --title="Archbox Desktop Manager" \
--text "Select .desktop entries those you want to install" \ --text "Select .desktop entries those you want to install" \
--column "Select" --column "Applications" \ --column "Select" --column "Applications" \
FALSE $zenity_entry | sed 's/|/\ /g') FALSE $zenity_entry | sed 's/|/\ /g')
[[ -z $selected_entry ]] && exit 1 [ $selected_entry ] || exit 1
install_desktop $selected_entry install_desktop $selected_entry
update-desktop-database update-desktop-database
exit 0 exit 0
;; ;;
'Remove desktop entries') 'Remove desktop entries')
list_desktop="$(ls --color=none -1 ~/.local/share/applications/archbox)" list_desktop="$(list ~/.local/share/applications/archbox)"
[[ -z $list_desktop ]] && zenity --info --title "Archbox Desktop Manager" \ [ $list_desktop = "*" ] && zenity --info --title "Archbox Desktop Manager" \
--text "No .desktop files installed" --width=300 && exit 1 --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 \ selected_entry=$(zenity --list --checklist --height=500 --width=450 \
--title="Archbox Desktop Manager" \ --title="Archbox Desktop Manager" \
--text "Select .desktop entries those you want to remove" \ --text "Select .desktop entries those you want to remove" \