2021-06-30 14:35:39 +00:00
#!/usr/bin/env bash
2021-08-07 12:48:15 +00:00
cmd_exists ( ) {
command -v " $1 " >/dev/null
}
2021-06-30 14:35:39 +00:00
echof( ) {
local colorReset = "\033[0m"
local prefix = " $1 "
local message = " $2 "
case " $prefix " in
header) msgpfx = "[\e[1;95mB\e[m]" color = "" ; ;
info) msgpfx = "[\e[1;97m=\e[m]" color = "\033[0;34m" ; ;
act) msgpfx = "[\e[1;92m*\e[m]" color = "" ; ;
ok) msgpfx = "[\e[1;93m+\e[m]" color = "\033[0;32m" ; ;
error) msgpfx = "[\e[1;91m!\e[m]" color = "\033[0;31m" ; ;
*) msgpfx = "" color = "" ; ;
esac
echo -e " $msgpfx $color $message $colorReset "
}
case $1 in
system)
BL_INSTALL_DIR = "/usr/local/bin"
; ;
user)
BL_INSTALL_DIR = " $HOME /.local/bin "
if [ [ ! -d $BL_INSTALL_DIR ] ] ; then
mkdir -p " $BL_INSTALL_DIR "
fi
; ;
*)
echo " Usage: $0 <install-mode> [<version>] [<systemd-service>] "
echo " <install-mode>: (string) 'user' installs to '~/.local/bin/', 'system' installs to '/usr/local/bin'"
2022-02-21 03:24:52 +00:00
echo " <version>: (string) defaults to local, which will install from the local copy of the repo. Use 'latest' which will determine the latest tag from git or specified branch/tag"
2021-06-30 14:35:39 +00:00
echo -e "\nPlease note: The order of the parameters *is* relevant, if you want to set '<system-service>' you need to specify '<version>' as well!"
exit 1
; ;
esac
echof header "Betterlockscreen-Setup"
if [ [ ! -w $BL_INSTALL_DIR ] ] ; then
echof error " Unable to write to ' $BL_INSTALL_DIR '! "
exit 1
fi
echof info "Checking system-requirements..."
declare -A DEPS
DEPS[ "ImageMagick" ] = "convert"
DEPS[ "i3lock-color" ] = "i3lock-color"
DEPS[ "xdpyinfo" ] = "xdpyinfo"
DEPS[ "xrdb" ] = "xrdb"
DEPS[ "xset" ] = "xset"
2021-08-07 12:48:15 +00:00
if ! cmd_exists DEPS[ "i3lock-color" ] && cmd_exists "i3lock" ; then
DEPS[ "i3lock-color" ] = "i3lock"
fi
2021-06-30 14:35:39 +00:00
for key in " ${ !DEPS[@] } " ; do
2021-08-07 12:48:15 +00:00
[ [ ! -e " $( command -v ${ DEPS [ $key ] } ) " ] ] && echof error " Missing ' $key ' under binary named ' ${ DEPS [ $key ] } '! " && exit 1
2021-06-30 14:35:39 +00:00
done
echof ok "done!"
VERSION = $2
2022-02-21 03:24:52 +00:00
if [ [ $VERSION = = "latest" ] ] ; then
2021-06-30 14:35:39 +00:00
echof info "Determinate latest release... "
VERSION = $( git describe --tags " $( git rev-list --tags --max-count= 1) " )
echof ok " done! ( $VERSION ) "
2022-02-21 03:24:52 +00:00
BLI_TEMP_DIR = $( mktemp -d)
2021-06-30 14:35:39 +00:00
2022-02-21 03:30:55 +00:00
git clone -b " $VERSION " https://github.com/GNUxeava/betterlockscreen " $BLI_TEMP_DIR " & >/dev/null
2022-02-21 03:24:52 +00:00
cd " $BLI_TEMP_DIR " || exit 1
fi
2021-06-30 14:35:39 +00:00
echof info " Installing Betterlockscreen to ' $BL_INSTALL_DIR '... "
cp betterlockscreen " $BL_INSTALL_DIR "
echof ok "done!"
if [ [ $PATH != *" $BL_INSTALL_DIR " * ] ] ; then
echof error "Please ensure to add 'export PATH=\"\$PATH:/home/\$USER/.local/bin\"' to your shell-config!\033[0m"
fi
echof ok "Install completed successfully!"
exit 0