From aed681d0b0c18cc2966c9c687434cf6b4b8f90e0 Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Mon, 13 May 2024 15:01:21 +0200
Subject: [PATCH 01/10] Improve error handling in autoinstall run
---
autoinstall/run_command.sh | 76 +++++++++++++++++++-------------------
1 file changed, 39 insertions(+), 37 deletions(-)
diff --git a/autoinstall/run_command.sh b/autoinstall/run_command.sh
index e60be67..f82eb34 100644
--- a/autoinstall/run_command.sh
+++ b/autoinstall/run_command.sh
@@ -4,7 +4,7 @@ group=${args[group]:?}
file=${args[--file]:-}
clean=${args[--clean]:-}
-_handle_entry() {
+_install_entry() {
type="$1"
source="$2"
target="$3"
@@ -30,19 +30,49 @@ _handle_entry() {
install_args+=("--completions=$completions")
fi
- if [[ $source = \$* ]]
- then
- source=$(eval "echo $source")
- fi
install_args+=("$source")
- install_args+=("$(eval "echo $target")")
+ install_args+=("$target")
+
+ "$0" "${install_args[@]}"
+}
+
+_handle_entry() {
+ unset AUTOINSTALL_ITEM_TYPE \
+ AUTOINSTALL_ITEM_SOURCE \
+ AUTOINSTALL_ITEM_TARGET \
+ AUTOINSTALL_ITEM_HOOK \
+ AUTOINSTALL_ITEM_PIPE \
+ AUTOINSTALL_ITEM_COMPLETIONS \
+ AUTOINSTALL_ITEM_GROUPS
+
+ eval "$1"
+
+ # check if we have the required vars
+ if [[ -z "${AUTOINSTALL_ITEM_TYPE:-}" \
+ || -z "${AUTOINSTALL_ITEM_SOURCE:-}" \
+ || -z "${AUTOINSTALL_ITEM_TARGET:-}" \
+ || -z "${AUTOINSTALL_ITEM_GROUPS:-}" ]]
+ then
+ return
+ fi
+
+ if [[ "$group" != "all" ]]
+ then
+ # check if group is in groups
+ if [[ ! "${AUTOINSTALL_ITEM_GROUPS}" =~ (^|,)$group(,|$) ]]
+ then
+ return
+ fi
+ fi
+
+ _install_entry "$AUTOINSTALL_ITEM_TYPE" "$AUTOINSTALL_ITEM_SOURCE" \
+ "$AUTOINSTALL_ITEM_TARGET" "${AUTOINSTALL_ITEM_HOOK:-}" "${AUTOINSTALL_ITEM_PIPE:-}" "${AUTOINSTALL_ITEM_COMPLETIONS:-}"
- "$0" "${install_args[@]}" || true # Continue on error
}
file_lines=$(wc -l < "$file")
-line=0
+line=129
while [[ $line -lt $file_lines ]]; do
entry=$(tail -n +$line "$file" | awk '/^$/{exit} {print} ')
entry_len=$(echo "$entry" | wc -l)
@@ -52,33 +82,5 @@ while [[ $line -lt $file_lines ]]; do
continue
fi
- unset AUTOINSTALL_ITEM_TYPE \
- AUTOINSTALL_ITEM_SOURCE \
- AUTOINSTALL_ITEM_TARGET \
- AUTOINSTALL_ITEM_HOOK \
- AUTOINSTALL_ITEM_PIPE \
- AUTOINSTALL_ITEM_COMPLETIONS \
- AUTOINSTALL_ITEM_GROUPS
- eval "$entry"
-
- # check if we have the required vars
- if [[ -z "${AUTOINSTALL_ITEM_TYPE:-}" \
- || -z "${AUTOINSTALL_ITEM_SOURCE:-}" \
- || -z "${AUTOINSTALL_ITEM_TARGET:-}" \
- || -z "${AUTOINSTALL_ITEM_GROUPS:-}" ]]
- then
- continue
- fi
-
- if [[ "$group" != "all" ]]
- then
- # check if group is in groups
- if [[ ! "${AUTOINSTALL_ITEM_GROUPS}" =~ (^|,)$group(,|$) ]]
- then
- continue
- fi
- fi
-
- _handle_entry "$AUTOINSTALL_ITEM_TYPE" "$AUTOINSTALL_ITEM_SOURCE" \
- "$AUTOINSTALL_ITEM_TARGET" "${AUTOINSTALL_ITEM_HOOK:-}" "${AUTOINSTALL_ITEM_PIPE:-}" "${AUTOINSTALL_ITEM_COMPLETIONS:-}"
+ _handle_entry "$entry" || true # ignore errors
done
From 1b891407a3eac6a36ed6395b5e1964d0c6fbb3ce Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Tue, 14 May 2024 12:20:10 +0200
Subject: [PATCH 02/10] Allow source to be evaluated only when group is matched
---
autoinstall/run_command.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/autoinstall/run_command.sh b/autoinstall/run_command.sh
index f82eb34..30142ef 100644
--- a/autoinstall/run_command.sh
+++ b/autoinstall/run_command.sh
@@ -30,9 +30,13 @@ _install_entry() {
install_args+=("--completions=$completions")
fi
+ if [[ $source = \$* ]]
+ then
+ source=$(eval "echo $source")
+ fi
install_args+=("$source")
- install_args+=("$target")
+ install_args+=("$(eval "echo $target")")
"$0" "${install_args[@]}"
}
From 2aa4ae8b5803a0c7a2f640b7fbc4698df3bccdfb Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Thu, 23 May 2024 18:28:10 +0200
Subject: [PATCH 03/10] Fix wrong starting line (was for debugging)
---
autoinstall/run_command.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/autoinstall/run_command.sh b/autoinstall/run_command.sh
index 30142ef..b3b77b6 100644
--- a/autoinstall/run_command.sh
+++ b/autoinstall/run_command.sh
@@ -76,7 +76,7 @@ _handle_entry() {
}
file_lines=$(wc -l < "$file")
-line=129
+line=0
while [[ $line -lt $file_lines ]]; do
entry=$(tail -n +$line "$file" | awk '/^$/{exit} {print} ')
entry_len=$(echo "$entry" | wc -l)
From 67fed76c689451442208a6dc7872bc93675cdf7c Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Fri, 21 Jun 2024 22:35:59 +0200
Subject: [PATCH 04/10] Add faster group-detection in autoinstall (dynamic
groups are now impossible)
Allow for absolute paths in autoinstall exe
Add timer in run.sh
---
autoinstall/file_command.sh | 2 +-
autoinstall/run_command.sh | 24 +++++++++++-------------
run.sh | 2 +-
3 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/autoinstall/file_command.sh b/autoinstall/file_command.sh
index 08e9519..f145fab 100644
--- a/autoinstall/file_command.sh
+++ b/autoinstall/file_command.sh
@@ -5,7 +5,7 @@ completions=${args[--completions]:-}
target=${args[target]:?}
url=${args[url]:?}
-if [ "${action:-file}" = "exe" ]
+if [ "${action:-file}" = "exe" ] && ! echo "$target" | grep -q "/"
then
if [ -x "$(command -v "$target")" ]
then
diff --git a/autoinstall/run_command.sh b/autoinstall/run_command.sh
index b3b77b6..5ea6714 100644
--- a/autoinstall/run_command.sh
+++ b/autoinstall/run_command.sh
@@ -47,29 +47,18 @@ _handle_entry() {
AUTOINSTALL_ITEM_TARGET \
AUTOINSTALL_ITEM_HOOK \
AUTOINSTALL_ITEM_PIPE \
- AUTOINSTALL_ITEM_COMPLETIONS \
- AUTOINSTALL_ITEM_GROUPS
+ AUTOINSTALL_ITEM_COMPLETIONS
eval "$1"
# check if we have the required vars
if [[ -z "${AUTOINSTALL_ITEM_TYPE:-}" \
|| -z "${AUTOINSTALL_ITEM_SOURCE:-}" \
- || -z "${AUTOINSTALL_ITEM_TARGET:-}" \
- || -z "${AUTOINSTALL_ITEM_GROUPS:-}" ]]
+ || -z "${AUTOINSTALL_ITEM_TARGET:-}" ]]
then
return
fi
- if [[ "$group" != "all" ]]
- then
- # check if group is in groups
- if [[ ! "${AUTOINSTALL_ITEM_GROUPS}" =~ (^|,)$group(,|$) ]]
- then
- return
- fi
- fi
-
_install_entry "$AUTOINSTALL_ITEM_TYPE" "$AUTOINSTALL_ITEM_SOURCE" \
"$AUTOINSTALL_ITEM_TARGET" "${AUTOINSTALL_ITEM_HOOK:-}" "${AUTOINSTALL_ITEM_PIPE:-}" "${AUTOINSTALL_ITEM_COMPLETIONS:-}"
@@ -86,5 +75,14 @@ while [[ $line -lt $file_lines ]]; do
continue
fi
+ if [[ "$group" != "all" ]]
+ then
+ # check if group is in groups
+ if ! echo "$entry" | grep -qE "^AUTOINSTALL_ITEM_GROUPS=\"(.*,)?$group(,.*)?\"$"
+ then
+ continue
+ fi
+ fi
+
_handle_entry "$entry" || true # ignore errors
done
diff --git a/run.sh b/run.sh
index 7cb49dc..155b243 100755
--- a/run.sh
+++ b/run.sh
@@ -8,4 +8,4 @@ make generate
printf "\nBuild complete. Running...\n==========================\n\n"
-"./output/$target" "$@"
+time "./output/$target" "$@"
From f48b7c86908e7b7af2d82349db68dfdb3c66f568 Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Wed, 23 Oct 2024 19:03:45 +0200
Subject: [PATCH 05/10] Add kill command to autostart-manage
---
autostart-manage/bashly.yml | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/autostart-manage/bashly.yml b/autostart-manage/bashly.yml
index 3327140..229eb11 100644
--- a/autostart-manage/bashly.yml
+++ b/autostart-manage/bashly.yml
@@ -73,6 +73,15 @@ commands:
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
From ab7c74f888b21434c59ac4ef30bc252775849c6a Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Wed, 23 Oct 2024 22:32:11 +0200
Subject: [PATCH 06/10] Add syncing with extra groups
---
Makefile | 2 +-
autostart-manage/bashly.yml | 4 ++++
autostart-manage/exec_command.sh | 3 +--
autostart-manage/info_command.sh | 2 +-
autostart-manage/lib/common.sh | 17 +++++++++++------
autostart-manage/list_command.sh | 2 +-
autostart-manage/sync_command.sh | 11 ++++-------
7 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
index b2a84de..35835aa 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,6 @@ generate: get-target output-dir completions
docs: generate
BASHLY_SOURCE_DIR=$(TARGET) bashly render :mandoc ./output/man1
-deploy: generate docs
+install: generate docs
cp -f ./output/$(TARGET) ~/.local/bin/
cp -f ./output/man1/$(TARGET)*.1 ~/.local/share/man/man1/
diff --git a/autostart-manage/bashly.yml b/autostart-manage/bashly.yml
index 229eb11..72f5d1a 100644
--- a/autostart-manage/bashly.yml
+++ b/autostart-manage/bashly.yml
@@ -19,6 +19,10 @@ commands:
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:
diff --git a/autostart-manage/exec_command.sh b/autostart-manage/exec_command.sh
index 2842069..2e2c816 100644
--- a/autostart-manage/exec_command.sh
+++ b/autostart-manage/exec_command.sh
@@ -2,6 +2,5 @@
program=${args[program]:?}
-cmd=$(_get_autostart_cmd "$program")
sleep "$(_get_autostart_delay "$program")"
-bash -c "$cmd"
+bash -c "$(_get_autostart_cmd "$program")"
diff --git a/autostart-manage/info_command.sh b/autostart-manage/info_command.sh
index 1f895e3..566cdce 100644
--- a/autostart-manage/info_command.sh
+++ b/autostart-manage/info_command.sh
@@ -4,6 +4,6 @@ autostart_units=()
while IFS='' read -r line
do
autostart_units+=("$line")
-done < <(_list)
+done < <(_list "*")
_echo_table "${autostart_units[@]}" | column -t -s$'\t' --table-columns 'Unit,Enabled?,Active?,Command'
diff --git a/autostart-manage/lib/common.sh b/autostart-manage/lib/common.sh
index 2479fe1..266c6e7 100644
--- a/autostart-manage/lib/common.sh
+++ b/autostart-manage/lib/common.sh
@@ -5,16 +5,21 @@ _systemctl () {
}
_query_autostart_toml() {
- tomlq -r --arg host "$HOSTNAME" \
+ 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))
+ ([.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'
+ _query_autostart_toml '.value.alias // .key' "$1"
}
_autostart_run_graphical () {
@@ -41,7 +46,7 @@ _autostart_run_graphical () {
_echo_table () {
for unit in "$@"
do
- if _systemctl "$unit" is-enabled --quiet
+ if [ "$(_systemctl "$unit" is-enabled)" = "enabled" ]
then
_enabled=$(green "enabled")
else
@@ -64,9 +69,9 @@ _echo_table () {
}
_get_autostart_cmd () {
- _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.command'
+ _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'
+ _query_autostart_toml 'select((.key == "'"$1"'") or (.value.alias == "'"$1"'")) | .value.delay // 0' "*"
}
diff --git a/autostart-manage/list_command.sh b/autostart-manage/list_command.sh
index 0986740..c732452 100644
--- a/autostart-manage/list_command.sh
+++ b/autostart-manage/list_command.sh
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
-_list
+_list "*"
diff --git a/autostart-manage/sync_command.sh b/autostart-manage/sync_command.sh
index d08ac71..49dfd4e 100644
--- a/autostart-manage/sync_command.sh
+++ b/autostart-manage/sync_command.sh
@@ -1,14 +1,11 @@
#!/usr/bin/env bash
-rm "$HOME/.config/systemd/user/autostart.target.wants/"*
+rm -f "$HOME/.config/systemd/user/autostart.target.wants/"*
autostart_units=()
while IFS='' read -r line
do
- autostart_units+=("$line")
-done < <(_list)
+ autostart_units+=("autostart@$line.service")
+done < <(_list "${args[groups]:-}")
-for unit in "${autostart_units[@]}"
-do
- _systemctl "$unit" add-wants autostart.target
-done
+systemctl --user add-wants autostart.target "${autostart_units[@]}"
From ff19aeaf32b428465e4dfff65d6e78dd60253244 Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Mon, 28 Oct 2024 19:53:42 +0100
Subject: [PATCH 07/10] Split repos
---
.envrc | 2 -
.forgejo/workflows/release.yaml | 31 ++---
.gitignore | 7 +-
Makefile | 24 +---
autoinstall/archive_command.sh | 18 ---
autoinstall/bashly.yml | 127 ------------------
autoinstall/before.sh | 30 -----
autoinstall/env_command.sh | 17 ---
autoinstall/file_command.sh | 45 -------
autoinstall/flatpak_command.sh | 13 --
autoinstall/git_command.sh | 15 ---
autoinstall/lib/common.sh | 20 ---
autoinstall/run_command.sh | 88 ------------
autoinstall/text_command.sh | 16 ---
autostart-manage/completions_command.sh | 3 -
autostart-manage/lib/colors.sh | 42 ------
settings.yml | 49 -------
{autostart-manage => src}/bashly.yml | 2 +-
{autostart-manage => src}/before.sh | 0
{autoinstall => src}/completions_command.sh | 0
{autostart-manage => src}/exec_command.sh | 0
{autostart-manage => src}/info_command.sh | 0
{autoinstall => src}/lib/colors.sh | 0
{autostart-manage => src}/lib/common.sh | 0
.../lib/systemd_files.sh | 0
{autostart-manage => src}/list_command.sh | 0
{autostart-manage => src}/log_command.sh | 0
{autostart-manage => src}/run_command.sh | 0
.../run_wayland_command.sh | 0
{autostart-manage => src}/run_xorg_command.sh | 0
{autostart-manage => src}/sync_command.sh | 0
{autostart-manage => src}/systemctl.sh | 0
32 files changed, 19 insertions(+), 530 deletions(-)
delete mode 100644 autoinstall/archive_command.sh
delete mode 100644 autoinstall/bashly.yml
delete mode 100644 autoinstall/before.sh
delete mode 100644 autoinstall/env_command.sh
delete mode 100644 autoinstall/file_command.sh
delete mode 100644 autoinstall/flatpak_command.sh
delete mode 100644 autoinstall/git_command.sh
delete mode 100644 autoinstall/lib/common.sh
delete mode 100644 autoinstall/run_command.sh
delete mode 100644 autoinstall/text_command.sh
delete mode 100644 autostart-manage/completions_command.sh
delete mode 100644 autostart-manage/lib/colors.sh
delete mode 100644 settings.yml
rename {autostart-manage => src}/bashly.yml (99%)
rename {autostart-manage => src}/before.sh (100%)
rename {autoinstall => src}/completions_command.sh (100%)
rename {autostart-manage => src}/exec_command.sh (100%)
rename {autostart-manage => src}/info_command.sh (100%)
rename {autoinstall => src}/lib/colors.sh (100%)
rename {autostart-manage => src}/lib/common.sh (100%)
rename {autostart-manage => src}/lib/systemd_files.sh (100%)
rename {autostart-manage => src}/list_command.sh (100%)
rename {autostart-manage => src}/log_command.sh (100%)
rename {autostart-manage => src}/run_command.sh (100%)
rename {autostart-manage => src}/run_wayland_command.sh (100%)
rename {autostart-manage => src}/run_xorg_command.sh (100%)
rename {autostart-manage => src}/sync_command.sh (100%)
rename {autostart-manage => src}/systemctl.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..a5297ea 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 ./autostart-manage /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..d0fb366 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
+autostart-manage
+man1
diff --git a/Makefile b/Makefile
index 35835aa..1fc809f 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 ./autostart-manage ~/.local/bin/
+ cp -f ./man1/autostart-manage*.1 ~/.local/share/man/man1/
diff --git a/autoinstall/archive_command.sh b/autoinstall/archive_command.sh
deleted file mode 100644
index 6019708..0000000
--- a/autoinstall/archive_command.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env bash
-
-target=${args[target]:?}
-url=${args[url]:?}
-
-if [ ! -f "$target" ]
-then
- echo "Installing archive $url to $target"
-
- target_dir=$(dirname "$target")
- mkdir -p "$target_dir"
- cd "$target_dir" || exit 1
-
- _http_client "$url" > "$target"
- tar xaf "$target"
-
- _run_hook
-fi
diff --git a/autoinstall/bashly.yml b/autoinstall/bashly.yml
deleted file mode 100644
index bd7fb0f..0000000
--- a/autoinstall/bashly.yml
+++ /dev/null
@@ -1,127 +0,0 @@
-name: autoinstall
-help: Install files, repository and else
-version: 0.1.3
-
-flags:
- - long: --clean
- short: -c
- help: Clean exisiting targets
- - long: --hook
- short: -h
- help: Hook to run if something changed
- arg: hook
-
-environment_variables:
- - name: AUTOINSTALL_CLEAN
- help: Clean exisiting targets
-
-dependencies:
- http_client:
- command: [curl, wget]
- help: Please install either curl or wget
-
-commands:
- - name: completions
- help: Generate bash completions
-
- - name: run
- help: Autoinstall from file
- args:
- - name: group
- required: true
- help: The group to install
- flags:
- - long: --file
- short: -f
- help: File from which to read autoinstall-config
- arg: file
- default: $XDG_CONFIG_HOME/autoinstall.conf
-
- - name: git
- help: Install a git repository
- args:
- - name: repo
- required: true
- help: The url of the git repository
- - name: target
- required: true
- help: The path to clone the repository into
-
- - name: file
- help: Install a file
- args:
- - name: url
- required: true
- help: The url of the file
- - name: target
- required: true
- help: The file-path to download the file into
- flags:
- - long: --pipe
- short: -p
- help: Pipe file through command (e.g. "tar xzO")
- arg: pipe
- default: cat
-
- - name: exe
- help: Install an executable
- args:
- - name: url
- required: true
- help: The url of the file
- - name: target
- required: true
- help: The file-path to download the file into
- filename: file_command.sh
- flags:
- - long: --pipe
- short: -f
- help: Pipe file through command (e.g. "tar xzO")
- arg: pipe
- default: cat
- - long: --completions
- short: -c
- help: Run a command on the new exe to install completions
- arg: completions
-
- - name: archive
- help: Install an archive
- args:
- - name: url
- required: true
- help: The url of the arhive
- - name: target
- required: true
- help: The path to clone the repository into
-
- - name: env
- help: Create a file with envsubst
- args:
- - name: template
- required: true
- help: The path to the template
- - name: target
- required: true
- help: The path to write the result to
- dependencies:
- envsubst: This tool is usually part of the gettext package
-
- - name: text
- help: Create a file from text
- args:
- - name: text
- required: true
- help: The text to write to the file
- - name: target
- required: true
- help: The path to write the result to
-
- - name: flatpak
- help: Install a flatpak
- args:
- - name: flatpak
- required: true
- help: The flatpak to install
- - name: mode
- required: true
- help: The target to install into (user or system)
diff --git a/autoinstall/before.sh b/autoinstall/before.sh
deleted file mode 100644
index 24b4323..0000000
--- a/autoinstall/before.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env bash
-
-action=${action:?}
-
-# do nothing on some selected actions
-if [ "$action" = "completions" ] || [ "$action" = "flatpak" ] || [ "$action" = "run" ]
-then
- return
-fi
-
-clean=${args[--clean]:-}
-target=${args[target]:?}
-
-if [ "$action" = "exe" ]
-then
- target="$HOME/.local/bin/$target"
-fi
-
-if [ -n "$clean" ] || [ -n "${AUTOINSTALL_CLEAN:-}" ]
-then
- echo "Cleaning $target"
-
- # sanity checks
- if [ -z "$target" ] || [ "$target" = "/" ] || [ "$target" = "$HOME" ] || [ "$target" = "$HOME/" ]
- then
- echo "Invalid target: '$target'"
- exit 1
- fi
- rm -rf "$target"
-fi
diff --git a/autoinstall/env_command.sh b/autoinstall/env_command.sh
deleted file mode 100644
index 74d65d7..0000000
--- a/autoinstall/env_command.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/env bash
-
-target=${args[target]:?}
-template=${args[template]:?}
-
-if [ ! -f "$target" ]
-then
- echo "Installing env-template $template to $target"
-
- target_dir=$(dirname "$target")
- mkdir -p "$target_dir"
- cd "$target_dir" || exit 1
-
- envsubst < "$template" > "$target"
-
- _run_hook
-fi
diff --git a/autoinstall/file_command.sh b/autoinstall/file_command.sh
deleted file mode 100644
index f145fab..0000000
--- a/autoinstall/file_command.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env bash
-
-pipe=${args[--pipe]:?}
-completions=${args[--completions]:-}
-target=${args[target]:?}
-url=${args[url]:?}
-
-if [ "${action:-file}" = "exe" ] && ! echo "$target" | grep -q "/"
-then
- if [ -x "$(command -v "$target")" ]
- then
- return
- fi
- exe=$target
- target="$HOME/.local/bin/$target"
-fi
-
-
-if [ ! -e "$target" ]
-then
- echo "Installing file $url to $target"
-
- target_dir=$(dirname "$target")
- mkdir -p "$target_dir"
- cd "$target_dir" || exit 1
-
- _http_client "$url" | eval "$pipe" > "$target"
-
- if [ "${action:-file}" = "exe" ]
- then
- chmod +x "$target"
-
- if [ -n "$completions" ]
- then
- echo "Installing completions for $exe"
-
- # path taken from "__load_completion" function
- bash_completions_dir=${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions
- mkdir -p "$bash_completions_dir"
- eval "$target $completions" > "$bash_completions_dir/_$(basename "$exe")"
- fi
- fi
-
- _run_hook
-fi
diff --git a/autoinstall/flatpak_command.sh b/autoinstall/flatpak_command.sh
deleted file mode 100644
index 89f6e54..0000000
--- a/autoinstall/flatpak_command.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-flatpak=${args[flatpak]:?}
-mode=${args[mode]:?}
-
-if ! flatpak info "$flatpak" &> /dev/null
-then
- echo "Installing flatpak $flatpak"
-
- flatpak install -y "--$mode" "$flatpak"
-
- _run_hook
-fi
diff --git a/autoinstall/git_command.sh b/autoinstall/git_command.sh
deleted file mode 100644
index 33faf65..0000000
--- a/autoinstall/git_command.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env bash
-
-target=${args[target]:?}
-repo=${args[repo]:?}
-
-if [ ! -d "$target" ]
-then
- echo "Installing repo $repo to $target"
-
- mkdir -p "$target"
-
- git clone --depth=1 "$repo" "$target" >/dev/null 2>&1
-
- _run_hook
-fi
diff --git a/autoinstall/lib/common.sh b/autoinstall/lib/common.sh
deleted file mode 100644
index 584603a..0000000
--- a/autoinstall/lib/common.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env bash
-
-_http_client() {
- if [ -x "$(command -v curl)" ]
- then
- curl -fsSL "$1"
- elif [ -x "$(command -v wget)" ]
- then
- wget -qO - "$1"
- fi
-}
-
-_run_hook() {
- hook=${args[--hook]:-}
- if [ -n "$hook" ]
- then
- yellow "Running hook: $hook"
- bash -c "$hook"
- fi
-}
diff --git a/autoinstall/run_command.sh b/autoinstall/run_command.sh
deleted file mode 100644
index 5ea6714..0000000
--- a/autoinstall/run_command.sh
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/usr/bin/env bash
-
-group=${args[group]:?}
-file=${args[--file]:-}
-clean=${args[--clean]:-}
-
-_install_entry() {
- type="$1"
- source="$2"
- target="$3"
- hook="$4"
- pipe="$5"
- completions="$6"
-
- install_args=()
-
- if [[ -n "$hook" ]]; then
- install_args+=("--hook=$hook")
- fi
- if [[ -n "$clean" ]]; then
- install_args+=("--clean")
- fi
-
- install_args+=("$type")
-
- if [[ -n "$pipe" ]]; then
- install_args+=("--pipe=$pipe")
- fi
- if [[ -n "$completions" ]]; then
- install_args+=("--completions=$completions")
- fi
-
- if [[ $source = \$* ]]
- then
- source=$(eval "echo $source")
- fi
- install_args+=("$source")
-
- install_args+=("$(eval "echo $target")")
-
- "$0" "${install_args[@]}"
-}
-
-_handle_entry() {
- unset AUTOINSTALL_ITEM_TYPE \
- AUTOINSTALL_ITEM_SOURCE \
- AUTOINSTALL_ITEM_TARGET \
- AUTOINSTALL_ITEM_HOOK \
- AUTOINSTALL_ITEM_PIPE \
- AUTOINSTALL_ITEM_COMPLETIONS
-
- eval "$1"
-
- # check if we have the required vars
- if [[ -z "${AUTOINSTALL_ITEM_TYPE:-}" \
- || -z "${AUTOINSTALL_ITEM_SOURCE:-}" \
- || -z "${AUTOINSTALL_ITEM_TARGET:-}" ]]
- then
- return
- fi
-
- _install_entry "$AUTOINSTALL_ITEM_TYPE" "$AUTOINSTALL_ITEM_SOURCE" \
- "$AUTOINSTALL_ITEM_TARGET" "${AUTOINSTALL_ITEM_HOOK:-}" "${AUTOINSTALL_ITEM_PIPE:-}" "${AUTOINSTALL_ITEM_COMPLETIONS:-}"
-
-}
-
-file_lines=$(wc -l < "$file")
-line=0
-while [[ $line -lt $file_lines ]]; do
- entry=$(tail -n +$line "$file" | awk '/^$/{exit} {print} ')
- entry_len=$(echo "$entry" | wc -l)
- line=$((line + entry_len))
-
- if [[ $entry_len -le 1 ]]; then
- continue
- fi
-
- if [[ "$group" != "all" ]]
- then
- # check if group is in groups
- if ! echo "$entry" | grep -qE "^AUTOINSTALL_ITEM_GROUPS=\"(.*,)?$group(,.*)?\"$"
- then
- continue
- fi
- fi
-
- _handle_entry "$entry" || true # ignore errors
-done
diff --git a/autoinstall/text_command.sh b/autoinstall/text_command.sh
deleted file mode 100644
index 4fcd486..0000000
--- a/autoinstall/text_command.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env bash
-
-target=${args[target]:?}
-text=${args[text]:?}
-
-if [ ! -f "$target" ]
-then
- echo "Installing text '$text' to $target"
-
- target_dir=$(dirname "$target")
- mkdir -p "$target_dir"
-
- echo "$text" > "$target"
-
- _run_hook
-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/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/settings.yml b/settings.yml
deleted file mode 100644
index 63e7150..0000000
--- a/settings.yml
+++ /dev/null
@@ -1,49 +0,0 @@
-# The path to bashly.yml
-config_path: "%{source_dir}/bashly.yml"
-
-# The path to use for creating the bash script
-target_dir: output
-
-# The path to use for common library files, relative to source_dir
-lib_dir: lib
-
-# The path to use for command files, relative to source_dir
-# When set to nil (~), command files will be placed directly under source_dir
-# When set to any other string, command files will be placed under this
-# directory, and each command will get its own subdirectory
-commands_dir: ~
-
-# Configure the bash options that will be added to the initialize function:
-# strict: true Bash strict mode (set -euo pipefail)
-# strict: false Only exit on errors (set -e)
-# strict: '' Do not add any 'set' directive
-# strict: <string> Add any other custom 'set' directive
-strict: true
-
-# When true, the generated script will use tab indentation instead of spaces
-# (every 2 leading spaces will be converted to a tab character)
-tab_indent: true
-
-# When true, the generated script will consider any argument in the form of
-# `-abc` as if it is `-a -b -c`.
-compact_short_flags: true
-
-# Set to 'production' or 'development':
-# env: production Generate a smaller script, without file markers
-# env: development Generate with file markers
-env: development
-
-# The extension to use when reading/writing partial script snippets
-partials_extension: sh
-
-# Display various usage elements in color by providing the name of the color
-# function. The value for each property is a name of a function that is
-# available in your script, for example: `green` or `bold`.
-# You can run `bashly add colors` to add a standard colors library.
-# This option cannot be set via environment variables.
-usage_colors:
- caption: blue
- command: green
- arg: red
- flag: yellow
- environment_variable: cyan
diff --git a/autostart-manage/bashly.yml b/src/bashly.yml
similarity index 99%
rename from autostart-manage/bashly.yml
rename to src/bashly.yml
index 72f5d1a..a578c1b 100644
--- a/autostart-manage/bashly.yml
+++ b/src/bashly.yml
@@ -1,6 +1,6 @@
name: autostart-manage
help: Manage autostart
-version: 0.1.3
+version: 0.1.4
dependencies:
tomlq: please install yq (https://github.com/kislyuk/yq)
diff --git a/autostart-manage/before.sh b/src/before.sh
similarity index 100%
rename from autostart-manage/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/autostart-manage/exec_command.sh b/src/exec_command.sh
similarity index 100%
rename from autostart-manage/exec_command.sh
rename to src/exec_command.sh
diff --git a/autostart-manage/info_command.sh b/src/info_command.sh
similarity index 100%
rename from autostart-manage/info_command.sh
rename to src/info_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/autostart-manage/lib/common.sh b/src/lib/common.sh
similarity index 100%
rename from autostart-manage/lib/common.sh
rename to src/lib/common.sh
diff --git a/autostart-manage/lib/systemd_files.sh b/src/lib/systemd_files.sh
similarity index 100%
rename from autostart-manage/lib/systemd_files.sh
rename to src/lib/systemd_files.sh
diff --git a/autostart-manage/list_command.sh b/src/list_command.sh
similarity index 100%
rename from autostart-manage/list_command.sh
rename to src/list_command.sh
diff --git a/autostart-manage/log_command.sh b/src/log_command.sh
similarity index 100%
rename from autostart-manage/log_command.sh
rename to src/log_command.sh
diff --git a/autostart-manage/run_command.sh b/src/run_command.sh
similarity index 100%
rename from autostart-manage/run_command.sh
rename to src/run_command.sh
diff --git a/autostart-manage/run_wayland_command.sh b/src/run_wayland_command.sh
similarity index 100%
rename from autostart-manage/run_wayland_command.sh
rename to src/run_wayland_command.sh
diff --git a/autostart-manage/run_xorg_command.sh b/src/run_xorg_command.sh
similarity index 100%
rename from autostart-manage/run_xorg_command.sh
rename to src/run_xorg_command.sh
diff --git a/autostart-manage/sync_command.sh b/src/sync_command.sh
similarity index 100%
rename from autostart-manage/sync_command.sh
rename to src/sync_command.sh
diff --git a/autostart-manage/systemctl.sh b/src/systemctl.sh
similarity index 100%
rename from autostart-manage/systemctl.sh
rename to src/systemctl.sh
From db39cd30b23914d4c5ab2f450ac4c099e6a66fae Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Mon, 28 Oct 2024 21:01:39 +0100
Subject: [PATCH 08/10] Update run.sh
---
run.sh | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/run.sh b/run.sh
index 155b243..8125377 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 ./autostart-manage "$@"
From a69141f54246986c219253e774a8bad534dd572e Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Sat, 21 Dec 2024 15:03:24 +0100
Subject: [PATCH 09/10] Improve log parameters
---
src/log_command.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/log_command.sh b/src/log_command.sh
index 7d9657c..8f8f075 100644
--- a/src/log_command.sh
+++ b/src/log_command.sh
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
-journalctl --user -fu "autostart@${args[program]:?}.service"
+journalctl --user -b0 -fu "autostart@${args[program]:?}.service"
From 70558a4c779b055f411795c1b91c2aa5ff67c224 Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Mon, 24 Feb 2025 02:01:07 +0100
Subject: [PATCH 10/10] Add extra check for empty group
---
src/lib/colors.sh | 9 +++++++++
src/lib/common.sh | 18 +++++++++++-------
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/lib/colors.sh b/src/lib/colors.sh
index cbdc015..7458e2d 100644
--- a/src/lib/colors.sh
+++ b/src/lib/colors.sh
@@ -26,17 +26,26 @@ yellow() { print_in_color "\e[33m" "$*"; }
blue() { print_in_color "\e[34m" "$*"; }
magenta() { print_in_color "\e[35m" "$*"; }
cyan() { print_in_color "\e[36m" "$*"; }
+black() { print_in_color "\e[30m" "$*"; }
+white() { print_in_color "\e[37m" "$*"; }
+
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" "$*"; }
+black_bold() { print_in_color "\e[1;30m" "$*"; }
+white_bold() { print_in_color "\e[1;37m" "$*"; }
+
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" "$*"; }
+black_underlined() { print_in_color "\e[4;30m" "$*"; }
+white_underlined() { print_in_color "\e[4;37m" "$*"; }
diff --git a/src/lib/common.sh b/src/lib/common.sh
index 266c6e7..2f99562 100644
--- a/src/lib/common.sh
+++ b/src/lib/common.sh
@@ -9,13 +9,17 @@ _query_autostart_toml() {
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"
+ '.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 == ["*"]
+ ) and (.value.group != "")
+ )
+ ) | '"$1" \
+ "$XDG_CONFIG_HOME/autostart.toml"
}
_list () {