Compare commits

..

8 commits
v0.1.2 ... main

Author SHA1 Message Date
Tobias Reisinger 67fed76c68
Add faster group-detection in autoinstall (dynamic groups are now impossible)
Allow for absolute paths in autoinstall exe
Add timer in run.sh
2024-06-21 22:35:59 +02:00
Tobias Reisinger 2aa4ae8b58
Fix wrong starting line (was for debugging) 2024-05-23 18:28:10 +02:00
Tobias Reisinger 1b891407a3
Allow source to be evaluated only when group is matched 2024-05-14 12:20:10 +02:00
Tobias Reisinger aed681d0b0
Improve error handling in autoinstall run 2024-05-13 15:01:21 +02:00
Tobias Reisinger e81f5ab4da
Improve run command to remove tomlq depedency
All checks were successful
/ build-artifacts (autoinstall) (push) Successful in 25s
/ build-artifacts (autostart-manage) (push) Successful in 15s
/ upload-release (push) Successful in 19s
2024-05-13 13:58:40 +02:00
Tobias Reisinger cadb8e01d0
Add autoinstall flatpak 2024-05-12 23:50:11 +02:00
Tobias Reisinger 790f3e8039
Add systemd file generation to autostart-manage 2024-03-27 18:58:31 +01:00
Tobias Reisinger 5dbdf3d311
Add some improvements 2024-03-22 22:14:13 +01:00
9 changed files with 138 additions and 22 deletions

View file

@ -1,6 +1,6 @@
name: autoinstall name: autoinstall
help: Install files, repository and else help: Install files, repository and else
version: 0.1.2 version: 0.1.3
flags: flags:
- long: --clean - long: --clean
@ -30,6 +30,12 @@ commands:
- name: group - name: group
required: true required: true
help: The group to install 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 - name: git
help: Install a git repository help: Install a git repository
@ -109,3 +115,13 @@ commands:
- name: target - name: target
required: true required: true
help: The path to write the result to 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)

View file

@ -2,8 +2,8 @@
action=${action:?} action=${action:?}
# if action is run or completions, do nothing # do nothing on some selected actions
if [ "$action" = "run" ] || [ "$action" = "completions" ] if [ "$action" = "completions" ] || [ "$action" = "flatpak" ] || [ "$action" = "run" ]
then then
return return
fi fi
@ -19,5 +19,12 @@ fi
if [ -n "$clean" ] || [ -n "${AUTOINSTALL_CLEAN:-}" ] if [ -n "$clean" ] || [ -n "${AUTOINSTALL_CLEAN:-}" ]
then then
echo "Cleaning $target" echo "Cleaning $target"
# sanity checks
if [ -z "$target" ] || [ "$target" = "/" ] || [ "$target" = "$HOME" ] || [ "$target" = "$HOME/" ]
then
echo "Invalid target: '$target'"
exit 1
fi
rm -rf "$target" rm -rf "$target"
fi fi

View file

@ -5,7 +5,7 @@ completions=${args[--completions]:-}
target=${args[target]:?} target=${args[target]:?}
url=${args[url]:?} url=${args[url]:?}
if [ "${action:-file}" = "exe" ] if [ "${action:-file}" = "exe" ] && ! echo "$target" | grep -q "/"
then then
if [ -x "$(command -v "$target")" ] if [ -x "$(command -v "$target")" ]
then then
@ -16,7 +16,7 @@ then
fi fi
if [ ! -f "$target" ] if [ ! -e "$target" ]
then then
echo "Installing file $url to $target" echo "Installing file $url to $target"

View file

@ -0,0 +1,13 @@
#!/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

View file

@ -1,24 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
group=${args[group]:?} group=${args[group]:?}
file=${args[--file]:-}
clean=${args[--clean]:-} clean=${args[--clean]:-}
_config_query() { _install_entry() {
tomlq -c --arg group "$group" \ type="$1"
'.autoinstall | map(select(.groups + ["all"] | contains([$group]))) | '"$1" \ source="$2"
"$XDG_CONFIG_HOME/autoinstall.toml" target="$3"
} hook="$4"
pipe="$5"
completions="$6"
_config_query ".[]" | while read -r entry; do
install_args=() install_args=()
type=$(echo "$entry" | jq -r '.type')
source=$(echo "$entry" | jq -r '.source')
target=$(echo "$entry" | jq -r '.target')
hook=$(echo "$entry" | jq -r '.hook // ""')
pipe=$(echo "$entry" | jq -r '.pipe // ""')
completions=$(echo "$entry" | jq -r '.completions // ""')
if [[ -n "$hook" ]]; then if [[ -n "$hook" ]]; then
install_args+=("--hook=$hook") install_args+=("--hook=$hook")
fi fi
@ -43,5 +38,51 @@ _config_query ".[]" | while read -r entry; do
install_args+=("$(eval "echo $target")") install_args+=("$(eval "echo $target")")
autoinstall "${install_args[@]}" "$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 done

View file

@ -1,6 +1,6 @@
name: autostart-manage name: autostart-manage
help: Manage autostart help: Manage autostart
version: 0.1.2 version: 0.1.3
dependencies: dependencies:
tomlq: please install yq (https://github.com/kislyuk/yq) tomlq: please install yq (https://github.com/kislyuk/yq)

View file

@ -0,0 +1,11 @@
#!/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

View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
_deploy_service_file() {
cat <<EOF > "$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 <<EOF > "$1"
[Unit]
Description=Current graphical user session
Documentation=man:systemd.special(7)
RefuseManualStart=no
StopWhenUnneeded=no
EOF
}

4
run.sh
View file

@ -6,4 +6,6 @@ target=$(cat .target)
make generate make generate
"./output/$target" "$@" printf "\nBuild complete. Running...\n==========================\n\n"
time "./output/$target" "$@"