Add flatpak dependency handling

This commit is contained in:
Alexander Gehrke 2021-08-06 17:27:14 +02:00
parent 7ba3dba2bc
commit 8f10d90f2c
5 changed files with 42 additions and 7 deletions

1
flatpaks/.repos/flathub Normal file
View file

@ -0,0 +1 @@
https://flathub.org/repo/flathub.flatpakrepo

View file

@ -1,3 +1,4 @@
#!/bin/zsh #!/bin/zsh
#flatpak: flathub:com.discordapp.Discord
export $(dbus-launch) export $(dbus-launch)
exec flatpak run com.discordapp.Discord exec flatpak run com.discordapp.Discord

4
flatpaks/schildichat Executable file
View file

@ -0,0 +1,4 @@
#!/bin/zsh
#flatpak: flathub:chat.schildi.desktop
export $(dbus-launch)
exec flatpak run chat.schildi.desktop

View file

@ -24,7 +24,24 @@ uses_interpreter() {
} }
get_dependencies() { get_dependencies() {
sed -n '2{/^#dep:/{s/^#dep://;p;q}}' $1 sed -n '2,4{/^#dep:/{s/^#dep://;p;q}}' $1
}
get_flatpak_dependencies() {
sed -n '2,4{/^#flatpak:/{s/^#flatpak://;p;q}}' $1
}
have_flatpak() {
check "Checking for flatpak: $1"
flatpak info "$@" &> /dev/null
}
install_flatpak() {
if [[ ! -e flatpaks/.repos/$1 ]]; then
fail "Unknown flatpak repo: $1. Add its URL in flatpaks/.repos/$1"
else
flatpak --user remote-add --if-not-exists $1 $(<flatpaks/.repos/$1)
flatpak --user install $1 $2
fi
} }
if [[ -z $1 ]]; then if [[ -z $1 ]]; then
@ -35,12 +52,13 @@ if [[ -z $1 ]]; then
-f, --force overwrite existing files in the same dir -f, --force overwrite existing files in the same dir
-s, --skip when installing several scripts, skip scripts with unmet -s, --skip when installing several scripts, skip scripts with unmet
dependencies instead of aborting. dependencies instead of aborting.
--no-flatpak do not automatically install flatpak deps (still checks for them)
HELP HELP
exit 1 exit 1
fi fi
zparseopts -D -E p:=install_path -path:=install_path f=force -force=force \ zparseopts -D -E p:=install_path -path:=install_path f=force -force=force \
s=skip -skip=skip s=skip -skip=skip -no-flatpak=noflatpakinstall
if [[ ! $install_path ]]; then if [[ ! $install_path ]]; then
install_path=$HOME/.local/bin install_path=$HOME/.local/bin
@ -56,11 +74,20 @@ for prog in $@; do
done done
for dep in $(get_dependencies $prog); do for dep in $(get_dependencies $prog); do
if ! have_dependency $dep; then if ! have_dependency $dep; then
if [[ $skip ]]; then [[ $skip ]] && continue 2 || exit 1
continue 2 fi
else done
exit 1 for dep in $(get_flatpak_dependencies $prog); do
fi local repo=${dep%:*}
local pak=${dep#*:}
if have_flatpak $pak; then
succeed
elif [[ $noflatpakinstall ]]; then
fail "not installed and --no-flatpak given"
[[ $skip ]] && continue 2 || exit 1
else
info "missing. Installing now..."
install_flatpak $repo $pak
fi fi
done done
if [[ -e $install_path/${prog:t} && ! $force ]]; then if [[ -e $install_path/${prog:t} && ! $force ]]; then

View file

@ -3,6 +3,7 @@ autoload -Uz colors && colors
local c_fail="${fg_bold[red]}$reset_color" local c_fail="${fg_bold[red]}$reset_color"
local c_warn="${fg_bold[yellow]}$reset_color" local c_warn="${fg_bold[yellow]}$reset_color"
local c_success="${fg_bold[green]}$reset_color" local c_success="${fg_bold[green]}$reset_color"
local c_info="${fg_bold[green]}💡$reset_color"
check() { check() {
echo -n " ? $*" echo -n " ? $*"
@ -18,6 +19,7 @@ result() {
fail() { result $c_fail $@ } fail() { result $c_fail $@ }
warn() { result $c_warn $@ } warn() { result $c_warn $@ }
info() { result $c_info $@ }
succeed() { result $c_success $@ } succeed() { result $c_success $@ }
error() { echo -n " "; fail $@ } error() { echo -n " "; fail $@ }
warning() { echo -n " "; warn $@ } warning() { echo -n " "; warn $@ }