diff options
Diffstat (limited to 'lib/util.bash')
-rw-r--r-- | lib/util.bash | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/lib/util.bash b/lib/util.bash index 32d61c6..72a41a8 100644 --- a/lib/util.bash +++ b/lib/util.bash @@ -187,13 +187,11 @@ pkg() { local system="bashtard/pkg" local action=$1 ; shift - local app="$(config "pkg.$1" "$(config "app.$1")")" ; shift + local pkg="$(config "pkg.$1")" ; shift - local type - - if [[ -z $app ]] + if [[ -z $pkg ]] then - crit "$system" "No package name for $app" + crit "$system" "No package name for $pkg" return 1 fi @@ -203,7 +201,7 @@ pkg() { return 1 fi - "pkg_$action" "$app" + "pkg_$action" "$pkg" } pkg_install() { @@ -214,7 +212,26 @@ pkg_install() { case "${BASHTARD_PLATFORM[key]}" in freebsd) set -- /usr/sbin/pkg install -y "$app" ;; linux-debian*) set -- apt install -y "$app" ;; - linux-gentoo) set -- emerge --ask=n "$app" ;; + linux-gentoo) set -- emerge --ask=n --update "$app" ;; + *) + crit "$system" "No package manager configured for ${BASHTARD_PLATFORM[key]}" + return 1 + ;; + esac + + notice "$system" "$*" + $@ +} + +pkg_uninstall() { + local system="bashtard/pkg/uninstall" + + local app=$1 ; shift + + case "${BASHTARD_PLATFORM[key]}" in + freebsd) set -- /usr/sbin/pkg uninstall -y "$app" ;; + linux-debian*) set -- apt remove -y "$app" ;; + linux-gentoo) set -- emerge --ask=n --unmerge "$app" ;; *) crit "$system" "No package manager configured for ${BASHTARD_PLATFORM[key]}" return 1 @@ -232,8 +249,8 @@ svc() { local service local action - service="$(config svc.$1)" ; shift action=$1 ; shift + service="$(config svc.$1)" ; shift if [[ -z $service ]] then @@ -250,6 +267,23 @@ svc() { "svc_$action" "$service" } +svc_disable() { + local system="bashtard/svc/disable" + + local service=$1 + + case "${BASHTARD_PLATFORM[key]}" in + linux-gentoo) set -- /sbin/rc-update del "$service" ;; + linux-*) set -- systemctl disable "$service" ;; + *) + crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + return 1 + esac + + notice "$system" "$*" + $@ +} + svc_enable() { local system="bashtard/svc/enable" @@ -267,6 +301,24 @@ svc_enable() { $@ } +svc_reload() { + local system="bashtard/svc/reload" + + local service=$1 + + case "${BASHTARD_PLATFORM[key]}" in + freebsd) set -- service "$service" reload ;; + linux-gentoo) set -- /sbin/rc-service "$service" reload ;; + linux-*) set -- systemctl reload "$service" ;; + *) + crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + return 1 + esac + + notice "$system" "$*" + $@ +} + svc_restart() { local system="bashtard/svc/restart" @@ -303,9 +355,27 @@ svc_start() { $@ } -template() +svc_stop() { + local system="bashtard/svc/stop" + + local service=$1 + + case "${BASHTARD_PLATFORM[key]}" in + freebsd) set -- service "$service" stop ;; + linux-gentoo) set -- /sbin/rc-service "$service" stop ;; + linux-*) set -- systemctl stop "$service" ;; + *) + crit "$system" "No service manager configured for ${BASHTARD_PLATFORM[key]}" + return 1 + esac + + notice "$system" "$*" + $@ +} + +file_template() { - local file="$BASEDIR/etc/templates/$1" ; shift + local file="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/share/$1" ; shift local sedfile="$(tmpfile)" if [[ ! -f $file ]] |