From ac1f67fe553f23c033f667f80118d68f59ec5f1c Mon Sep 17 00:00:00 2001 From: B Stack Date: Fri, 10 Jan 2020 13:32:23 -0500 Subject: WIP: initial commit, 5% done --- src/bin/systemctl | 280 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100755 src/bin/systemctl (limited to 'src/bin/systemctl') diff --git a/src/bin/systemctl b/src/bin/systemctl new file mode 100755 index 0000000..2f3201e --- /dev/null +++ b/src/bin/systemctl @@ -0,0 +1,280 @@ +#!/bin/sh +# Filename: systemctl +# Location: +# Author: bgstack15@gmail.com +# Startdate: 2020-01-10 13:02:14 +# Title: +# Purpose: +# Package: systemdtl +# History: +# Usage: +# Reference: ftemplate.sh 2019-05-02a ; framework.sh 2018-05-02a +# Improve: +fiversion="2019-05-02a" +systemctlversion="2020-01-10a" + +usage() { + ${PAGER:-/usr/bin/less -F} >&2 </dev/null + + # Delayed cleanup + if test -z "${SYSTEMCTL_NO_CLEAN}" ; + then +# nohup /bin/bash </dev/null 2>&1 & +#sleep "${SYSTEMCTL_CLEANUP_SEC:-300}" ; /bin/rm -r "${SYSTEMCTL_TMPDIR:-NOTHINGTODELETE}" 1>/dev/null 2>&1 ; +#EOF + /bin/rm -r "${SYSTEMCTL_TMPDIR:-NOTHINGTODELETE}" 1>/dev/null 2>&1 ; + fi +} + +CTRLC() { + # use with: trap "CTRLC" 2 + # useful for controlling the ctrl+c keystroke + : +} + +CTRLZ() { + # use with: trap "CTRLZ" 18 + # useful for controlling the ctrl+z keystroke + : +} + +parseFlag() { + flag="$1" + hasval=0 + case ${flag} in + # INSERT FLAGS HERE + "d" | "debug" | "DEBUG" | "dd" ) setdebug ; ferror "debug level ${debug}" ; __debug_set_by_param=1 ;; + "u" | "usage" | "help" | "h" ) usage ; exit 1 ;; + "V" | "fcheck" | "version" ) ferror "${scriptfile} version ${systemctlversion}" ; exit 1 ;; + #"i" | "infile" | "inputfile" ) getval ; infile1=${tempval} ;; + "c" | "conf" | "conffile" | "config" ) getval ; conffile="${tempval}" ;; + "now" ) export SYSTEMCTL_NOW=1 ;; + "full") export SYSTEMCTL_FULL=1 ;; + "system") export SYSTEMCTL_SYSTEM=1 ;; + esac + + debuglev 10 && { test ${hasval} -eq 1 && ferror "flag: ${flag} = ${tempval}" || ferror "flag: ${flag}" ; } +} + +# DETERMINE LOCATION OF FRAMEWORK +f_needed=20181030 +___frameworkpath="$( find $( echo "${FRAMEWORKPATH}" | tr ':' ' ' ) -maxdepth 1 -mindepth 0 -name 'framework.sh' 2>/dev/null )" +while read flocation ; do if test -e ${flocation} ; then __thisfver="$( sh ${flocation} --fcheck 2>/dev/null )" ; if test ${__thisfver:-0} -ge ${f_needed} ; then frameworkscript="${flocation}" ; break ; elif test -n "${___thisfver}" ; then printf "Obsolete: %s %s\n" "${flocation}" "${__thisfver}" 1>&2 ; fi ; fi ; done <&2 && exit 4 + +# INITIALIZE VARIABLES +# variables set in framework: +# today server thistty scriptdir scriptfile scripttrim +# is_cronjob stdin_piped stdout_piped stderr_piped sendsh sendopts +. ${frameworkscript} || echo "$0: framework did not run properly. Continuing..." 1>&2 +infile1= +outfile1= +logfile=/var/log/systemctl.log +define_if_new interestedparties "bgstack15@gmail.com" +# SIMPLECONF +#define_if_new default_conffile "/etc/systemctl/systemctl.conf" +#define_if_new defuser_conffile ~/.config/systemctl/systemctl.conf +#define_if_new SYSTEMCTL_TMPDIR "$( mktemp -d )" +#tmpfile1="$( TMPDIR="${SYSTEMCTL_TMPDIR}" mktemp )" +#tmpfile2="$( TMPDIR="${SYSTEMCTL_TMPDIR}" mktemp )" + +# REACT TO OPERATING SYSTEM TYPE +case $( uname -s ) in + Linux) : ;; + FreeBSD) : ;; + *) echo "${scriptfile}: 3. Indeterminate OS: $( uname -s )" 1>&2 && exit 3 ;; +esac + +## REACT TO ROOT STATUS +#case ${is_root} in +# 1) # proper root +# : ;; +# sudo) # sudo to root +# : ;; +# "") # not root at all +# #ferror "${scriptfile}: 5. Please run as root or sudo. Aborted." +# #exit 5 +# : +# ;; +#esac + +# SET CUSTOM SCRIPT AND VALUES +#setval 1 sendsh sendopts<&2 +} + +# MAIN LOOP +#{ + #printf "%s\n" "${*}" >> "${logfile}" + #echo "thiscount=${thiscount}" + #x=1 + #while test ${x:-${thiscount}} -le $(( thiscount - 1 )) && test ${thiscount} -gt 1 ; + #do + # eval thisopt="\${opt${x}}" + # echo "thisopt${x}=${thisopt}" + # x=$(( x + 1 )) + #done + + # actions + actionlist="" + case "${action}" in + start|stop|status) + x=1 + while test ${x:-${thiscount}} -le $(( thiscount - 1 )) && test ${thiscount} -gt 1 ; + do + eval thisopt="\${opt${x}}" + thisopt="$( echo "${thisopt}" | sed -r -e 's/\.service$//;' )" + actionstatement="$( printf "%s" "service ${thisopt} ${action};" )" + actionlist="${actionlist:+${actionlist} }${actionstatement}" + x=$(( x + 1 )) + done + ;; + enable|disable) + # action should be update-rc.d ${thisopt} ${action} + echo "WORK IN PROGRESS" + ;; + *) + ferror "Fatal! 2. Unable to understand action ${action}. Aborted." + ;; + esac + + # list of actions + echo "Need to perform these commands:" + echo "${actionlist}" +#} | tee -a ${logfile} + +# EMAIL LOGFILE +#${sendsh} ${sendopts} "${server} ${scriptfile} out" ${logfile} ${interestedparties} + +## STOP THE READ CONFIG FILE +#return_code 0 +#fi ; done ; } -- cgit