Skip to content

Commit

Permalink
WIP: setup-dns now functional again
Browse files Browse the repository at this point in the history
/ref #221

- `dorothy-workflow.yml`: add latest images
- `echo-mkdirp`: support quiet
- `setup-dns`: made mono-function again, and cleaned up code
- `setup-environment-commands`: add `STATE_DIR`
- `setup-util`: add `--installed` and `--uninstalled` aliases
- `setup-util-(adguard-home|cloudflared|dnscrypt-proxy)`: now just aliases for `setup-dns`
- `setup-util-plex` renamed to `setup-util-plex-media-server`
- `dns.json` move `about` before `url`, and remove `local` as that is a programmatic provider
  • Loading branch information
balupton committed Sep 26, 2024
1 parent ad51e12 commit 03c8de4
Show file tree
Hide file tree
Showing 11 changed files with 1,169 additions and 1,176 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dorothy-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
strategy:
fail-fast: false
matrix:
runner: [ubuntu-24.04, ubuntu-22.04, macos-14, macos-12]
runner: [ubuntu-24.04, ubuntu-22.04, macos-15, macos-14, macos-12]
# ubuntu-20.04 not supported, echo-wait fails: https://github.com/bevry/dorothy/actions/runs/9705310169/job/26787151094#step:2:1346
runs-on: ${{ matrix.runner }}
steps:
Expand All @@ -131,7 +131,7 @@ jobs:
strategy:
fail-fast: false
matrix:
runner: [macos-14, macos-12]
runner: [macos-15, macos-14, macos-12]
runs-on: ${{ matrix.runner }}
steps:
- name: 'Uninstall Homebrew'
Expand Down
27 changes: 13 additions & 14 deletions commands/echo-mkdir
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ function echo_mkdir() (
}

# process our own arguments, delegate everything else to stdinargs
local item option_sudo='no' option_args=()
local item option_sudo='no' option_args=() option_quiet
option_quiet="$(echo-quiet-enabled -- "$@")"
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--no-quiet'* | '--quiet'* | '--no-verbose'* | '--verbose'*) ;; # handled by echo-quiet-enabled
'--no-sudo'* | '--sudo'*)
option_sudo="$(get-flag-value --affirmative --fallback="$option_sudo" -- "$item")"
;;
Expand All @@ -56,27 +58,24 @@ function echo_mkdir() (
done

# construct command
local cmd=()
if test "$option_sudo" = 'yes'; then
cmd=(
'sudo-helper'
'--'
'mkdir'
'-p'
)
function __mkdir {
sudo-helper --reason="Your sudo/root/login password is required to make the directory: $*" -- mkdir -p "$@"
}
else
cmd=(
'mkdir'
'-p'
)
function __mkdir {
mkdir -p
}
fi

# =====================================
# Action

function on_line {
if test -d "$1" || ("${cmd[@]}" "$1"); then
fs-absolute -- "$1"
if test -d "$1" || __mkdir "$1"; then
if test "$option_quiet" != 'yes'; then
fs-absolute -- "$1"
fi
return 0
else
return 1
Expand Down
242 changes: 47 additions & 195 deletions commands/service-helper
Original file line number Diff line number Diff line change
Expand Up @@ -95,61 +95,19 @@ function service_helper() (

# process, @todo rewrite with option_ prefix
# don't use empty quiet, as that only outputs wraps
local item option_quiet services=() ignore='no' supported='' start='' stop='' restart='' unmask='' load='' unload='' enable='' disable='' reenable='' status='' logs='' running='' remove='' exists='' edit=''
local item option_quiet option_services=() option_ignore='no' option_supported='' option_actions=()
option_quiet="$(echo-quiet-enabled --fallback=no -- "$@")"
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--no-quiet'* | '--quiet'* | '--no-verbose'* | '--verbose'*) ;; # handled by echo-quiet-enabled
'--supported') supported='yes' ;;
'--ignore-missing' | '--ignore') ignore='yes' ;;
'--supported') option_supported='yes' ;;
'--ignore-missing' | '--ignore') option_ignore='yes' ;;
# service options
'--no-start'* | '--start'*)
start="$(get-flag-value --affirmative --fallback="$start" -- "$item")"
;;
'--no-stop'* | '--stop'*)
stop="$(get-flag-value --affirmative --fallback="$stop" -- "$item")"
;;
'--no-restart'* | '--restart'*)
restart="$(get-flag-value --affirmative --fallback="$restart" -- "$item")"
;;
'--no-unmask'* | '--unmask'*)
unmask="$(get-flag-value --affirmative --fallback="$unmask" -- "$item")"
;;
'--no-load'* | '--load'*)
load="$(get-flag-value --affirmative --fallback="$load" -- "$item")"
;;
'--no-unload'* | '--unload'*)
unload="$(get-flag-value --affirmative --fallback="$unload" -- "$item")"
;;
'--no-enable'* | '--enable'*)
enable="$(get-flag-value --affirmative --fallback="$enable" -- "$item")"
;;
'--no-disable'* | '--disable'*)
disable="$(get-flag-value --affirmative --fallback="$disable" -- "$item")"
;;
'--no-reenable'* | '--reenable'*)
reenable="$(get-flag-value --affirmative --fallback="$reenable" -- "$item")"
;;
'--no-status'* | '--status'*)
status="$(get-flag-value --affirmative --fallback="$status" -- "$item")"
;;
'--no-logs'* | '--logs'*)
logs="$(get-flag-value --affirmative --fallback="$logs" -- "$item")"
;;
'--no-running'* | '--running'*)
running="$(get-flag-value --affirmative --fallback="$running" -- "$item")"
;;
'--no-remove'* | '--remove'*)
remove="$(get-flag-value --affirmative --fallback="$remove" -- "$item")"
;;
'--no-exists'* | '--exists'*)
exists="$(get-flag-value --affirmative --fallback="$exists" -- "$item")"
;;
'--no-edit'* | '--edit'*)
edit="$(get-flag-value --affirmative --fallback="$edit" -- "$item")"
--(start|stop|restart|unmask|load|unload|enable|enable-now|disable|disable-now|reenable|status|logs|running|remove|exists|edit))
option_actions+=("${item#--}")
;;
'--')
services+=("$@")
Expand Down Expand Up @@ -460,7 +418,7 @@ function service_helper() (
test "${#paths[@]}" -ne 0
}
else
if test "$supported" = 'yes'; then
if test "$option_supported" = 'yes'; then
# if --supported, no error message
return 1
else
Expand All @@ -470,7 +428,7 @@ function service_helper() (
fi

# if --supported, then we are done
if test "$supported" = 'yes'; then
if test "$option_supported" = 'yes'; then
return 0
fi

Expand All @@ -488,10 +446,10 @@ function service_helper() (
# https://man.archlinux.org/man/systemctl.1.en
# https://wiki.gentoo.org/wiki/OpenRC_to_systemd_Cheatsheet
function handle {
local this_service="$1" this_unmask="$unmask" this_load="$load" this_unload="$unload" this_start="$start" this_stop="$stop" this_restart="$restart" this_enable="$enable" this_disable="$disable" this_reenable="$reenable" this_status="$status" this_logs="$logs" this_running="$running" this_remove="$remove" this_exists="$exists" this_edit="$edit"
local this_service="$1" this_action=''

# ignore?
if test "$ignore" = 'yes' && ! __do_exists "$this_service"; then
if test "$option_ignore" = 'yes' && ! __do_exists "$this_service"; then
# is missing, and desire to ignore, so skip this one
if test "$option_quiet" = 'no'; then
echo-style \
Expand All @@ -501,150 +459,44 @@ function service_helper() (
return 0
fi

# exists?
if test "$this_exists" = 'yes'; then
this_exists=''
__do_exists "$this_service"
fi

# edit?
if test "$this_edit" = 'yes'; then
this_edit=''
do_edit "$this_service"
fi

# remove?
if test "$this_remove" = 'yes'; then
this_remove=''
do_remove "$this_service"
fi

# status
if test "$this_status" = 'yes'; then
this_status='maybe'
do_status "$this_service"
fi

# unmask, do before load
if test "$this_unmask" = 'yes'; then
this_unmask=''
do_unmask "$this_service"

# renable status
if test "$this_status" = 'maybe'; then
this_status='yes'
fi
fi

# load
if test "$this_load" = 'yes'; then
this_load=''
do_load "$this_service"

# renable status
if test "$this_status" = 'maybe'; then
this_status='yes'
fi
fi

# split restart if autostart is being modified
if test "$this_restart" = 'yes' && test "$this_reenable" = 'yes' -o "$this_enable" = 'yes' -o "$this_disable" = 'yes'; then
this_restart=''
this_stop='yes'
this_start='yes'
fi

# stop
if test "$this_stop" = 'yes'; then
this_stop=''
do_stop "$this_service"

# renable status
if test "$this_status" = 'maybe'; then
this_status='yes'
fi
fi

# autostart
if test "$this_reenable" = 'yes'; then
this_reenable=''
do_reenable "$this_service"

# renable status
if test "$this_status" = 'maybe'; then
this_status='yes'
fi
elif test "$this_enable" = 'yes'; then
this_enable=''
if test "$this_start" = 'yes'; then
this_start=''
do_enable_now "$this_service"
else
do_enable "$this_service"
fi

# renable status
if test "$this_status" = 'maybe'; then
this_status='yes'
fi
elif test "$this_disable" = 'yes'; then
this_disable=''
if test "$this_stop" = 'yes'; then
this_stop=''
do_disable_no "$this_service"
else
do_disable "$this_service"
fi

# renable status
if test "$this_status" = 'maybe'; then
this_status='yes'
fi
fi

# start / restart
if test "$this_start" = 'yes'; then
this_start=''
do_start "$this_service"

# renable status
if test "$this_status" = 'maybe'; then
this_status='yes'
fi
fi
if test "$this_restart" = 'yes'; then
this_restart=''
do_restart "$this_service"

# renable status
if test "$this_status" = 'maybe'; then
this_status='yes'
fi
fi

# unload
if test "$this_unload" = 'yes'; then
this_unload=''
do_unload "$this_service"
fi

# status
if test "$this_status" = 'yes'; then
this_status=''
do_status "$this_service"
fi

# logs
if test "$this_logs" = 'yes'; then
this_logs=''
do_logs "$this_service"
fi

# running
if test "$this_running" = 'yes'; then
this_running=''
do_running "$this_service"
fi
# actions
for this_action in "${option_actions[@]}"; do
case "$this_action" in
'exists')
test "$option_ignore" = 'yes'; then
return 0 # we already know from earlier
else
__do_exists "$this_service"
fi
;;
'edit') do_edit "$this_service" ;;
'remove') do_remove "$this_service" ;;
'status') do_status "$this_service" ;;
# unmask before load
'unmask') do_unmask "$this_service" ;;
# load before stops
'load') do_load "$this_service" ;;
# do stop, starts, before unload
'stop') do_stop "$this_service" ;;
'reenable') do_reenable "$this_service" ;;
'enable') do_enable "$this_service" ;;
'disable') do_disable "$this_service" ;;
# do enable/disable starts stops
'enable-now') do_enable_now "$this_service" ;;
'disable-now') do_disable_now "$this_service" ;;
# do starts
'start') do_start "$this_service" ;;
# if any of reenable/disable/enable, then restart should be changed to stop and start
'restart') do_restart "$this_service" ;;
# do unload
'unload') do_unload "$this_service" ;;
'status') do_status "$this_service" ;;
'logs') do_logs "$this_service" ;;
# do running
'running') do_running "$this_service" ;;
*) help "An unrecognised action was provided: $this_action" ;;
esac
done
}

# cycle through
Expand Down
Loading

0 comments on commit 03c8de4

Please sign in to comment.