diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | booksplit | 2 | ||||
-rwxr-xr-x | dmenumount | 23 | ||||
-rwxr-xr-x | dmenuumount | 16 | ||||
-rwxr-xr-x | doppler | 2 | ||||
-rwxr-xr-x | install.sh | 38 | ||||
-rwxr-xr-x | mailsync | 17 | ||||
-rwxr-xr-x | rofi-power-menu | 280 | ||||
-rwxr-xr-x | s6-db-update | 31 | ||||
-rwxr-xr-x | s6-user-update | 31 | ||||
-rwxr-xr-x | slider | 4 | ||||
-rwxr-xr-x | us6c | 31 |
12 files changed, 447 insertions, 29 deletions
@@ -4,6 +4,7 @@ generics/ scripts/ shortcmds/ sp/ +volsv/ # other directories flatpak-sc/ @@ -28,7 +28,7 @@ ext="mp3" #ext="${1#*.}" # Get the total number of tracks from the number of lines. -total="$(wc -l < "$2")" +#total="$(wc -l < "$2")" while read -r x; do @@ -8,27 +8,34 @@ # input a novel directory, it will prompt you to create that directory. printhelp () { + printf "dmenumount: dmenu prompt to mount drives or android phones\n" + printf "dmenumount [-d X]\n" + printf "\t-d X) pass X as an arg to dmenu\n" exit } while getopts "hd:" o; do case "${o}" in - d) ARGS="$ARGS$OPTARG " ;; + d) ARG=${ARG:+"$ARG "}"$OPTARG" ;; *) printhelp ;; esac done +dmenu_lp () { + dmenu -l 15 -p "$@" +} + getmount() { \ [ -z "$chosen" ] && exit 1 # shellcheck disable=SC2086 - mp="$(find $1 2>/dev/null | dmenu -l 15 -p "Type in mount point." $ARGS)" || exit 1 + mp="$(find $1 2>/dev/null | dmenu_lp "Type in mount point." ${ARG:+"$ARG"})" || exit 1 test -z "$mp" && exit 1 if [ ! -d "$mp" ]; then - mkdiryn=$(printf "No\\nYes" | dmenu -l 15 -p "$mp does not exist. Create it?" $ARGS) || exit 1 + mkdiryn=$(printf "No\\nYes" | dmenu_lp "$mp does not exist. Create it?" ${ARG:+"$ARG"}) || exit 1 [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo mkdir -p "$mp") fi } mountusb() { \ - chosen="$(echo "$usbdrives" | dmenu -l 15 -p "Mount which drive?" $ARGS)" || exit 1 + chosen="$(echo "$usbdrives" | dmenu_lp "Mount which drive?" ${ARG:+"$ARG"})" || exit 1 chosen="$(echo "$chosen" | awk '{print $1}')" echo "$chosen" sudo mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0 @@ -44,17 +51,17 @@ mountusb() { \ } mountandroid() { \ - chosen="$(echo "$anddrives" | dmenu -l 15 -p "Which Android device?" $ARGS)" || exit 1 + chosen="$(echo "$anddrives" | dmenu_lp "Which Android device?" ${ARG:+"$ARG"})" || exit 1 chosen="$(echo "$chosen" | cut -d : -f 1)" getmount "$HOME -maxdepth 3 -type d" simple-mtpfs --device "$chosen" "$mp" - echo "OK" | dmenu -l 15 -p "Tap Allow on your phone if it asks for permission and then press enter" $ARGS || exit 1 + echo "OK" | dmenu_lp "Tap Allow on your phone if it asks for permission and then press enter" ${ARG:+"$ARG"} || exit 1 simple-mtpfs --device "$chosen" "$mp" notify-send "🤖 Android Mounting" "Android device mounted to $mp." } asktype() { \ - choice="$(printf "USB\\nAndroid" | dmenu -l 15 -p "Mount a USB drive or Android device?" $ARGS)" || exit 1 + choice="$(printf "USB\\nAndroid" | dmenu_lp "Mount a USB drive or Android device?" ${ARG:+"$ARG"})" || exit 1 case $choice in USB) mountusb ;; Android) mountandroid ;; @@ -66,7 +73,7 @@ alldrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom\|crypt' | for i in $alldrives; do echo "$i" | grep -qi '([0-9.]*[mgt])' && continue - if ! `blkid $i | grep -q 'crypto_LUKS'`; then + if ! blkid "$i" | grep -q 'crypto_LUKS'; then usbdrives="$(echo "$alldrives" | grep "$i")\n$usbdrives" fi done diff --git a/dmenuumount b/dmenuumount index 59383f1..877bae0 100755 --- a/dmenuumount +++ b/dmenuumount @@ -7,33 +7,37 @@ # Drives mounted at /, /boot and /home will not be options to unmount. printhelp () { + printf "dmenuumount: dmenu prompt to unmount drives\n" + printf "dmenuumount [-d X]\n" + printf "\t-d X) pass X as an arg to dmenu\n" exit } while getopts "hd:" o; do case "${o}" in - d) ARGS="$ARGS$OPTARG " ;; + d) ARG=${ARG:+"$ARG "}"$OPTARG" ;; *) printhelp ;; esac done -DMENU="dmenu" -DEFARGS="-l 15 -p" +dmenu_lp () { + dmenu -l 15 -p "$@" +} unmountusb() { [ -z "$drives" ] && exit - chosen="$(echo "$drives" | $DMENU $DEFARGS "Unmount which drive?" $ARGS)" || exit 1 + chosen="$(echo "$drives" | dmenu_lp "Unmount which drive?" ${ARG:+"$ARG"})" || exit 1 chosen="$(echo "$chosen" | awk '{print $1}')" [ -z "$chosen" ] && exit sudo umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted." } unmountandroid() { \ - chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | $DMENU $DEFARGS "Unmount which device?" $ARGS )" || exit 1 + chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu_lp "Unmount which device?" ${ARG:+"$ARG"} )" || exit 1 [ -z "$chosen" ] && exit sudo umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted." } asktype() { \ - choice="$(printf "USB\\nAndroid" | $DMENU $DEFARGS "Unmount a USB drive or Android device?" $ARGS)" || exit 1 + choice="$(printf "USB\\nAndroid" | dmenu_lp "Unmount a USB drive or Android device?" ${ARG:+"$ARG"})" || exit 1 case "$choice" in USB) unmountusb ;; Android) unmountandroid ;; @@ -5,7 +5,7 @@ # Show a Doppler RADAR of a user's preferred location. -secs=600 # Download a new doppler radar if one hasn't been downloaded in $secs seconds. +#secs=600 # Download a new doppler radar if one hasn't been downloaded in $secs seconds. radarloc="${XDG_CACHE_HOME:-$HOME/.cache}/radar" doppler="${XDG_CACHE_HOME:-$HOME/.cache}/doppler.gif" @@ -7,22 +7,28 @@ SSH_BASE_URL="git@git.zachir.xyz:zachir/" HTTP_BASE_URL="https://git.zachir.xyz/" SCRIPT_DIRS="$(cat << 'EOF' +blocks generics scripts shortcmds sp +volsv EOF )" +UPDATE="" + printhelp () { printf "install.sh | Used to add my other script repos as submodules. Feel free to modfy it to clone yours as well.\n" printf " -s) clone repos using ssh\n" printf " -S) clone repos using https\n" printf " -h) prints this help message\n" printf " -u X ) will clone using X as the URL\n" + printf " -U) updates the repos rather than clones\n" + exit ${1:-1} } -while getopts "cdhsSu:" o; do case "${o}" in +while getopts "cdhsSu:U" o; do case "${o}" in c) unset SCRIPT_DIRS ;; d) [ -n "$SCRIPT_DIRS" ] && SCRIPT_DIRS="$SCRIPT_DIRS\n$OPTARG" @@ -30,10 +36,28 @@ while getopts "cdhsSu:" o; do case "${o}" in ;; s) ___USE_SSH=y ;; S) unset ___USE_SSH ;; - u) URL="$OPTARG" ;; + u) + SSH_BASE_URL="$OPTARG" + HTTP_BASE_URL="$OPTARG" + ;; + U) UPDATE="y" ;; + h) printhelp 0 ;; *) printhelp ;; esac done +update_dir () { + if [ ! -d "$1" ]; then + printf "%s does not exist; please clone first.\n" "$1" + elif [ -f "$1" ]; then + printf "%s already exists, but not as a dir; cannot update.\n" "$1" + else + printf "Updating %s...\n" "$1" + cd "$1" + git pull + cd .. + fi +} + clone_dir () { if [ -d "$1" ]; then printf "%s already exists as dir; not adding.\n" "$1" @@ -41,7 +65,7 @@ clone_dir () { printf "%s already exists, but not as a dir; not adding.\n" "$1" else if [ -n "$2" ]; then - printf "Cloning %s %s using ssh; will be read-write\nNote: only my ssh key will clone it\n" "$1" + printf "Cloning %s using ssh; will be read-write\nNote: only my ssh key will clone it\n" "$1" git clone "$SSH_BASE_URL$1.git" "$1" else printf "Cloning %s using http; will be read-only\n" "$1" @@ -50,7 +74,11 @@ clone_dir () { fi } -echo "$SCRIPT_DIRS" | while read i; do +echo "$SCRIPT_DIRS" | while read -r i; do [ -z "$i" ] && continue - clone_dir "$i" "$___USE_SSH" + if [ "$UPDATE" = "y" ]; then + update_dir "$i" + else + clone_dir "$i" "$___USE_SSH" + fi done @@ -28,9 +28,10 @@ eval "$(grep -h -- \ "$HOME/.config/zsh/.zshenv" "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.config/zsh/.zshrc" \ "$HOME/.pam_environment" 2>/dev/null)" -export GPG_TTY="$(tty)" +GPG_TTY="$(tty)" +export GPG_TTY -[ -n "$MBSYNCRC" ] && alias mbsync="mbsync -c $MBSYNCRC" || MBSYNCRC="$HOME/.config/isync/mbsyncrc" +[ -n "$MBSYNCRC" ] && alias mbsync='mbsync -c $MBSYNCRC' || MBSYNCRC="$HOME/.config/isync/mbsyncrc" # Settings are different for MacOS (Darwin) systems. case "$(uname)" in @@ -39,13 +40,16 @@ case "$(uname)" in ;; *) case "$(readlink -f /sbin/init)" in - *systemd*|*openrc*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;; + *systemd*|*openrc*) + DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus + export DBUS_SESSION_BUS_ADDRESS + ;; esac # remember if a display server is running since `ps` doesn't always contain a display pgrepoutput="$(pgrep -a X\(org\|wayland\))" displays="$(echo "$pgrepoutput" | grep -wo "[0-9]*:[0-9]\+" | sort -u)" notify() { [ -n "$pgrepoutput" ] && for x in ${displays:-0:}; do - export DISPLAY=$x + export DISPLAY="$x" notify-send --app-name="mutt-wizard" "New mail!" "📬 $2 new mail(s) in \`$1\` account." done ;} ;; @@ -64,7 +68,8 @@ syncandnotify() { "$HOME/.local/share/mail/$acc/inbox/cur/"\ -type f -newer "${XDG_CONFIG_HOME:-$HOME/.config}/mutt/.mailsynclastrun" 2> /dev/null) newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) - case 1 in + one="1" + case "$one" in $((newcount > 0)) ) notify "$acc" "$newcount" ;; esac } @@ -74,7 +79,7 @@ if [ "$#" -eq "0" ]; then accounts="$(awk '/^Channel/ {print $2}' "$MBSYNCRC")" else for arg in "$@"; do - [ "${arg%${arg#?}}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1 + [ "${arg%"${arg#?}"}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1 done accounts=$* fi diff --git a/rofi-power-menu b/rofi-power-menu new file mode 100755 index 0000000..0a8fda4 --- /dev/null +++ b/rofi-power-menu @@ -0,0 +1,280 @@ +#!/usr/bin/env bash + +# This script defines just a mode for rofi instead of being a self-contained +# executable that launches rofi by itself. This makes it more flexible than +# running rofi inside this script as now the user can call rofi as one pleases. +# For instance: +# +# rofi -show powermenu -modi powermenu:./rofi-power-menu +# +# See README.md for more information. + +set -e +set -u + +# All supported choices +all=(shutdown reboot suspend hibernate logout lockscreen) + +# By default, show all (i.e., just copy the array) +show=("${all[@]}") + +declare -A texts +texts[lockscreen]="lock screen" +texts[switchuser]="switch user" +texts[logout]="log out" +texts[suspend]="suspend" +texts[hibernate]="hibernate" +texts[reboot]="reboot" +texts[shutdown]="shut down" + +declare -A icons +icons[lockscreen]="\Uf033e" +icons[switchuser]="\Uf0019" +icons[logout]="\Uf0343" +icons[suspend]="\Uf04b2" +icons[hibernate]="\Uf02ca" +icons[reboot]="\Uf0709" +icons[shutdown]="\Uf0425" +icons[cancel]="\Uf0156" + +declare -A actions +actions[lockscreen]="loginctl lock-session ${XDG_SESSION_ID-}" +#actions[switchuser]="???" +actions[logout]="loginctl terminate-session ${XDG_SESSION_ID-}" +actions[suspend]="loginctl suspend" +actions[hibernate]="loginctl hibernate" +actions[reboot]="loginctl reboot" +actions[shutdown]="loginctl poweroff" + +# By default, ask for confirmation for actions that are irreversible +confirmations=(reboot shutdown logout) + +# By default, no dry run +dryrun=false +showsymbols=true +showtext=true + +function check_valid { + option="$1" + shift 1 + for entry in "${@}" + do + if [ -z "${actions[$entry]+x}" ] + then + echo "Invalid choice in $1: $entry" >&2 + exit 1 + fi + done +} + +# Parse command-line options +parsed=$(getopt --options=h --longoptions=help,dry-run,confirm:,choices:,choose:,symbols,no-symbols,text,no-text,symbols-font: --name "$0" -- "$@") +if [ $? -ne 0 ]; then + echo 'Terminating...' >&2 + exit 1 +fi +eval set -- "$parsed" +unset parsed +while true; do + case "$1" in + "-h"|"--help") + echo "rofi-power-menu - a power menu mode for Rofi" + echo + echo "Usage: rofi-power-menu [--choices CHOICES] [--confirm CHOICES]" + echo " [--choose CHOICE] [--dry-run] [--symbols|--no-symbols]" + echo + echo "Use with Rofi in script mode. For instance, to ask for shutdown or reboot:" + echo + echo " rofi -show menu -modi \"menu:rofi-power-menu --choices=shutdown/reboot\"" + echo + echo "Available options:" + echo " --dry-run Don't perform the selected action but print it to stderr." + echo " --choices CHOICES Show only the selected choices in the given order. Use /" + echo " as the separator. Available choices are lockscreen," + echo " logout,suspend, hibernate, reboot and shutdown. By" + echo " default, all available choices are shown." + echo " --confirm CHOICES Require confirmation for the gives choices only. Use / as" + echo " the separator. Available choices are lockscreen, logout," + echo " suspend, hibernate, reboot and shutdown. By default, only" + echo " irreversible actions logout, reboot and shutdown require" + echo " confirmation." + echo " --choose CHOICE Preselect the given choice and only ask for a" + echo " confirmation (if confirmation is set to be requested). It" + echo " is strongly recommended to combine this option with" + echo " --confirm=CHOICE if the choice wouldn't require" + echo " confirmation by default. Available choices are" + echo " lockscreen, logout, suspend, hibernate, reboot and" + echo " shutdown." + echo " --[no-]symbols Show Unicode symbols or not. Requires a font with support" + echo " for the symbols. Use, for instance, fonts from the" + echo " Nerdfonts collection. By default, they are shown" + echo " --[no-]text Show text description or not." + echo " --symbols-font FONT Use the given font for symbols. By default, the symbols" + echo " use the same font as the text. That font is configured" + echo " with rofi." + echo " -h,--help Show this help text." + exit 0 + ;; + "--dry-run") + dryrun=true + shift 1 + ;; + "--confirm") + IFS='/' read -ra confirmations <<< "$2" + check_valid "$1" "${confirmations[@]}" + shift 2 + ;; + "--choices") + IFS='/' read -ra show <<< "$2" + check_valid "$1" "${show[@]}" + shift 2 + ;; + "--choose") + # Check that the choice is valid + check_valid "$1" "$2" + selectionID="$2" + shift 2 + ;; + "--symbols") + showsymbols=true + shift 1 + ;; + "--no-symbols") + showsymbols=false + shift 1 + ;; + "--text") + showtext=true + shift 1 + ;; + "--no-text") + showtext=false + shift 1 + ;; + "--symbols-font") + symbols_font="$2" + shift 2 + ;; + "--") + shift + break + ;; + *) + echo "Internal error" >&2 + exit 1 + ;; + esac +done + +if [ "$showsymbols" = "false" -a "$showtext" = "false" ] +then + echo "Invalid options: cannot have --no-symbols and --no-text enabled at the same time." >&2 + exit 1 +fi + +# Define the messages after parsing the CLI options so that it is possible to +# configure them in the future. + +function write_message { + if [ -z ${symbols_font+x} ]; + then + icon="<span font_size=\"medium\">$1</span>" + else + icon="<span font=\"${symbols_font}\" font_size=\"medium\">$1</span>" + fi + text="<span font_size=\"medium\">$2</span>" + if [ "$showsymbols" = "true" ] + then + if [ "$showtext" = "true" ] + then + echo -n "\u200e$icon \u2068$text\u2069" + else + echo -n "\u200e$icon" + fi + else + echo -n "$text" + fi +} + +function print_selection { + echo -e "$1" | $(read -r -d '' entry; echo "echo $entry") +} + +declare -A messages +declare -A confirmationMessages +for entry in "${all[@]}" +do + messages[$entry]=$(write_message "${icons[$entry]}" "${texts[$entry]^}") +done +for entry in "${all[@]}" +do + confirmationMessages[$entry]=$(write_message "${icons[$entry]}" "Yes, ${texts[$entry]}") +done +confirmationMessages[cancel]=$(write_message "${icons[cancel]}" "No, cancel") + +if [ $# -gt 0 ] +then + # If arguments given, use those as the selection + selection="${@}" +else + # Otherwise, use the CLI passed choice if given + if [ -n "${selectionID+x}" ] + then + selection="${messages[$selectionID]}" + fi +fi + +# Don't allow custom entries +echo -e "\0no-custom\x1ftrue" +# Use markup +echo -e "\0markup-rows\x1ftrue" + +if [ -z "${selection+x}" ] +then + echo -e "\0prompt\x1fPower menu" + for entry in "${show[@]}" + do + echo -e "${messages[$entry]}\0icon\x1f${icons[$entry]}" + done +else + for entry in "${show[@]}" + do + if [ "$selection" = "$(print_selection "${messages[$entry]}")" ] + then + # Check if the selected entry is listed in confirmation requirements + for confirmation in "${confirmations[@]}" + do + if [ "$entry" = "$confirmation" ] + then + # Ask for confirmation + echo -e "\0prompt\x1fAre you sure" + echo -e "${confirmationMessages[$entry]}\0icon\x1f${icons[$entry]}" + echo -e "${confirmationMessages[cancel]}\0icon\x1f${icons[cancel]}" + exit 0 + fi + done + # If not, then no confirmation is required, so mark confirmed + selection=$(print_selection "${confirmationMessages[$entry]}") + fi + if [ "$selection" = "$(print_selection "${confirmationMessages[$entry]}")" ] + then + if [ $dryrun = true ] + then + # Tell what would have been done + echo "Selected: $entry" >&2 + else + # Perform the action + ${actions[$entry]} + fi + exit 0 + fi + if [ "$selection" = "$(print_selection "${confirmationMessages[cancel]}")" ] + then + # Do nothing + exit 0 + fi + done + # The selection didn't match anything, so raise an error + echo "Invalid selection: $selection" >&2 + exit 1 +fi diff --git a/s6-db-update b/s6-db-update new file mode 100755 index 0000000..0b55077 --- /dev/null +++ b/s6-db-update @@ -0,0 +1,31 @@ +#!/bin/sh + +DATAPATH="/home/${USER}/.local/share/s6" +RCPATH="${DATAPATH}/rc" +DBPATH="${RCPATH}/compiled" +SVPATH="${DATAPATH}/sv" +SVDIRS="/run/${USER}/s6-rc/servicedirs" +TIMESTAMP=$(date +%s) + +if ! s6-rc-compile "${DBPATH}"-"${TIMESTAMP}" "${SVPATH}"; then + echo "Error compiling database. Please double check the ${SVPATH} directories." + exit 1 +fi + +if [ -e "/run/${USER}/s6-rc" ]; then + for dir in "${SVDIRS}"/*; do + if [ -e "${dir}/down" ]; then + s6-svc -x "${dir}" + fi + done + s6-rc-update -l "/run/${USER}/s6-rc" "${DBPATH}"-"${TIMESTAMP}" +fi + +if [ -d "${DBPATH}" ]; then + ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}"/compiled && mv -f "${DBPATH}"/compiled "${RCPATH}" +else + ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}" +fi + +echo "==> Switched to a new database for ${USER}." +echo " Remove any old unwanted/unneeded database directories in ${RCPATH}." diff --git a/s6-user-update b/s6-user-update new file mode 100755 index 0000000..0b55077 --- /dev/null +++ b/s6-user-update @@ -0,0 +1,31 @@ +#!/bin/sh + +DATAPATH="/home/${USER}/.local/share/s6" +RCPATH="${DATAPATH}/rc" +DBPATH="${RCPATH}/compiled" +SVPATH="${DATAPATH}/sv" +SVDIRS="/run/${USER}/s6-rc/servicedirs" +TIMESTAMP=$(date +%s) + +if ! s6-rc-compile "${DBPATH}"-"${TIMESTAMP}" "${SVPATH}"; then + echo "Error compiling database. Please double check the ${SVPATH} directories." + exit 1 +fi + +if [ -e "/run/${USER}/s6-rc" ]; then + for dir in "${SVDIRS}"/*; do + if [ -e "${dir}/down" ]; then + s6-svc -x "${dir}" + fi + done + s6-rc-update -l "/run/${USER}/s6-rc" "${DBPATH}"-"${TIMESTAMP}" +fi + +if [ -d "${DBPATH}" ]; then + ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}"/compiled && mv -f "${DBPATH}"/compiled "${RCPATH}" +else + ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}" +fi + +echo "==> Switched to a new database for ${USER}." +echo " Remove any old unwanted/unneeded database directories in ${RCPATH}." @@ -10,7 +10,7 @@ # Application cache if not stated elsewhere. cache="${XDG_CACHE_HOME:-$HOME/.cache}/slider" -while getopts "hvrpi:c:a:o:d:f:t:e:x:" o; do case "${o}" in +while getopts "hvrpi:c:a:o:d:f:t:e:x:s:" o; do case "${o}" in c) bgc="$OPTARG" ;; t) fgc="$OPTARG" ;; i) file="$OPTARG" ;; @@ -65,7 +65,7 @@ if [ -n "${audio+x}" ]; then audio/*) ;; *) echo "That doesn't look like an audio file."; exit 1 ;; esac - totseconds="$(date '+%s' -d $(ffmpeg -i "$audio" 2>&1 | awk '/Duration/ {print $2}' | sed s/,//))" + totseconds="$(date '+%s' -d "$(ffmpeg -i "$audio" 2>&1 | awk '/Duration/ {print $2}' | sed s/,//)")" endtime="$((totseconds-seconds))" fi @@ -0,0 +1,31 @@ +#!/bin/sh + +DATAPATH="/home/${USER}/.local/share/s6" +RCPATH="${DATAPATH}/rc" +DBPATH="${RCPATH}/compiled" +SVPATH="${DATAPATH}/sv" +SVDIRS="/run/${USER}/s6-rc/servicedirs" +TIMESTAMP=$(date +%s) + +if ! s6-rc-compile "${DBPATH}"-"${TIMESTAMP}" "${SVPATH}"; then + echo "Error compiling database. Please double check the ${SVPATH} directories." + exit 1 +fi + +if [ -e "/run/${USER}/s6-rc" ]; then + for dir in "${SVDIRS}"/*; do + if [ -e "${dir}/down" ]; then + s6-svc -x "${dir}" + fi + done + s6-rc-update -l "/run/${USER}/s6-rc" "${DBPATH}"-"${TIMESTAMP}" +fi + +if [ -d "${DBPATH}" ]; then + ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}"/compiled && mv -f "${DBPATH}"/compiled "${RCPATH}" +else + ln -sf "${DBPATH}"-"${TIMESTAMP}" "${DBPATH}" +fi + +echo "==> Switched to a new database for ${USER}." +echo " Remove any old unwanted/unneeded database directories in ${RCPATH}." |