archbox/archbox-desktop.bash

110 lines
3.8 KiB
Bash
Raw Normal View History

2020-12-28 05:22:53 +00:00
#!/usr/bin/env bash
2020-12-15 07:11:47 +00:00
source /etc/archbox.conf
install_desktop(){
mkdir -p ~/.local/share/applications/archbox
for i in $@; do
archbox readlink /usr/share/applications/$i >/dev/null 2>&1 \
&& cp $CHROOT/$(archbox readlink /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
2020-12-19 08:14:23 +00:00
sed -i '/TryExec=/d' ~/.local/share/applications/archbox/$i
2020-12-15 07:11:47 +00:00
done
}
2020-12-15 07:18:45 +00:00
checkdep(){
2021-01-10 06:01:43 +00:00
hash $1 2>/dev/null || err "Install $1!"
2020-12-15 07:18:45 +00:00
}
err(){
echo "$(tput bold)$(tput setaf 1)==> $@ $(tput sgr0)" 1>&2
2020-12-15 07:18:45 +00:00
exit 1
}
2020-12-15 07:11:47 +00:00
help_text(){
cat << EOF
USAGE: $0 <arguments>
OPTIONS:
2020-12-16 07:42:26 +00:00
-i, --install FILE Installs desktop entries in /usr/share/applications
-r, --remove FILE Removes desktop entries in ~/.local/share/applications/archbox
-l, --list List available desktop entries
-s, --list-installed List installed desktop entries
2020-12-15 07:11:47 +00:00
-h, --help Displays this help message
EOF
}
case $1 in
-i|--install)
2020-12-31 16:16:31 +00:00
checkdep update-desktop-database
2020-12-15 07:11:47 +00:00
install_desktop ${@:2}
2020-12-31 16:16:31 +00:00
update-desktop-database
exit $?
;;
2020-12-16 07:42:26 +00:00
-r|--remove)
2020-12-31 16:16:31 +00:00
checkdep update-desktop-database
selected_entry=${@:2}
for i in $selected_entry; do
rm ~/.local/share/applications/archbox/$i
done
update-desktop-database
exit $?
;;
2020-12-15 07:11:47 +00:00
-h|--help)
help_text
2020-12-31 16:16:31 +00:00
exit 0
;;
2020-12-16 07:42:26 +00:00
-l|--list)
archbox ls -1 --color=none /usr/share/applications
2020-12-31 16:16:31 +00:00
exit $?
;;
2020-12-16 07:42:26 +00:00
-s|--list-installed)
ls -1 --color=none ~/.local/share/applications/archbox
2020-12-31 16:16:31 +00:00
exit $?
;;
2020-12-15 07:11:47 +00:00
*)
2020-12-15 07:18:45 +00:00
checkdep zenity
2020-12-15 07:28:17 +00:00
checkdep sed
2020-12-31 16:16:31 +00:00
checkdep update-desktop-database
2020-12-16 07:42:26 +00:00
action="$(zenity --list --radiolist --title 'Archbox Desktop Manager' \
--height=200 --width=450 --column 'Select' --column 'Action' \
--text 'What do you want to do?' \
FALSE 'Install desktop entries' FALSE 'Remove desktop entries')"
case $action in
'Install desktop entries')
list_desktop="$(archbox ls --color=none -1 /usr/share/applications)"
zenity_entry="$(echo $list_desktop | sed 's/\ /\ FALSE\ /g')"
selected_entry=$(zenity --list --checklist --height=500 --width=450 \
2020-12-31 16:16:31 +00:00
--title="Archbox Desktop Manager" \
--text "Select .desktop entries those you want to install" \
--column "Select" --column "Applications" \
FALSE $zenity_entry | sed 's/|/\ /g')
2020-12-16 07:42:26 +00:00
[[ -z $selected_entry ]] && exit 1
install_desktop $selected_entry
2020-12-31 16:16:31 +00:00
update-desktop-database
2020-12-16 07:42:26 +00:00
exit 0
2020-12-31 16:16:31 +00:00
;;
2020-12-16 07:42:26 +00:00
'Remove desktop entries')
list_desktop="$(ls --color=none -1 ~/.local/share/applications/archbox)"
[[ -z $list_desktop ]] && zenity --info --title "Archbox Desktop Manager" \
--text "No .desktop files installed" --width=300 && exit 1
zenity_entry="$(echo $list_desktop | sed 's/\ /\ FALSE\ /g')"
selected_entry=$(zenity --list --checklist --height=500 --width=450 \
--title="Archbox Desktop Manager" \
--text "Select .desktop entries those you want to remove" \
--column "Select" --column "Applications" \
2020-12-19 08:14:23 +00:00
FALSE $zenity_entry | sed 's/|/\ /g')
2020-12-16 07:42:26 +00:00
[[ -z $selected_entry ]] && exit 1
2020-12-31 16:16:31 +00:00
for i in $selected_entry; do
rm ~/.local/share/applications/archbox/$i
done
update-desktop-database
2020-12-16 07:42:26 +00:00
exit $?
2020-12-31 16:16:31 +00:00
;;
2020-12-16 07:42:26 +00:00
esac
exit 1
2020-12-15 07:11:47 +00:00
;;
2020-12-19 08:14:23 +00:00
esac