pamac-url-handler-package/pamac-url-handler

35 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2019-08-22 19:38:31 +00:00
#!/usr/bin/env bash
# ALPM package URL handler
# x-alpm-package://packagename
# install: xdg-mime default pamac-url-handler.desktop x-scheme-handler/x-alpm-package
2024-07-13 19:42:49 +00:00
if [ $# != 1 ] || [[ "$1" != 'x-alpm-package://'* ]]; then
echo "Usage: $0 [URL]"
exit 1
2019-08-22 19:38:31 +00:00
fi
2024-07-13 19:42:49 +00:00
content="${1#x-alpm-package://}"
# AUR install
if [[ "$content" == 'aur//'* ]]; then
packagename="${content#aur//}"
pamac-installer --build "$packagename"
# Flatpak install
elif [[ "$content" == 'flatpak//'* ]]; then
appID="${content#flatpak//}"
info=$(flatpak remote-info flathub "$appID") || {
yad --image 'dialog-error' --title 'Alert' --buttons-layout=center --text-align=center --button=yad-close --borders=10 --text "Flatpak ID not found:\n$appID"
exit 1
}
yad --image 'dialog-question' --title 'Flatpak install' --button=Cancel:1 --button=Install:0 --text "$info" &&
exo-open --launch TerminalEmulator \
bash -c "flatpak install --assumeyes flathub $appID ; printf '\n'; read -n1 -rsp 'press any key to close window...'"
# Repo install
else
packagename=$content
pamac-installer "$packagename"
fi