From a2d794ea7042c30d4096b5cbc274bd575d004f50 Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Tue, 11 Aug 2020 12:09:05 +0200 Subject: [PATCH] Do most dependency checking during install instead of runtime --- devel/idea | 3 ++- install.zsh | 13 ++++++++++--- misc/alert | 1 + misc/dbus-find | 2 +- misc/dmpc | 2 +- misc/dmscrot | 1 + misc/dmsearch | 10 +--------- misc/dmumount | 1 + misc/dmxrandr | 1 + misc/docopen | 1 + misc/fixenc | 1 + misc/git-http-to-git | 3 --- misc/guiterm | 1 + misc/install-proton-ge.zsh | 1 + misc/mdcat | 1 + misc/newmails | 1 + misc/newpass | 1 + misc/pathtest | 3 --- misc/pdftosvg | 1 + misc/pue | 1 + misc/qrshow | 1 + misc/selfip | 11 +++++++++++ misc/share | 1 + misc/smapi-update | 23 +++++++++++++++++++++++ misc/sweechat | 1 + misc/tmux-url-fuzz | 1 + misc/txmenu | 2 +- misc/unlock-track | 1 + misc/venv | 1 + misc/vf | 1 + misc/webapp | 5 +---- misc/xc | 2 +- misc/xdg-info | 1 + misc/zenity-askpass | 1 + 34 files changed, 74 insertions(+), 27 deletions(-) delete mode 100755 misc/git-http-to-git delete mode 100755 misc/pathtest create mode 100755 misc/selfip create mode 100755 misc/smapi-update diff --git a/devel/idea b/devel/idea index 71437ba..03c3550 100755 --- a/devel/idea +++ b/devel/idea @@ -1,6 +1,7 @@ #!/bin/zsh +#dep:java 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 XMODIFIERS="" diff --git a/install.zsh b/install.zsh index 380f5b7..611ac9c 100755 --- a/install.zsh +++ b/install.zsh @@ -3,7 +3,7 @@ source ${$(realpath "$0"):h}/lib/common.zsh typeset -A interpreter_checked -have_interpreter() { +have_dependency() { if [[ ! $interpreter_checked[$1] ]]; then check "Checking for $1… " if which $1 &> /dev/null; then @@ -22,6 +22,10 @@ uses_interpreter() { head -n 1 $2 | grep -q $1 } +get_dependencies() { + sed -n '2{/^#dep:/{s/^#dep://;p;q}}' $1 +} + if [[ -z $1 ]]; then <<-HELP Usage: $0 [-p PATH] @@ -38,11 +42,14 @@ else fi 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 - have_interpreter $lang || exit 1 + have_dependency $lang || exit 1 fi done + for dep in $(get_dependencies $prog); do + have_dependency $dep || exit 1 + done if [[ -e $install_path/${prog:t} && ! $force ]]; then warning "$prog already exists at $install_path. Skipping." else diff --git a/misc/alert b/misc/alert index 8247395..1988e1d 100755 --- a/misc/alert +++ b/misc/alert @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:at time=$1; shift ( echo "DISPLAY=$DISPLAY sm \"$@\"" | at $time diff --git a/misc/dbus-find b/misc/dbus-find index fa634e3..ee87840 100755 --- a/misc/dbus-find +++ b/misc/dbus-find @@ -1,5 +1,5 @@ #!/bin/zsh - +#dep:pgrep if [[ $1 == "-u" ]]; then USER=$2 SUDO="sudo -u $USER" diff --git a/misc/dmpc b/misc/dmpc index 1f33eb0..a862b7c 100755 --- a/misc/dmpc +++ b/misc/dmpc @@ -1,5 +1,5 @@ #!/bin/zsh - +#dep:mpc dmenu dmenu_opts=("" "-i") replace=("-r") diff --git a/misc/dmscrot b/misc/dmscrot index ae0299c..614ec4f 100755 --- a/misc/dmscrot +++ b/misc/dmscrot @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +#dep:scrot dmenu require 'dmenu' diff --git a/misc/dmsearch b/misc/dmsearch index de3c73a..1436845 100755 --- a/misc/dmsearch +++ b/misc/dmsearch @@ -1,6 +1,5 @@ #!/bin/zsh - -source ${$(realpath "$0"):h:h}/lib/common.zsh +#dep:rofi emulate -L zsh @@ -9,13 +8,6 @@ CONFIG_PATH="$HOME/.config/dmsearch" CACHE_PATH="$HOME/.cache/dmsearch" mkdir -p "${CACHE_PATH}" -# required software -depend dmsearch \ - rofi \ - mv \ - tail \ - cut - ################################################################################ # helpers diff --git a/misc/dmumount b/misc/dmumount index bd6c1ca..a1182e5 100755 --- a/misc/dmumount +++ b/misc/dmumount @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:udiskie-info dmenu device=$(udiskie-info -a -o '{mount_path}' | grep -ve '^$' | dmenu -l 20) if [[ -n "$device" ]]; then udiskie-umount $device diff --git a/misc/dmxrandr b/misc/dmxrandr index 6b9c6a4..4a7f4e7 100755 --- a/misc/dmxrandr +++ b/misc/dmxrandr @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +#dep:xrandr require 'xrandr' require 'dmenu' diff --git a/misc/docopen b/misc/docopen index a4b876c..d6f92a4 100755 --- a/misc/docopen +++ b/misc/docopen @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:fd dmenu fzf zparseopts -D -E h=help -help=help e+:=extension -extension+:=extension if [[ -n "$help" ]]; then diff --git a/misc/fixenc b/misc/fixenc index 5828004..fbd9cc5 100755 --- a/misc/fixenc +++ b/misc/fixenc @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:dos2unix iconv for i in "$@"; do dos2unix $i &>/dev/null iconv -fLATIN1 -tUTF8 $i | sponge $i diff --git a/misc/git-http-to-git b/misc/git-http-to-git deleted file mode 100755 index 7785293..0000000 --- a/misc/git-http-to-git +++ /dev/null @@ -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:#') diff --git a/misc/guiterm b/misc/guiterm index 5540c0d..9ac7c28 100755 --- a/misc/guiterm +++ b/misc/guiterm @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:tmux alacritty if [[ "${0:t}" == "guiterm" ]]; then <<-HELP diff --git a/misc/install-proton-ge.zsh b/misc/install-proton-ge.zsh index c167b9d..cae0def 100755 --- a/misc/install-proton-ge.zsh +++ b/misc/install-proton-ge.zsh @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:curl # installs or updates to latest release of Proton build by GloriousEggroll # saves installed versions in $STEAM_DIR/compatibilitytools.d/proton-ge-tags diff --git a/misc/mdcat b/misc/mdcat index a93f830..f244017 100755 --- a/misc/mdcat +++ b/misc/mdcat @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:mdcat iconv MDCAT=/usr/bin/mdcat encoding=$(file -i "$1" | sed "s/.*charset=\(.*\)$/\1/") diff --git a/misc/newmails b/misc/newmails index 340eead..0e32680 100755 --- a/misc/newmails +++ b/misc/newmails @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:perl notify-send DEFAULT=raw ICON=/usr/share/icons/Adwaita/48x48/actions/mail-message-new.png diff --git a/misc/newpass b/misc/newpass index aeabba2..46d15bf 100755 --- a/misc/newpass +++ b/misc/newpass @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:pass pwgen xclip source ${$(realpath "$0"):h:h}/lib/common.zsh diff --git a/misc/pathtest b/misc/pathtest deleted file mode 100755 index eaaa581..0000000 --- a/misc/pathtest +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/zsh - -source ${$(realpath "$0"):h:h}/lib diff --git a/misc/pdftosvg b/misc/pdftosvg index 5aeb7aa..bdaa928 100755 --- a/misc/pdftosvg +++ b/misc/pdftosvg @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:inkscape xmllint for i in "$@"; do inkscape --without-gui --file=$i --export-plain-svg=/dev/stdout \ | tr -d '\n' \ diff --git a/misc/pue b/misc/pue index 20bc3e9..7a71e09 100755 --- a/misc/pue +++ b/misc/pue @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:pueue jq column JQ_PREDEF=' def colors: diff --git a/misc/qrshow b/misc/qrshow index aacb5d0..78330cf 100755 --- a/misc/qrshow +++ b/misc/qrshow @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:qrencode feh if [[ -z "$1" ]]; then qrencode -s 40 -o - else diff --git a/misc/selfip b/misc/selfip new file mode 100755 index 0000000..4d337b5 --- /dev/null +++ b/misc/selfip @@ -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' diff --git a/misc/share b/misc/share index bcf4532..178e891 100755 --- a/misc/share +++ b/misc/share @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:ssh rsync file_id=$(head -c 12 /dev/urandom|base64| tr '/' '+') file_name=${2:-${1:t}} diff --git a/misc/smapi-update b/misc/smapi-update new file mode 100755 index 0000000..ad5c71f --- /dev/null +++ b/misc/smapi-update @@ -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 diff --git a/misc/sweechat b/misc/sweechat index 6daeda8..cbef248 100755 --- a/misc/sweechat +++ b/misc/sweechat @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:alacritty tmux mosh if [[ "$1" == "-S" ]]; then shift server=${1}; diff --git a/misc/tmux-url-fuzz b/misc/tmux-url-fuzz index 7432dc9..c3bedc1 100755 --- a/misc/tmux-url-fuzz +++ b/misc/tmux-url-fuzz @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:tmux ifne fzf-tmux xdg-open target=$(tmux capture-pane -e -p -J -S -20 \ | grep -oP "(https?://|www\.)[^\"<>') \e]*" \ | ifne fzf-tmux --tac) diff --git a/misc/txmenu b/misc/txmenu index 29a6cee..5fbd796 100755 --- a/misc/txmenu +++ b/misc/txmenu @@ -1,5 +1,5 @@ #!/bin/zsh - +#dep:fzf dmenu # 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 diff --git a/misc/unlock-track b/misc/unlock-track index b0385d6..b556f88 100755 --- a/misc/unlock-track +++ b/misc/unlock-track @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:slimlock lockstate() { pidof slimlock &>/dev/null } diff --git a/misc/venv b/misc/venv index e834f56..5e2dbbf 100755 --- a/misc/venv +++ b/misc/venv @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:fd fzf source ${$(realpath "$0"):h:h}/lib/common.zsh diff --git a/misc/vf b/misc/vf index b33d9ee..f6e62d5 100755 --- a/misc/vf +++ b/misc/vf @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:fd fzf zparseopts -D -E -ext:=ext e:=ext h=help -help=help if [[ -n $help ]]; then diff --git a/misc/webapp b/misc/webapp index 0754449..0cc04de 100755 --- a/misc/webapp +++ b/misc/webapp @@ -1,11 +1,8 @@ #!/bin/zsh - -source ${$(realpath "$0"):h:h}/lib/common.zsh +#dep:chromium firejail profile="${0:t}" -depend chromium firejail - mkdir -p $HOME/.jails/chromium-$profile exec firejail --private=$HOME/.jails/chromium-$profile \ diff --git a/misc/xc b/misc/xc index 62c576f..f72cbb8 100755 --- a/misc/xc +++ b/misc/xc @@ -1,10 +1,10 @@ #!/bin/zsh +#dep:xclip # 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 source ${$(realpath "$0"):h:h}/lib/common.zsh -depend xclip function get_primary() { xclip -o -selection primary } function get_clipboard() { xclip -o -selection clipboard } diff --git a/misc/xdg-info b/misc/xdg-info index 0d1fd7c..58e9930 100755 --- a/misc/xdg-info +++ b/misc/xdg-info @@ -1,4 +1,5 @@ #!/bin/zsh +#dep:xdg-mime source ${$(realpath "$0"):h:h}/lib/common.zsh diff --git a/misc/zenity-askpass b/misc/zenity-askpass index 59263e4..96188cf 100755 --- a/misc/zenity-askpass +++ b/misc/zenity-askpass @@ -1,2 +1,3 @@ #!/bin/zsh +#dep:zenity zenity --password --title="sudo password prompt" --timeout=10