From b49d6a4c3ac524d8b6f3a3522e27c3c0cc6d47d6 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Mon, 28 Oct 2024 20:37:23 +0100 Subject: [PATCH] Split repos --- .envrc | 2 - .forgejo/workflows/release.yaml | 31 +- .gitignore | 7 +- Makefile | 24 +- autostart-manage/bashly.yml | 111 - autostart-manage/before.sh | 11 - autostart-manage/completions_command.sh | 3 - autostart-manage/exec_command.sh | 6 - autostart-manage/info_command.sh | 9 - autostart-manage/lib/colors.sh | 42 - autostart-manage/lib/common.sh | 77 - autostart-manage/lib/systemd_files.sh | 26 - autostart-manage/list_command.sh | 3 - autostart-manage/log_command.sh | 3 - autostart-manage/run_command.sh | 3 - autostart-manage/run_wayland_command.sh | 5 - autostart-manage/run_xorg_command.sh | 12 - autostart-manage/sync_command.sh | 11 - autostart-manage/systemctl.sh | 9 - output/autostart-manage | 2220 +++++++++++++++++++ run.sh | 6 +- {autoinstall => src}/archive_command.sh | 0 {autoinstall => src}/bashly.yml | 2 +- {autoinstall => src}/before.sh | 0 {autoinstall => src}/completions_command.sh | 0 {autoinstall => src}/env_command.sh | 0 {autoinstall => src}/file_command.sh | 0 {autoinstall => src}/flatpak_command.sh | 0 {autoinstall => src}/git_command.sh | 0 {autoinstall => src}/lib/colors.sh | 0 {autoinstall => src}/lib/common.sh | 0 {autoinstall => src}/run_command.sh | 0 {autoinstall => src}/text_command.sh | 0 33 files changed, 2240 insertions(+), 383 deletions(-) delete mode 100644 autostart-manage/bashly.yml delete mode 100644 autostart-manage/before.sh delete mode 100644 autostart-manage/completions_command.sh delete mode 100644 autostart-manage/exec_command.sh delete mode 100644 autostart-manage/info_command.sh delete mode 100644 autostart-manage/lib/colors.sh delete mode 100644 autostart-manage/lib/common.sh delete mode 100644 autostart-manage/lib/systemd_files.sh delete mode 100644 autostart-manage/list_command.sh delete mode 100644 autostart-manage/log_command.sh delete mode 100644 autostart-manage/run_command.sh delete mode 100644 autostart-manage/run_wayland_command.sh delete mode 100644 autostart-manage/run_xorg_command.sh delete mode 100644 autostart-manage/sync_command.sh delete mode 100644 autostart-manage/systemctl.sh create mode 100755 output/autostart-manage rename {autoinstall => src}/archive_command.sh (100%) rename {autoinstall => src}/bashly.yml (99%) rename {autoinstall => src}/before.sh (100%) rename {autoinstall => src}/completions_command.sh (100%) rename {autoinstall => src}/env_command.sh (100%) rename {autoinstall => src}/file_command.sh (100%) rename {autoinstall => src}/flatpak_command.sh (100%) rename {autoinstall => src}/git_command.sh (100%) rename {autoinstall => src}/lib/colors.sh (100%) rename {autoinstall => src}/lib/common.sh (100%) rename {autoinstall => src}/run_command.sh (100%) rename {autoinstall => src}/text_command.sh (100%) diff --git a/.envrc b/.envrc index 4857c1e..1d953f4 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1 @@ use nix - -export BASHLY_SOURCE_DIR=$(cat .target) diff --git a/.forgejo/workflows/release.yaml b/.forgejo/workflows/release.yaml index a574329..59fe7cd 100644 --- a/.forgejo/workflows/release.yaml +++ b/.forgejo/workflows/release.yaml @@ -3,45 +3,30 @@ on: tags: - v** jobs: - build-artifacts: + release: runs-on: docker - strategy: - matrix: - tool: - - autoinstall - - autostart-manage steps: - uses: https://code.forgejo.org/actions/checkout@v3 - id: install-dependencies run: | apt update + # TODO add pandoc for docs apt install -y make ruby gem install bashly shell: bash - id: run-bashly run: | - echo "${{ matrix.tool }}" > .target make generate + #make docs shell: bash - - uses: https://code.forgejo.org/actions/upload-artifact@v3 - with: - name: ${{ matrix.tool }} - path: ${{ github.workspace }}/output/${{ matrix.tool }} - upload-release: - runs-on: docker - steps: - - uses: https://code.forgejo.org/actions/checkout@v3 - - uses: https://code.forgejo.org/actions/download-artifact@v3 - with: - path: /tmp/artifacts-in - merge-multiple: true # broken "collect-artifacts" used as workaround - - id: collect-artifacts + - id: prepare-release run: | - mkdir /tmp/artifacts-out - mv $(find /tmp/artifacts-in -type f) /tmp/artifacts-out + mkdir /tmp/release + cp ./autoinstall /tmp/release + #cp -r ./man1 /tmp/release shell: bash - uses: https://code.forgejo.org/actions/forgejo-release@v1 with: direction: upload - release-dir: /tmp/artifacts-out + release-dir: /tmp/release token: ${{ github.token }} diff --git a/.gitignore b/.gitignore index d45b622..20ab056 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -.target -output/ +src/lib/send_completions.sh -autoinstall/lib/send_completions.sh -autostart-manage/lib/send_completions.sh +autoinstall +man1 diff --git a/Makefile b/Makefile index 35835aa..5056f95 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,12 @@ -target: - @echo "Select target directory" - @echo $$(find . -name bashly.yml | sed -e 's/.\///' -e 's/\/.*//' | $$DMENU) > .target +completions: + bashly add completions -get-target: - $(eval TARGET := $(shell cat .target)) - -output-dir: - mkdir -p ./output - -completions: get-target - BASHLY_SOURCE_DIR=$(TARGET) bashly add completions - -generate: get-target output-dir completions - BASHLY_SOURCE_DIR=$(TARGET) bashly generate --upgrade +generate: completions + bashly generate --upgrade docs: generate - BASHLY_SOURCE_DIR=$(TARGET) bashly render :mandoc ./output/man1 + bashly render :mandoc ./man1 install: generate docs - cp -f ./output/$(TARGET) ~/.local/bin/ - cp -f ./output/man1/$(TARGET)*.1 ~/.local/share/man/man1/ + cp -f ./autoinstall ~/.local/bin/ + cp -f ./man1/autoinstall*.1 ~/.local/share/man/man1/ diff --git a/autostart-manage/bashly.yml b/autostart-manage/bashly.yml deleted file mode 100644 index 72f5d1a..0000000 --- a/autostart-manage/bashly.yml +++ /dev/null @@ -1,111 +0,0 @@ -name: autostart-manage -help: Manage autostart -version: 0.1.3 - -dependencies: - tomlq: please install yq (https://github.com/kislyuk/yq) - -environment_variables: -- name: HOSTNAME - help: The hostname to use. We will try to get the value automatically. - -commands: - - name: completions - help: Generate bash completions - - - name: list - help: List available programs - - name: info - help: Get the current status of all programs - - name: sync - help: Remove all programs from autostart and the re-enable all - args: - - name: groups - required: false - help: Extra groups to sync - - name: enable - help: Add a single program to autostart - args: - - name: program - required: true - help: Program to add to autostart - completions: - - $(autostart-manage list) - filename: systemctl.sh - - name: disable - help: Remove a single program from autostart - args: - - name: program - required: true - help: Program to add to autostart - completions: - - $(autostart-manage list) - filename: systemctl.sh - - name: restart - help: Restart programs from autostart - args: - - name: program - help: Program to add to autostart - default: "*" - completions: - - $(autostart-manage list) - filename: systemctl.sh - - name: start - help: Start programs from autostart - args: - - name: program - help: Program to start to autostart - default: "*" - completions: - - $(autostart-manage list) - filename: systemctl.sh - - name: status - help: Check status of programs from autostart - args: - - name: program - help: Program to check status on - default: "*" - completions: - - $(autostart-manage list) - filename: systemctl.sh - - name: stop - help: Stop programs from autostart - args: - - name: program - help: Program to stop - default: "*" - completions: - - $(autostart-manage list) - filename: systemctl.sh - - name: kill - help: Kill the program from autostart - args: - - name: program - required: true - help: Program to kill - completions: - - $(autostart-manage list) - filename: systemctl.sh - - name: log - alias: logs - help: Show the log for a single program from autostart - args: - - name: program - required: true - help: Program to log - completions: - - $(autostart-manage list) - - name: exec - help: Execute a single program from autostart - args: - - name: program - required: true - help: Program to execute - completions: - - $(autostart-manage list) - - name: run - help: Run all programs - - name: run-wayland - help: Run all the wayland specific tasks and all programs - - name: run-xorg - help: Run all the xorg specific tasks and all programs diff --git a/autostart-manage/before.sh b/autostart-manage/before.sh deleted file mode 100644 index b2e3c84..0000000 --- a/autostart-manage/before.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -service_file="$HOME/.config/systemd/user/autostart@.service" -if [ ! -f "$service_file" ]; then - _deploy_service_file "$service_file" -fi - -target_file="$HOME/.config/systemd/user/autostart.target" -if [ ! -f "$target_file" ]; then - _deploy_target_file "$target_file" -fi diff --git a/autostart-manage/completions_command.sh b/autostart-manage/completions_command.sh deleted file mode 100644 index 0d10993..0000000 --- a/autostart-manage/completions_command.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -send_completions diff --git a/autostart-manage/exec_command.sh b/autostart-manage/exec_command.sh deleted file mode 100644 index 2e2c816..0000000 --- a/autostart-manage/exec_command.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -program=${args[program]:?} - -sleep "$(_get_autostart_delay "$program")" -bash -c "$(_get_autostart_cmd "$program")" diff --git a/autostart-manage/info_command.sh b/autostart-manage/info_command.sh deleted file mode 100644 index 566cdce..0000000 --- a/autostart-manage/info_command.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -autostart_units=() -while IFS='' read -r line -do - autostart_units+=("$line") -done < <(_list "*") - -_echo_table "${autostart_units[@]}" | column -t -s$'\t' --table-columns 'Unit,Enabled?,Active?,Command' diff --git a/autostart-manage/lib/colors.sh b/autostart-manage/lib/colors.sh deleted file mode 100644 index cbdc015..0000000 --- a/autostart-manage/lib/colors.sh +++ /dev/null @@ -1,42 +0,0 @@ -## Color functions [@bashly-upgrade colors] -## This file is a part of Bashly standard library -## -## Usage: -## Use any of the functions below to color or format a portion of a string. -## -## echo "before $(red this is red) after" -## echo "before $(green_bold this is green_bold) after" -## -## Color output will be disabled if `NO_COLOR` environment variable is set -## in compliance with https://no-color.org/ -## -print_in_color() { - local color="$1" - shift - if [[ -z ${NO_COLOR+x} ]]; then - printf "$color%b\e[0m\n" "$*" - else - printf "%b\n" "$*" - fi -} - -red() { print_in_color "\e[31m" "$*"; } -green() { print_in_color "\e[32m" "$*"; } -yellow() { print_in_color "\e[33m" "$*"; } -blue() { print_in_color "\e[34m" "$*"; } -magenta() { print_in_color "\e[35m" "$*"; } -cyan() { print_in_color "\e[36m" "$*"; } -bold() { print_in_color "\e[1m" "$*"; } -underlined() { print_in_color "\e[4m" "$*"; } -red_bold() { print_in_color "\e[1;31m" "$*"; } -green_bold() { print_in_color "\e[1;32m" "$*"; } -yellow_bold() { print_in_color "\e[1;33m" "$*"; } -blue_bold() { print_in_color "\e[1;34m" "$*"; } -magenta_bold() { print_in_color "\e[1;35m" "$*"; } -cyan_bold() { print_in_color "\e[1;36m" "$*"; } -red_underlined() { print_in_color "\e[4;31m" "$*"; } -green_underlined() { print_in_color "\e[4;32m" "$*"; } -yellow_underlined() { print_in_color "\e[4;33m" "$*"; } -blue_underlined() { print_in_color "\e[4;34m" "$*"; } -magenta_underlined() { print_in_color "\e[4;35m" "$*"; } -cyan_underlined() { print_in_color "\e[4;36m" "$*"; } diff --git a/autostart-manage/lib/common.sh b/autostart-manage/lib/common.sh deleted file mode 100644 index 266c6e7..0000000 --- a/autostart-manage/lib/common.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash - -_systemctl () { - systemctl --user "${@:2}" "autostart@$1.service" -} - -_query_autostart_toml() { - groups_json=$(echo -n "$2" | tr "," "\n" | jq -R . | jq -s .) - tomlq -r \ - --arg host "$HOSTNAME" \ - --argjson extra_groups "$groups_json" \ - '.hosts[$host].groups as $groups | .apps | to_entries[] | select( - (.value.hosts | contains([$host])) or - ([.value.group] | inside($groups)) or - ([.value.group] | inside($extra_groups)) or - $extra_groups == ["*"] - ) | '"$1" \ - "$XDG_CONFIG_HOME/autostart.toml" -} - -_list () { - _query_autostart_toml '.value.alias // .key' "$1" -} - -_autostart_run_graphical () { - set +e - pass x # Try to unlock yubikey asap - - start-audio pipewire - wait-for-service "network-online.target" - - # Execute only if not already running - # Don't match keepassxc-proxy - if ! (pgrep -l keepassxc | grep -v prox) >/dev/null - then - if pass x - then - (pass keepass | head -n 1 | keepassxc --pw-stdin ~/sync/passwords.kdbx) & - fi - fi - - autoinstall run graphical - autostart-manage run -} - -_echo_table () { - for unit in "$@" - do - if [ "$(_systemctl "$unit" is-enabled)" = "enabled" ] - then - _enabled=$(green "enabled") - else - _enabled=$(red "disabled") - fi - - if _systemctl "$unit" is-active --quiet - then - _active=$(green "active") - else - _active=$(red "inactive") - fi - - printf "%s\t%s\t%s\t%s\n" \ - "$unit" \ - "$_enabled" \ - "$_active" \ - "$(_get_autostart_cmd "$unit")" - done -} - -_get_autostart_cmd () { - _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.command' "*" -} - -_get_autostart_delay () { - _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.delay // 0' "*" -} diff --git a/autostart-manage/lib/systemd_files.sh b/autostart-manage/lib/systemd_files.sh deleted file mode 100644 index d5eb682..0000000 --- a/autostart-manage/lib/systemd_files.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -_deploy_service_file() { - cat < "$1" -[Unit] -Description=Autostart several tools and services -StartLimitIntervalSec=120 -StartLimitBurst=10 - -[Service] -KillMode=process -ExecStart=/bin/sh -c ". \$HOME/.profile && autostart-manage exec '%i'" -Restart=on-failure -RestartSec=5s -EOF -} - -_deploy_target_file() { - cat < "$1" -[Unit] -Description=Current graphical user session -Documentation=man:systemd.special(7) -RefuseManualStart=no -StopWhenUnneeded=no -EOF -} diff --git a/autostart-manage/list_command.sh b/autostart-manage/list_command.sh deleted file mode 100644 index c732452..0000000 --- a/autostart-manage/list_command.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -_list "*" diff --git a/autostart-manage/log_command.sh b/autostart-manage/log_command.sh deleted file mode 100644 index 7d9657c..0000000 --- a/autostart-manage/log_command.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -journalctl --user -fu "autostart@${args[program]:?}.service" diff --git a/autostart-manage/run_command.sh b/autostart-manage/run_command.sh deleted file mode 100644 index 46fcb48..0000000 --- a/autostart-manage/run_command.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -systemctl --user start autostart.target diff --git a/autostart-manage/run_wayland_command.sh b/autostart-manage/run_wayland_command.sh deleted file mode 100644 index 6e2f6cb..0000000 --- a/autostart-manage/run_wayland_command.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -_autostart_run_graphical - -killall -SIGUSR2 waybar diff --git a/autostart-manage/run_xorg_command.sh b/autostart-manage/run_xorg_command.sh deleted file mode 100644 index b9ee3ae..0000000 --- a/autostart-manage/run_xorg_command.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -feh --bg-fill "$XDG_PICTURES_DIR/wallpaper/active_wallpaper" - -"$HOME/.config/polybar/launch.sh" & -"$HOME/.config/bspwm/focus-voip.py" & - -numlockx on -xsetroot -cursor_name left_ptr -xrdb "$HOME/.Xresources" - -_autostart_run_graphical diff --git a/autostart-manage/sync_command.sh b/autostart-manage/sync_command.sh deleted file mode 100644 index 49dfd4e..0000000 --- a/autostart-manage/sync_command.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -rm -f "$HOME/.config/systemd/user/autostart.target.wants/"* - -autostart_units=() -while IFS='' read -r line -do - autostart_units+=("autostart@$line.service") -done < <(_list "${args[groups]:-}") - -systemctl --user add-wants autostart.target "${autostart_units[@]}" diff --git a/autostart-manage/systemctl.sh b/autostart-manage/systemctl.sh deleted file mode 100644 index 7ae9a38..0000000 --- a/autostart-manage/systemctl.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -systemctl_args=("$action") -if [[ $action == "enable" ]]; then - systemctl_args=("add-wants" "autostart.target") -fi - -#shellcheck disable=SC2068 -_systemctl "${args[program]:?}" "${systemctl_args[@]}" diff --git a/output/autostart-manage b/output/autostart-manage new file mode 100755 index 0000000..99373dc --- /dev/null +++ b/output/autostart-manage @@ -0,0 +1,2220 @@ +#!/usr/bin/env bash +# This script was generated by bashly 1.1.10 (https://bashly.dannyb.co) +# Modifying it manually is not recommended + +# :wrapper.bash3_bouncer +if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then + printf "bash version 4 or higher is required\n" >&2 + exit 1 +fi + +# :command.master_script + +# :command.version_command +version_command() { + echo "$version" +} + +# :command.usage +autostart_manage_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage - Manage autostart\n" + echo + + else + printf "autostart-manage - Manage autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage COMMAND\n" + printf " autostart-manage [COMMAND] --help | -h\n" + printf " autostart-manage --version | -v\n" + echo + # :command.usage_commands + printf "%s\n" "$(blue "Commands:")" + printf " %s Generate bash completions\n" "$(green "completions")" + printf " %s List available programs\n" "$(green "list") " + printf " %s Get the current status of all programs\n" "$(green "info") " + printf " %s Remove all programs from autostart and the re-enable all\n" "$(green "sync") " + printf " %s Add a single program to autostart\n" "$(green "enable") " + printf " %s Remove a single program from autostart\n" "$(green "disable") " + printf " %s Restart programs from autostart\n" "$(green "restart") " + printf " %s Start programs from autostart\n" "$(green "start") " + printf " %s Check status of programs from autostart\n" "$(green "status") " + printf " %s Stop programs from autostart\n" "$(green "stop") " + printf " %s Kill the program from autostart\n" "$(green "kill") " + printf " %s Show the log for a single program from autostart\n" "$(green "log") " + printf " %s Execute a single program from autostart\n" "$(green "exec") " + printf " %s Run all programs\n" "$(green "run") " + printf " %s Run all the wayland specific tasks and all programs\n" "$(green "run-wayland")" + printf " %s Run all the xorg specific tasks and all programs\n" "$(green "run-xorg") " + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + printf " %s\n" "$(yellow "--version, -v")" + printf " Show version number\n" + echo + + # :command.usage_environment_variables + printf "%s\n" "$(blue "Environment Variables:")" + + # :environment_variable.usage + printf " %s\n" "$(cyan "HOSTNAME")" + printf " The hostname to use. We will try to get the value automatically.\n" + echo + + fi +} + +# :command.usage +autostart_manage_completions_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage completions - Generate bash completions\n" + echo + + else + printf "autostart-manage completions - Generate bash completions\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage completions\n" + printf " autostart-manage completions --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + fi +} + +# :command.usage +autostart_manage_list_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage list - List available programs\n" + echo + + else + printf "autostart-manage list - List available programs\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage list\n" + printf " autostart-manage list --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + fi +} + +# :command.usage +autostart_manage_info_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage info - Get the current status of all programs\n" + echo + + else + printf "autostart-manage info - Get the current status of all programs\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage info\n" + printf " autostart-manage info --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + fi +} + +# :command.usage +autostart_manage_sync_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage sync - Remove all programs from autostart and the re-enable all\n" + echo + + else + printf "autostart-manage sync - Remove all programs from autostart and the re-enable all\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage sync [GROUPS]\n" + printf " autostart-manage sync --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "GROUPS")" + printf " Extra groups to sync\n" + echo + + fi +} + +# :command.usage +autostart_manage_enable_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage enable - Add a single program to autostart\n" + echo + + else + printf "autostart-manage enable - Add a single program to autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage enable PROGRAM\n" + printf " autostart-manage enable --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to add to autostart\n" + echo + + fi +} + +# :command.usage +autostart_manage_disable_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage disable - Remove a single program from autostart\n" + echo + + else + printf "autostart-manage disable - Remove a single program from autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage disable PROGRAM\n" + printf " autostart-manage disable --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to add to autostart\n" + echo + + fi +} + +# :command.usage +autostart_manage_restart_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage restart - Restart programs from autostart\n" + echo + + else + printf "autostart-manage restart - Restart programs from autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage restart [PROGRAM]\n" + printf " autostart-manage restart --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to add to autostart\n" + printf " Default: *\n" + echo + + fi +} + +# :command.usage +autostart_manage_start_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage start - Start programs from autostart\n" + echo + + else + printf "autostart-manage start - Start programs from autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage start [PROGRAM]\n" + printf " autostart-manage start --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to start to autostart\n" + printf " Default: *\n" + echo + + fi +} + +# :command.usage +autostart_manage_status_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage status - Check status of programs from autostart\n" + echo + + else + printf "autostart-manage status - Check status of programs from autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage status [PROGRAM]\n" + printf " autostart-manage status --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to check status on\n" + printf " Default: *\n" + echo + + fi +} + +# :command.usage +autostart_manage_stop_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage stop - Stop programs from autostart\n" + echo + + else + printf "autostart-manage stop - Stop programs from autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage stop [PROGRAM]\n" + printf " autostart-manage stop --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to stop\n" + printf " Default: *\n" + echo + + fi +} + +# :command.usage +autostart_manage_kill_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage kill - Kill the program from autostart\n" + echo + + else + printf "autostart-manage kill - Kill the program from autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage kill PROGRAM\n" + printf " autostart-manage kill --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to kill\n" + echo + + fi +} + +# :command.usage +autostart_manage_log_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage log - Show the log for a single program from autostart\n" + echo + + else + printf "autostart-manage log - Show the log for a single program from autostart\n" + echo + + fi + + printf "Alias: logs\n" + echo + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage log PROGRAM\n" + printf " autostart-manage log --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to log\n" + echo + + fi +} + +# :command.usage +autostart_manage_exec_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage exec - Execute a single program from autostart\n" + echo + + else + printf "autostart-manage exec - Execute a single program from autostart\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage exec PROGRAM\n" + printf " autostart-manage exec --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(blue "Arguments:")" + + # :argument.usage + printf " %s\n" "$(red "PROGRAM")" + printf " Program to execute\n" + echo + + fi +} + +# :command.usage +autostart_manage_run_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage run - Run all programs\n" + echo + + else + printf "autostart-manage run - Run all programs\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage run\n" + printf " autostart-manage run --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + fi +} + +# :command.usage +autostart_manage_run_wayland_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage run-wayland - Run all the wayland specific tasks and all programs\n" + echo + + else + printf "autostart-manage run-wayland - Run all the wayland specific tasks and all programs\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage run-wayland\n" + printf " autostart-manage run-wayland --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + fi +} + +# :command.usage +autostart_manage_run_xorg_usage() { + if [[ -n $long_usage ]]; then + printf "autostart-manage run-xorg - Run all the xorg specific tasks and all programs\n" + echo + + else + printf "autostart-manage run-xorg - Run all the xorg specific tasks and all programs\n" + echo + + fi + + printf "%s\n" "$(blue "Usage:")" + printf " autostart-manage run-xorg\n" + printf " autostart-manage run-xorg --help | -h\n" + echo + + # :command.long_usage + if [[ -n $long_usage ]]; then + printf "%s\n" "$(blue "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(yellow "--help, -h")" + printf " Show this help\n" + echo + + fi +} + +# :command.normalize_input +# :command.normalize_input_function +normalize_input() { + local arg flags passthru + passthru=false + + while [[ $# -gt 0 ]]; do + arg="$1" + if [[ $passthru == true ]]; then + input+=("$arg") + elif [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then + input+=("${BASH_REMATCH[1]}") + input+=("${BASH_REMATCH[2]}") + elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then + input+=("${BASH_REMATCH[1]}") + input+=("${BASH_REMATCH[2]}") + elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then + flags="${BASH_REMATCH[1]}" + for ((i = 0; i < ${#flags}; i++)); do + input+=("-${flags:i:1}") + done + elif [[ "$arg" == "--" ]]; then + passthru=true + input+=("$arg") + else + input+=("$arg") + fi + + shift + done +} + +# :command.inspect_args +inspect_args() { + if ((${#args[@]})); then + readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) + echo args: + for k in "${sorted_keys[@]}"; do + echo "- \${args[$k]} = ${args[$k]}" + done + else + echo args: none + fi + + if ((${#other_args[@]})); then + echo + echo other_args: + echo "- \${other_args[*]} = ${other_args[*]}" + for i in "${!other_args[@]}"; do + echo "- \${other_args[$i]} = ${other_args[$i]}" + done + fi + + if ((${#deps[@]})); then + readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort) + echo + echo deps: + for k in "${sorted_keys[@]}"; do + echo "- \${deps[$k]} = ${deps[$k]}" + done + fi + + if ((${#env_var_names[@]})); then + readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort) + echo + echo "environment variables:" + for k in "${sorted_names[@]}"; do + echo "- \$$k = ${!k:-}" + done + fi +} + +# :command.user_lib +# autostart-manage/lib/colors.sh +print_in_color() { + local color="$1" + shift + if [[ -z ${NO_COLOR+x} ]]; then + printf "$color%b\e[0m\n" "$*" + else + printf "%b\n" "$*" + fi +} + +red() { print_in_color "\e[31m" "$*"; } +green() { print_in_color "\e[32m" "$*"; } +yellow() { print_in_color "\e[33m" "$*"; } +blue() { print_in_color "\e[34m" "$*"; } +magenta() { print_in_color "\e[35m" "$*"; } +cyan() { print_in_color "\e[36m" "$*"; } +bold() { print_in_color "\e[1m" "$*"; } +underlined() { print_in_color "\e[4m" "$*"; } +red_bold() { print_in_color "\e[1;31m" "$*"; } +green_bold() { print_in_color "\e[1;32m" "$*"; } +yellow_bold() { print_in_color "\e[1;33m" "$*"; } +blue_bold() { print_in_color "\e[1;34m" "$*"; } +magenta_bold() { print_in_color "\e[1;35m" "$*"; } +cyan_bold() { print_in_color "\e[1;36m" "$*"; } +red_underlined() { print_in_color "\e[4;31m" "$*"; } +green_underlined() { print_in_color "\e[4;32m" "$*"; } +yellow_underlined() { print_in_color "\e[4;33m" "$*"; } +blue_underlined() { print_in_color "\e[4;34m" "$*"; } +magenta_underlined() { print_in_color "\e[4;35m" "$*"; } +cyan_underlined() { print_in_color "\e[4;36m" "$*"; } + +# autostart-manage/lib/common.sh +#!/usr/bin/env bash + +_systemctl () { + systemctl --user "${@:2}" "autostart@$1.service" +} + +_query_autostart_toml() { + groups_json=$(echo -n "$2" | tr "," "\n" | jq -R . | jq -s .) + tomlq -r \ + --arg host "$HOSTNAME" \ + --argjson extra_groups "$groups_json" \ + '.hosts[$host].groups as $groups | .apps | to_entries[] | select( + (.value.hosts | contains([$host])) or + ([.value.group] | inside($groups)) or + ([.value.group] | inside($extra_groups)) or + $extra_groups == ["*"] + ) | '"$1" \ + "$XDG_CONFIG_HOME/autostart.toml" +} + +_list () { + _query_autostart_toml '.value.alias // .key' "$1" +} + +_autostart_run_graphical () { + set +e + pass x # Try to unlock yubikey asap + + start-audio pipewire + wait-for-service "network-online.target" + + # Execute only if not already running + # Don't match keepassxc-proxy + if ! (pgrep -l keepassxc | grep -v prox) >/dev/null + then + if pass x + then + (pass keepass | head -n 1 | keepassxc --pw-stdin ~/sync/passwords.kdbx) & + fi + fi + + autoinstall run graphical + autostart-manage run +} + +_echo_table () { + for unit in "$@" + do + if [ "$(_systemctl "$unit" is-enabled)" = "enabled" ] + then + _enabled=$(green "enabled") + else + _enabled=$(red "disabled") + fi + + if _systemctl "$unit" is-active --quiet + then + _active=$(green "active") + else + _active=$(red "inactive") + fi + + printf "%s\t%s\t%s\t%s\n" \ + "$unit" \ + "$_enabled" \ + "$_active" \ + "$(_get_autostart_cmd "$unit")" + done +} + +_get_autostart_cmd () { + _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.command' "*" +} + +_get_autostart_delay () { + _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.delay // 0' "*" +} + +# autostart-manage/lib/send_completions.sh +send_completions() { + echo $'# autostart-manage completion -*- shell-script -*-' + echo $'' + echo $'# This bash completions script was generated by' + echo $'# completely (https://github.com/dannyben/completely)' + echo $'# Modifying it manually is not recommended' + echo $'' + echo $'_autostart-manage_completions_filter() {' + echo $' local words="$1"' + echo $' local cur=${COMP_WORDS[COMP_CWORD]}' + echo $' local result=()' + echo $'' + echo $' if [[ "${cur:0:1}" == "-" ]]; then' + echo $' echo "$words"' + echo $' ' + echo $' else' + echo $' for word in $words; do' + echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")' + echo $' done' + echo $'' + echo $' echo "${result[*]}"' + echo $'' + echo $' fi' + echo $'}' + echo $'' + echo $'_autostart-manage_completions() {' + echo $' local cur=${COMP_WORDS[COMP_CWORD]}' + echo $' local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")' + echo $' local compline="${compwords[*]}"' + echo $'' + echo $' case "$compline" in' + echo $' \'completions\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "--help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'run-wayland\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "--help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'run-xorg\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "--help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'restart\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'disable\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'status\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'enable\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'start\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'sync\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "--help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'info\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "--help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'stop\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'kill\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'logs\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'exec\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'list\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "--help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'log\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "$(autostart-manage list) --help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' \'run\'*)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "--help -h")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' *)' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_autostart-manage_completions_filter "--help --version -h -v completions disable enable exec info kill list log logs restart run run-wayland run-xorg start status stop sync")" -- "$cur" )' + echo $' ;;' + echo $'' + echo $' esac' + echo $'} &&' + echo $'complete -F _autostart-manage_completions autostart-manage' + echo $'' + echo $'# ex: filetype=sh' +} + +# autostart-manage/lib/systemd_files.sh +#!/usr/bin/env bash + +_deploy_service_file() { + cat < "$1" +[Unit] +Description=Autostart several tools and services +StartLimitIntervalSec=120 +StartLimitBurst=10 + +[Service] +KillMode=process +ExecStart=/bin/sh -c ". \$HOME/.profile && autostart-manage exec '%i'" +Restart=on-failure +RestartSec=5s +EOF +} + +_deploy_target_file() { + cat < "$1" +[Unit] +Description=Current graphical user session +Documentation=man:systemd.special(7) +RefuseManualStart=no +StopWhenUnneeded=no +EOF +} + +# :command.command_functions +# :command.function +autostart_manage_completions_command() { + # autostart-manage/completions_command.sh + #!/usr/bin/env bash + + send_completions + +} + +# :command.function +autostart_manage_list_command() { + # autostart-manage/list_command.sh + #!/usr/bin/env bash + + _list "*" + +} + +# :command.function +autostart_manage_info_command() { + # autostart-manage/info_command.sh + #!/usr/bin/env bash + + autostart_units=() + while IFS='' read -r line + do + autostart_units+=("$line") + done < <(_list "*") + + _echo_table "${autostart_units[@]}" | column -t -s$'\t' --table-columns 'Unit,Enabled?,Active?,Command' + +} + +# :command.function +autostart_manage_sync_command() { + # autostart-manage/sync_command.sh + #!/usr/bin/env bash + + rm -f "$HOME/.config/systemd/user/autostart.target.wants/"* + + autostart_units=() + while IFS='' read -r line + do + autostart_units+=("autostart@$line.service") + done < <(_list "${args[groups]:-}") + + systemctl --user add-wants autostart.target "${autostart_units[@]}" + +} + +# :command.function +autostart_manage_enable_command() { + # autostart-manage/systemctl.sh + #!/usr/bin/env bash + + systemctl_args=("$action") + if [[ $action == "enable" ]]; then + systemctl_args=("add-wants" "autostart.target") + fi + + #shellcheck disable=SC2068 + _systemctl "${args[program]:?}" "${systemctl_args[@]}" + +} + +# :command.function +autostart_manage_disable_command() { + # autostart-manage/systemctl.sh + #!/usr/bin/env bash + + systemctl_args=("$action") + if [[ $action == "enable" ]]; then + systemctl_args=("add-wants" "autostart.target") + fi + + #shellcheck disable=SC2068 + _systemctl "${args[program]:?}" "${systemctl_args[@]}" + +} + +# :command.function +autostart_manage_restart_command() { + # autostart-manage/systemctl.sh + #!/usr/bin/env bash + + systemctl_args=("$action") + if [[ $action == "enable" ]]; then + systemctl_args=("add-wants" "autostart.target") + fi + + #shellcheck disable=SC2068 + _systemctl "${args[program]:?}" "${systemctl_args[@]}" + +} + +# :command.function +autostart_manage_start_command() { + # autostart-manage/systemctl.sh + #!/usr/bin/env bash + + systemctl_args=("$action") + if [[ $action == "enable" ]]; then + systemctl_args=("add-wants" "autostart.target") + fi + + #shellcheck disable=SC2068 + _systemctl "${args[program]:?}" "${systemctl_args[@]}" + +} + +# :command.function +autostart_manage_status_command() { + # autostart-manage/systemctl.sh + #!/usr/bin/env bash + + systemctl_args=("$action") + if [[ $action == "enable" ]]; then + systemctl_args=("add-wants" "autostart.target") + fi + + #shellcheck disable=SC2068 + _systemctl "${args[program]:?}" "${systemctl_args[@]}" + +} + +# :command.function +autostart_manage_stop_command() { + # autostart-manage/systemctl.sh + #!/usr/bin/env bash + + systemctl_args=("$action") + if [[ $action == "enable" ]]; then + systemctl_args=("add-wants" "autostart.target") + fi + + #shellcheck disable=SC2068 + _systemctl "${args[program]:?}" "${systemctl_args[@]}" + +} + +# :command.function +autostart_manage_kill_command() { + # autostart-manage/systemctl.sh + #!/usr/bin/env bash + + systemctl_args=("$action") + if [[ $action == "enable" ]]; then + systemctl_args=("add-wants" "autostart.target") + fi + + #shellcheck disable=SC2068 + _systemctl "${args[program]:?}" "${systemctl_args[@]}" + +} + +# :command.function +autostart_manage_log_command() { + # autostart-manage/log_command.sh + #!/usr/bin/env bash + + journalctl --user -fu "autostart@${args[program]:?}.service" + +} + +# :command.function +autostart_manage_exec_command() { + # autostart-manage/exec_command.sh + #!/usr/bin/env bash + + program=${args[program]:?} + + sleep "$(_get_autostart_delay "$program")" + bash -c "$(_get_autostart_cmd "$program")" + +} + +# :command.function +autostart_manage_run_command() { + # autostart-manage/run_command.sh + #!/usr/bin/env bash + + systemctl --user start autostart.target + +} + +# :command.function +autostart_manage_run_wayland_command() { + # autostart-manage/run_wayland_command.sh + #!/usr/bin/env bash + + _autostart_run_graphical + + killall -SIGUSR2 waybar + +} + +# :command.function +autostart_manage_run_xorg_command() { + # autostart-manage/run_xorg_command.sh + #!/usr/bin/env bash + + feh --bg-fill "$XDG_PICTURES_DIR/wallpaper/active_wallpaper" + + "$HOME/.config/polybar/launch.sh" & + "$HOME/.config/bspwm/focus-voip.py" & + + numlockx on + xsetroot -cursor_name left_ptr + xrdb "$HOME/.Xresources" + + _autostart_run_graphical + +} + +# :command.parse_requirements +parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --version | -v) + version_command + exit + ;; + + --help | -h) + long_usage=yes + autostart_manage_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.environment_variables_filter + + env_var_names+=("HOSTNAME") + + # :command.dependencies_filter + if command -v tomlq >/dev/null 2>&1; then + deps['tomlq']="$(command -v tomlq | head -n1)" + else + printf "missing dependency: tomlq\n" >&2 + printf "%s\n" "please install yq (https://github.com/kislyuk/yq)" >&2 + exit 1 + fi + + # :command.command_filter + action=${1:-} + + case $action in + -*) ;; + + completions) + action="completions" + shift + autostart_manage_completions_parse_requirements "$@" + shift $# + ;; + + list) + action="list" + shift + autostart_manage_list_parse_requirements "$@" + shift $# + ;; + + info) + action="info" + shift + autostart_manage_info_parse_requirements "$@" + shift $# + ;; + + sync) + action="sync" + shift + autostart_manage_sync_parse_requirements "$@" + shift $# + ;; + + enable) + action="enable" + shift + autostart_manage_enable_parse_requirements "$@" + shift $# + ;; + + disable) + action="disable" + shift + autostart_manage_disable_parse_requirements "$@" + shift $# + ;; + + restart) + action="restart" + shift + autostart_manage_restart_parse_requirements "$@" + shift $# + ;; + + start) + action="start" + shift + autostart_manage_start_parse_requirements "$@" + shift $# + ;; + + status) + action="status" + shift + autostart_manage_status_parse_requirements "$@" + shift $# + ;; + + stop) + action="stop" + shift + autostart_manage_stop_parse_requirements "$@" + shift $# + ;; + + kill) + action="kill" + shift + autostart_manage_kill_parse_requirements "$@" + shift $# + ;; + + log | logs) + action="log" + shift + autostart_manage_log_parse_requirements "$@" + shift $# + ;; + + exec) + action="exec" + shift + autostart_manage_exec_parse_requirements "$@" + shift $# + ;; + + run) + action="run" + shift + autostart_manage_run_parse_requirements "$@" + shift $# + ;; + + run-wayland) + action="run-wayland" + shift + autostart_manage_run_wayland_parse_requirements "$@" + shift $# + ;; + + run-xorg) + action="run-xorg" + shift + autostart_manage_run_xorg_parse_requirements "$@" + shift $# + ;; + + # :command.command_fallback + "") + autostart_manage_usage >&2 + exit 1 + ;; + + *) + printf "invalid command: %s\n" "$action" >&2 + exit 1 + ;; + + esac + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + + ;; + + esac + done + +} + +# :command.parse_requirements +autostart_manage_completions_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_completions_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="completions" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + + ;; + + esac + done + +} + +# :command.parse_requirements +autostart_manage_list_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_list_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="list" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + + ;; + + esac + done + +} + +# :command.parse_requirements +autostart_manage_info_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_info_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="info" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + + ;; + + esac + done + +} + +# :command.parse_requirements +autostart_manage_sync_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_sync_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="sync" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['groups']+x} ]]; then + args['groups']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + +} + +# :command.parse_requirements +autostart_manage_enable_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_enable_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="enable" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.required_args_filter + if [[ -z ${args['program']+x} ]]; then + printf "missing required argument: PROGRAM\nusage: autostart-manage enable PROGRAM\n" >&2 + exit 1 + fi + +} + +# :command.parse_requirements +autostart_manage_disable_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_disable_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="disable" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.required_args_filter + if [[ -z ${args['program']+x} ]]; then + printf "missing required argument: PROGRAM\nusage: autostart-manage disable PROGRAM\n" >&2 + exit 1 + fi + +} + +# :command.parse_requirements +autostart_manage_restart_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_restart_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="restart" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.default_assignments + [[ -n ${args['program']:-} ]] || args['program']="*" + +} + +# :command.parse_requirements +autostart_manage_start_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_start_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="start" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.default_assignments + [[ -n ${args['program']:-} ]] || args['program']="*" + +} + +# :command.parse_requirements +autostart_manage_status_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_status_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="status" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.default_assignments + [[ -n ${args['program']:-} ]] || args['program']="*" + +} + +# :command.parse_requirements +autostart_manage_stop_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_stop_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="stop" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.default_assignments + [[ -n ${args['program']:-} ]] || args['program']="*" + +} + +# :command.parse_requirements +autostart_manage_kill_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_kill_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="kill" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.required_args_filter + if [[ -z ${args['program']+x} ]]; then + printf "missing required argument: PROGRAM\nusage: autostart-manage kill PROGRAM\n" >&2 + exit 1 + fi + +} + +# :command.parse_requirements +autostart_manage_log_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_log_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="log" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.required_args_filter + if [[ -z ${args['program']+x} ]]; then + printf "missing required argument: PROGRAM\nusage: autostart-manage log PROGRAM\n" >&2 + exit 1 + fi + +} + +# :command.parse_requirements +autostart_manage_exec_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_exec_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="exec" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['program']+x} ]]; then + args['program']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.required_args_filter + if [[ -z ${args['program']+x} ]]; then + printf "missing required argument: PROGRAM\nusage: autostart-manage exec PROGRAM\n" >&2 + exit 1 + fi + +} + +# :command.parse_requirements +autostart_manage_run_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_run_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="run" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + + ;; + + esac + done + +} + +# :command.parse_requirements +autostart_manage_run_wayland_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_run_wayland_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="run-wayland" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + + ;; + + esac + done + +} + +# :command.parse_requirements +autostart_manage_run_xorg_parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + case "${1:-}" in + --help | -h) + long_usage=yes + autostart_manage_run_xorg_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="run-xorg" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + + ;; + + esac + done + +} + +# :command.user_hooks +before_hook() { + # autostart-manage/before.sh + #!/usr/bin/env bash + + service_file="$HOME/.config/systemd/user/autostart@.service" + if [ ! -f "$service_file" ]; then + _deploy_service_file "$service_file" + fi + + target_file="$HOME/.config/systemd/user/autostart.target" + if [ ! -f "$target_file" ]; then + _deploy_target_file "$target_file" + fi + +} + +# :command.initialize +initialize() { + version="0.1.3" + long_usage='' + set -euo pipefail + +} + +# :command.run +run() { + declare -A args=() + declare -A deps=() + declare -a other_args=() + declare -a env_var_names=() + declare -a input=() + normalize_input "$@" + parse_requirements "${input[@]}" + before_hook + + case "$action" in + "completions") autostart_manage_completions_command ;; + "list") autostart_manage_list_command ;; + "info") autostart_manage_info_command ;; + "sync") autostart_manage_sync_command ;; + "enable") autostart_manage_enable_command ;; + "disable") autostart_manage_disable_command ;; + "restart") autostart_manage_restart_command ;; + "start") autostart_manage_start_command ;; + "status") autostart_manage_status_command ;; + "stop") autostart_manage_stop_command ;; + "kill") autostart_manage_kill_command ;; + "log") autostart_manage_log_command ;; + "exec") autostart_manage_exec_command ;; + "run") autostart_manage_run_command ;; + "run-wayland") autostart_manage_run_wayland_command ;; + "run-xorg") autostart_manage_run_xorg_command ;; + esac +} + +initialize +run "$@" diff --git a/run.sh b/run.sh index 155b243..88ced7f 100755 --- a/run.sh +++ b/run.sh @@ -1,11 +1,7 @@ #!/usr/bin/env sh -target=$(cat .target) - -[ -n "$target" ] || exit 1 - make generate printf "\nBuild complete. Running...\n==========================\n\n" -time "./output/$target" "$@" +time ./autoinstall "$@" diff --git a/autoinstall/archive_command.sh b/src/archive_command.sh similarity index 100% rename from autoinstall/archive_command.sh rename to src/archive_command.sh diff --git a/autoinstall/bashly.yml b/src/bashly.yml similarity index 99% rename from autoinstall/bashly.yml rename to src/bashly.yml index bd7fb0f..c99c68d 100644 --- a/autoinstall/bashly.yml +++ b/src/bashly.yml @@ -1,6 +1,6 @@ name: autoinstall help: Install files, repository and else -version: 0.1.3 +version: 0.1.4 flags: - long: --clean diff --git a/autoinstall/before.sh b/src/before.sh similarity index 100% rename from autoinstall/before.sh rename to src/before.sh diff --git a/autoinstall/completions_command.sh b/src/completions_command.sh similarity index 100% rename from autoinstall/completions_command.sh rename to src/completions_command.sh diff --git a/autoinstall/env_command.sh b/src/env_command.sh similarity index 100% rename from autoinstall/env_command.sh rename to src/env_command.sh diff --git a/autoinstall/file_command.sh b/src/file_command.sh similarity index 100% rename from autoinstall/file_command.sh rename to src/file_command.sh diff --git a/autoinstall/flatpak_command.sh b/src/flatpak_command.sh similarity index 100% rename from autoinstall/flatpak_command.sh rename to src/flatpak_command.sh diff --git a/autoinstall/git_command.sh b/src/git_command.sh similarity index 100% rename from autoinstall/git_command.sh rename to src/git_command.sh diff --git a/autoinstall/lib/colors.sh b/src/lib/colors.sh similarity index 100% rename from autoinstall/lib/colors.sh rename to src/lib/colors.sh diff --git a/autoinstall/lib/common.sh b/src/lib/common.sh similarity index 100% rename from autoinstall/lib/common.sh rename to src/lib/common.sh diff --git a/autoinstall/run_command.sh b/src/run_command.sh similarity index 100% rename from autoinstall/run_command.sh rename to src/run_command.sh diff --git a/autoinstall/text_command.sh b/src/text_command.sh similarity index 100% rename from autoinstall/text_command.sh rename to src/text_command.sh