Do most dependency checking during install instead of runtime

This commit is contained in:
Alexander Gehrke 2020-08-11 12:09:05 +02:00
parent f8d866b623
commit a2d794ea70
34 changed files with 74 additions and 27 deletions

View file

@ -1,6 +1,7 @@
#!/bin/zsh #!/bin/zsh
#dep:java
unset JAVA_HOME unset JAVA_HOME
source /etc/profile.d/11_oracle-jdk.sh source /etc/profile.d/10_openjdk11.sh
export IBUS_ENABLE_SYNC_MODE=1 export IBUS_ENABLE_SYNC_MODE=1
export XMODIFIERS="" export XMODIFIERS=""

View file

@ -3,7 +3,7 @@
source ${$(realpath "$0"):h}/lib/common.zsh source ${$(realpath "$0"):h}/lib/common.zsh
typeset -A interpreter_checked typeset -A interpreter_checked
have_interpreter() { have_dependency() {
if [[ ! $interpreter_checked[$1] ]]; then if [[ ! $interpreter_checked[$1] ]]; then
check "Checking for $1" check "Checking for $1"
if which $1 &> /dev/null; then if which $1 &> /dev/null; then
@ -22,6 +22,10 @@ uses_interpreter() {
head -n 1 $2 | grep -q $1 head -n 1 $2 | grep -q $1
} }
get_dependencies() {
sed -n '2{/^#dep:/{s/^#dep://;p;q}}' $1
}
if [[ -z $1 ]]; then if [[ -z $1 ]]; then
<<-HELP <<-HELP
Usage: $0 [-p PATH] <program_names> Usage: $0 [-p PATH] <program_names>
@ -38,11 +42,14 @@ else
fi fi
for prog in $@; do for prog in $@; do
for lang in zsh ruby python; do for lang in zsh ruby python amm; do
if uses_interpreter $lang $prog; then if uses_interpreter $lang $prog; then
have_interpreter $lang || exit 1 have_dependency $lang || exit 1
fi fi
done done
for dep in $(get_dependencies $prog); do
have_dependency $dep || exit 1
done
if [[ -e $install_path/${prog:t} && ! $force ]]; then if [[ -e $install_path/${prog:t} && ! $force ]]; then
warning "$prog already exists at $install_path. Skipping." warning "$prog already exists at $install_path. Skipping."
else else

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:at
time=$1; shift time=$1; shift
( (
echo "DISPLAY=$DISPLAY sm \"$@\"" | at $time echo "DISPLAY=$DISPLAY sm \"$@\"" | at $time

View file

@ -1,5 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:pgrep
if [[ $1 == "-u" ]]; then if [[ $1 == "-u" ]]; then
USER=$2 USER=$2
SUDO="sudo -u $USER" SUDO="sudo -u $USER"

View file

@ -1,5 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:mpc dmenu
dmenu_opts=("" "-i") dmenu_opts=("" "-i")
replace=("-r") replace=("-r")

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
#dep:scrot dmenu
require 'dmenu' require 'dmenu'

View file

@ -1,6 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:rofi
source ${$(realpath "$0"):h:h}/lib/common.zsh
emulate -L zsh emulate -L zsh
@ -9,13 +8,6 @@ CONFIG_PATH="$HOME/.config/dmsearch"
CACHE_PATH="$HOME/.cache/dmsearch" CACHE_PATH="$HOME/.cache/dmsearch"
mkdir -p "${CACHE_PATH}" mkdir -p "${CACHE_PATH}"
# required software
depend dmsearch \
rofi \
mv \
tail \
cut
################################################################################ ################################################################################
# helpers # helpers

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:udiskie-info dmenu
device=$(udiskie-info -a -o '{mount_path}' | grep -ve '^$' | dmenu -l 20) device=$(udiskie-info -a -o '{mount_path}' | grep -ve '^$' | dmenu -l 20)
if [[ -n "$device" ]]; then if [[ -n "$device" ]]; then
udiskie-umount $device udiskie-umount $device

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
#dep:xrandr
require 'xrandr' require 'xrandr'
require 'dmenu' require 'dmenu'

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:fd dmenu fzf
zparseopts -D -E h=help -help=help e+:=extension -extension+:=extension zparseopts -D -E h=help -help=help e+:=extension -extension+:=extension
if [[ -n "$help" ]]; then if [[ -n "$help" ]]; then

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:dos2unix iconv
for i in "$@"; do for i in "$@"; do
dos2unix $i &>/dev/null dos2unix $i &>/dev/null
iconv -fLATIN1 -tUTF8 $i | sponge $i iconv -fLATIN1 -tUTF8 $i | sponge $i

View file

@ -1,3 +0,0 @@
#!/bin/zsh
remote=${1:-origin}
git remote set-url $remote $(git remote get-url $remote | sed -e 's#https?://\([^/]*\)/#git@\1:#')

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:tmux alacritty
if [[ "${0:t}" == "guiterm" ]]; then if [[ "${0:t}" == "guiterm" ]]; then
<<-HELP <<-HELP

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:curl
# installs or updates to latest release of Proton build by GloriousEggroll # installs or updates to latest release of Proton build by GloriousEggroll
# saves installed versions in $STEAM_DIR/compatibilitytools.d/proton-ge-tags # saves installed versions in $STEAM_DIR/compatibilitytools.d/proton-ge-tags

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:mdcat iconv
MDCAT=/usr/bin/mdcat MDCAT=/usr/bin/mdcat
encoding=$(file -i "$1" | sed "s/.*charset=\(.*\)$/\1/") encoding=$(file -i "$1" | sed "s/.*charset=\(.*\)$/\1/")

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:perl notify-send
DEFAULT=raw DEFAULT=raw
ICON=/usr/share/icons/Adwaita/48x48/actions/mail-message-new.png ICON=/usr/share/icons/Adwaita/48x48/actions/mail-message-new.png

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:pass pwgen xclip
source ${$(realpath "$0"):h:h}/lib/common.zsh source ${$(realpath "$0"):h:h}/lib/common.zsh

View file

@ -1,3 +0,0 @@
#!/bin/zsh
source ${$(realpath "$0"):h:h}/lib

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:inkscape xmllint
for i in "$@"; do for i in "$@"; do
inkscape --without-gui --file=$i --export-plain-svg=/dev/stdout \ inkscape --without-gui --file=$i --export-plain-svg=/dev/stdout \
| tr -d '\n' \ | tr -d '\n' \

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:pueue jq column
JQ_PREDEF=' JQ_PREDEF='
def colors: def colors:

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:qrencode feh
if [[ -z "$1" ]]; then if [[ -z "$1" ]]; then
qrencode -s 40 -o - qrencode -s 40 -o -
else else

11
misc/selfip Executable file
View file

@ -0,0 +1,11 @@
#!/bin/zsh
#dep:jq ip
if [[ $1 == "-h" || $1 == "--help" ]]; then
echo "Usage: selfip [target address]"
echo
echo " Prints own address used to access the given address"
echo " Defaults to 8.8.8.8, which will show the IP of the"
echo " interface used to access the internet"
exit 0
fi
ip -json route get ${1:-8.8.8.8} | jq -r '.[0].prefsrc'

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:ssh rsync
file_id=$(head -c 12 /dev/urandom|base64| tr '/' '+') file_id=$(head -c 12 /dev/urandom|base64| tr '/' '+')
file_name=${2:-${1:t}} file_name=${2:-${1:t}}

23
misc/smapi-update Executable file
View file

@ -0,0 +1,23 @@
#!/bin/zsh
#dep:unzip wget
# installs or updates to latest release of SMAPI (Stardew Valley Modding API)
WORKDIR=$(mktemp -d)
cd $WORKDIR
echo $WORKDIR
pwd
latest_json=$(curl -s https://api.github.com/repos/Pathoschild/SMAPI/releases/latest)
download_url=$(jq -r <<<"$latest_json" '.assets[]|select(.name | contains("developer")|not)|.browser_download_url')
wget -O smapi.zip $download_url
unzip smapi.zip
cd SMAPI*
{ sleep 0.5; printf "2\n1\n"} | sh install\ on\ Linux.sh
cd /
rm -rf $WORKDIR

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:alacritty tmux mosh
if [[ "$1" == "-S" ]]; then if [[ "$1" == "-S" ]]; then
shift shift
server=${1}; server=${1};

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:tmux ifne fzf-tmux xdg-open
target=$(tmux capture-pane -e -p -J -S -20 \ target=$(tmux capture-pane -e -p -J -S -20 \
| grep -oP "(https?://|www\.)[^\"<>') \e]*" \ | grep -oP "(https?://|www\.)[^\"<>') \e]*" \
| ifne fzf-tmux --tac) | ifne fzf-tmux --tac)

View file

@ -1,5 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:fzf dmenu
# A simple wrapper around fzf and rofi, choosing based on if called from a terminal # A simple wrapper around fzf and rofi, choosing based on if called from a terminal
zparseopts -D -E i=ignorecase l:=rofi_lines p:=listprompt -prompt:=listprompt zparseopts -D -E i=ignorecase l:=rofi_lines p:=listprompt -prompt:=listprompt

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:slimlock
lockstate() { pidof slimlock &>/dev/null } lockstate() { pidof slimlock &>/dev/null }

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:fd fzf
source ${$(realpath "$0"):h:h}/lib/common.zsh source ${$(realpath "$0"):h:h}/lib/common.zsh

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:fd fzf
zparseopts -D -E -ext:=ext e:=ext h=help -help=help zparseopts -D -E -ext:=ext e:=ext h=help -help=help
if [[ -n $help ]]; then if [[ -n $help ]]; then

View file

@ -1,11 +1,8 @@
#!/bin/zsh #!/bin/zsh
#dep:chromium firejail
source ${$(realpath "$0"):h:h}/lib/common.zsh
profile="${0:t}" profile="${0:t}"
depend chromium firejail
mkdir -p $HOME/.jails/chromium-$profile mkdir -p $HOME/.jails/chromium-$profile
exec firejail --private=$HOME/.jails/chromium-$profile \ exec firejail --private=$HOME/.jails/chromium-$profile \

View file

@ -1,10 +1,10 @@
#!/bin/zsh #!/bin/zsh
#dep:xclip
# install this program with the name xc and symlink it as xs. # install this program with the name xc and symlink it as xs.
# xc will use the clipboard selection, while xs while use the primary selection # xc will use the clipboard selection, while xs while use the primary selection
source ${$(realpath "$0"):h:h}/lib/common.zsh source ${$(realpath "$0"):h:h}/lib/common.zsh
depend xclip
function get_primary() { xclip -o -selection primary } function get_primary() { xclip -o -selection primary }
function get_clipboard() { xclip -o -selection clipboard } function get_clipboard() { xclip -o -selection clipboard }

View file

@ -1,4 +1,5 @@
#!/bin/zsh #!/bin/zsh
#dep:xdg-mime
source ${$(realpath "$0"):h:h}/lib/common.zsh source ${$(realpath "$0"):h:h}/lib/common.zsh

View file

@ -1,2 +1,3 @@
#!/bin/zsh #!/bin/zsh
#dep:zenity
zenity --password --title="sudo password prompt" --timeout=10 zenity --password --title="sudo password prompt" --timeout=10