Compare commits
15 commits
Author | SHA1 | Date | |
---|---|---|---|
Tobias Reisinger | 67fed76c68 | ||
Tobias Reisinger | 2aa4ae8b58 | ||
Tobias Reisinger | 1b891407a3 | ||
Tobias Reisinger | aed681d0b0 | ||
Tobias Reisinger | e81f5ab4da | ||
Tobias Reisinger | cadb8e01d0 | ||
Tobias Reisinger | 790f3e8039 | ||
Tobias Reisinger | 5dbdf3d311 | ||
Tobias Reisinger | c5316e8318 | ||
Tobias Reisinger | ef3602167e | ||
Tobias Reisinger | 056b7fc89e | ||
Tobias Reisinger | 7934e32b27 | ||
Tobias Reisinger | 6003e52c8a | ||
Tobias Reisinger | 5cc3d5144d | ||
Tobias Reisinger | 6c2eeb4c9b |
2
.envrc
2
.envrc
|
@ -1,3 +1,3 @@
|
||||||
use nix
|
use nix
|
||||||
|
|
||||||
printf '\nPlease set and export $BASHLY_SOURCE_DIR\n\n'
|
export BASHLY_SOURCE_DIR=$(cat .target)
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
.target
|
.target
|
||||||
output/
|
output/
|
||||||
|
|
||||||
|
autoinstall/lib/send_completions.sh
|
||||||
autostart-manage/lib/send_completions.sh
|
autostart-manage/lib/send_completions.sh
|
||||||
|
|
12
Makefile
12
Makefile
|
@ -8,19 +8,15 @@ get-target:
|
||||||
output-dir:
|
output-dir:
|
||||||
mkdir -p ./output
|
mkdir -p ./output
|
||||||
|
|
||||||
generate: get-target output-dir
|
completions: get-target
|
||||||
BASHLY_SOURCE_DIR=$(TARGET) bashly generate
|
BASHLY_SOURCE_DIR=$(TARGET) bashly add completions
|
||||||
|
|
||||||
generate-upgrade: get-target output-dir
|
generate: get-target output-dir completions
|
||||||
BASHLY_SOURCE_DIR=$(TARGET) bashly generate --upgrade
|
BASHLY_SOURCE_DIR=$(TARGET) bashly generate --upgrade
|
||||||
|
|
||||||
completions: generate-upgrade
|
|
||||||
BASHLY_SOURCE_DIR=$(TARGET) bashly add --force completions_script ./output/_$(TARGET)
|
|
||||||
|
|
||||||
docs: generate
|
docs: generate
|
||||||
BASHLY_SOURCE_DIR=$(TARGET) bashly render :mandoc ./output/man1
|
BASHLY_SOURCE_DIR=$(TARGET) bashly render :mandoc ./output/man1
|
||||||
|
|
||||||
deploy: completions docs
|
deploy: generate docs
|
||||||
cp -f ./output/$(TARGET) ~/.local/bin/
|
cp -f ./output/$(TARGET) ~/.local/bin/
|
||||||
cp -f ./output/_$(TARGET) ~/.config/completionsrc.d/
|
|
||||||
cp -f ./output/man1/$(TARGET)*.1 ~/.local/share/man/man1/
|
cp -f ./output/man1/$(TARGET)*.1 ~/.local/share/man/man1/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: autoinstall
|
name: autoinstall
|
||||||
help: Install files, repository and else
|
help: Install files, repository and else
|
||||||
version: 0.1.0
|
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
|
||||||
|
@ -73,6 +79,10 @@ commands:
|
||||||
help: Pipe file through command (e.g. "tar xzO")
|
help: Pipe file through command (e.g. "tar xzO")
|
||||||
arg: pipe
|
arg: pipe
|
||||||
default: cat
|
default: cat
|
||||||
|
- long: --completions
|
||||||
|
short: -c
|
||||||
|
help: Run a command on the new exe to install completions
|
||||||
|
arg: completions
|
||||||
|
|
||||||
- name: archive
|
- name: archive
|
||||||
help: Install an archive
|
help: Install an archive
|
||||||
|
@ -105,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)
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [ "${action:?}" = "run" ]
|
action=${action:?}
|
||||||
|
|
||||||
|
# do nothing on some selected actions
|
||||||
|
if [ "$action" = "completions" ] || [ "$action" = "flatpak" ] || [ "$action" = "run" ]
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -8,7 +11,7 @@ fi
|
||||||
clean=${args[--clean]:-}
|
clean=${args[--clean]:-}
|
||||||
target=${args[target]:?}
|
target=${args[target]:?}
|
||||||
|
|
||||||
if [ "${action:?}" = "exe" ]
|
if [ "$action" = "exe" ]
|
||||||
then
|
then
|
||||||
target="$HOME/.local/bin/$target"
|
target="$HOME/.local/bin/$target"
|
||||||
fi
|
fi
|
||||||
|
@ -16,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
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
pipe=${args[--pipe]:?}
|
pipe=${args[--pipe]:?}
|
||||||
|
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
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
exe=$target
|
||||||
target="$HOME/.local/bin/$target"
|
target="$HOME/.local/bin/$target"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ ! -f "$target" ]
|
if [ ! -e "$target" ]
|
||||||
then
|
then
|
||||||
echo "Installing file $url to $target"
|
echo "Installing file $url to $target"
|
||||||
|
|
||||||
|
@ -27,6 +29,16 @@ then
|
||||||
if [ "${action:-file}" = "exe" ]
|
if [ "${action:-file}" = "exe" ]
|
||||||
then
|
then
|
||||||
chmod +x "$target"
|
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
|
fi
|
||||||
|
|
||||||
_run_hook
|
_run_hook
|
||||||
|
|
13
autoinstall/flatpak_command.sh
Normal file
13
autoinstall/flatpak_command.sh
Normal 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
|
|
@ -1,32 +1,34 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
group=${args[group]:?}
|
group=${args[group]:?}
|
||||||
|
file=${args[--file]:-}
|
||||||
|
clean=${args[--clean]:-}
|
||||||
|
|
||||||
_config_query() {
|
_install_entry() {
|
||||||
tomlq -c --arg group "$group" \
|
type="$1"
|
||||||
'.autoinstall | map(select(.group == $group)) | '"$1" \
|
source="$2"
|
||||||
"$XDG_CONFIG_HOME/autoinstall.toml"
|
target="$3"
|
||||||
}
|
hook="$4"
|
||||||
|
pipe="$5"
|
||||||
|
completions="$6"
|
||||||
|
|
||||||
#length=$(_config_query "length")
|
|
||||||
_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 // ""')
|
|
||||||
|
|
||||||
if [[ -n "$hook" ]]; then
|
if [[ -n "$hook" ]]; then
|
||||||
install_args+=("--hook=$hook")
|
install_args+=("--hook=$hook")
|
||||||
fi
|
fi
|
||||||
|
if [[ -n "$clean" ]]; then
|
||||||
|
install_args+=("--clean")
|
||||||
|
fi
|
||||||
|
|
||||||
install_args+=("$type")
|
install_args+=("$type")
|
||||||
|
|
||||||
if [[ -n "$pipe" ]]; then
|
if [[ -n "$pipe" ]]; then
|
||||||
install_args+=("--pipe=$pipe")
|
install_args+=("--pipe=$pipe")
|
||||||
fi
|
fi
|
||||||
|
if [[ -n "$completions" ]]; then
|
||||||
|
install_args+=("--completions=$completions")
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $source = \$* ]]
|
if [[ $source = \$* ]]
|
||||||
then
|
then
|
||||||
|
@ -36,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
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: autostart-manage
|
name: autostart-manage
|
||||||
help: Manage autostart
|
help: Manage autostart
|
||||||
version: 0.1.0
|
version: 0.1.3
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
tomlq: please install yq (https://github.com/kislyuk/yq)
|
tomlq: please install yq (https://github.com/kislyuk/yq)
|
||||||
|
|
11
autostart-manage/before.sh
Normal file
11
autostart-manage/before.sh
Normal 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
|
|
@ -41,10 +41,24 @@ _autostart_run_graphical () {
|
||||||
_echo_table () {
|
_echo_table () {
|
||||||
for unit in "$@"
|
for unit in "$@"
|
||||||
do
|
do
|
||||||
|
if _systemctl "$unit" is-enabled --quiet
|
||||||
|
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" \
|
printf "%s\t%s\t%s\t%s\n" \
|
||||||
"$unit" \
|
"$unit" \
|
||||||
"$(_systemctl "$unit" is-enabled)" \
|
"$_enabled" \
|
||||||
"$(_systemctl "$unit" is-active)" \
|
"$_active" \
|
||||||
"$(_get_autostart_cmd "$unit")"
|
"$(_get_autostart_cmd "$unit")"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
26
autostart-manage/lib/systemd_files.sh
Normal file
26
autostart-manage/lib/systemd_files.sh
Normal 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
|
||||||
|
}
|
Loading…
Reference in a new issue