parent
							
								
									ab7c74f888
								
							
						
					
					
						commit
						6222075b6f
					
				
					 32 changed files with 18 additions and 530 deletions
				
			
		
							
								
								
									
										111
									
								
								src/bashly.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								src/bashly.yml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,111 @@
 | 
			
		|||
name: autostart-manage
 | 
			
		||||
help: Manage autostart
 | 
			
		||||
version: 0.1.4
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
							
								
								
									
										11
									
								
								src/before.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/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
 | 
			
		||||
							
								
								
									
										3
									
								
								src/completions_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/completions_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
send_completions
 | 
			
		||||
							
								
								
									
										6
									
								
								src/exec_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/exec_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
program=${args[program]:?}
 | 
			
		||||
 | 
			
		||||
sleep "$(_get_autostart_delay "$program")"
 | 
			
		||||
bash -c "$(_get_autostart_cmd "$program")"
 | 
			
		||||
							
								
								
									
										9
									
								
								src/info_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/info_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
#!/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'
 | 
			
		||||
							
								
								
									
										42
									
								
								src/lib/colors.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/lib/colors.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,42 @@
 | 
			
		|||
## 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" "$*"; }
 | 
			
		||||
							
								
								
									
										77
									
								
								src/lib/common.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								src/lib/common.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,77 @@
 | 
			
		|||
#!/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' "*"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										26
									
								
								src/lib/systemd_files.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/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
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								src/list_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/list_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
_list "*"
 | 
			
		||||
							
								
								
									
										3
									
								
								src/log_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/log_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
journalctl --user -fu "autostart@${args[program]:?}.service"
 | 
			
		||||
							
								
								
									
										3
									
								
								src/run_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/run_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
systemctl --user start autostart.target
 | 
			
		||||
							
								
								
									
										5
									
								
								src/run_wayland_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/run_wayland_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
_autostart_run_graphical
 | 
			
		||||
 | 
			
		||||
killall -SIGUSR2 waybar
 | 
			
		||||
							
								
								
									
										12
									
								
								src/run_xorg_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/run_xorg_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,12 @@
 | 
			
		|||
#!/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
 | 
			
		||||
							
								
								
									
										11
									
								
								src/sync_command.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/sync_command.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
#!/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[@]}"
 | 
			
		||||
							
								
								
									
										9
									
								
								src/systemctl.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/systemctl.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
#!/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[@]}"
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue