aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorziggys <ziggys@autistici.org>2018-05-20 17:36:15 -0300
committerziggys <ziggys@autistici.org>2018-05-20 21:19:16 -0300
commit60afa4f42e1a60fa7b80a5846a48f85d81141bbd (patch)
treeb552126e5b24c098f4b3377104fa07aa2ce64245
parentda4ea7afb0ac16614eb7c105972fcf0f8bebba29 (diff)
downloadpupm-60afa4f42e1a60fa7b80a5846a48f85d81141bbd.tar
pupm-60afa4f42e1a60fa7b80a5846a48f85d81141bbd.zip
Release 3.0.0
-rw-r--r--README.txt23
-rwxr-xr-xpupm.sh164
2 files changed, 66 insertions, 121 deletions
diff --git a/README.txt b/README.txt
index cd1a2e3..259cdfb 100644
--- a/README.txt
+++ b/README.txt
@@ -1,30 +1,29 @@
Properly Update Prosody Modules
-Simply update core and community prosody xmpp server modules to last version from mercurial
-official modules repository (https://hg.prosody.im/prosody-modules).
+Simply update core and community prosody xmpp server modules to last version
+in official modules repository (https://hg.prosody.im/prosody-modules).
-Change variables in pupm.config according to your enviroment. Run the script:
+Download the script into your localhost and execute (need root access).
-./pupm.sh
+Run it:
-Or parse variables as flags from commandline
+./pupm.sh <config>
-./pupm.sh [OPTIONS] <args> ...
+./pupm.sh pupm.config
-Examples:
-./pupm.sh -c other.confit will use another file to parse variables
+Run it with no arguments for help.
-./pupm.sh -d /srv/prosody/modules will use <path> as 'MODULEPATH'
-
-
-Run: ./pupm.sh -h to learn about
+Config example is provided within repository
STDOUT and STDERR will be logged in '/tmp/pupm.log'. Cronjob can be configued
easyly. Use '/tmp/pupm.log' as inputfile for sending notifications with
appropiate tools.
+# TODO
+# check syntax
+# define default for empty vars
diff --git a/pupm.sh b/pupm.sh
index 843da55..1e91039 100755
--- a/pupm.sh
+++ b/pupm.sh
@@ -6,13 +6,13 @@
# License BSD 2.0 (3-Clause)
# scriptinfo
-VERSION='2.0.2' # Parse variables from commandline
+VERSION='3.0.0' # Make it simpler - 3.0.0
AUTHOR="ziggys"
-CYEAR=`date +%Y`
-COPYRIGHT="${CYEAR} by ${AUTHOR}"
+CYEAR=$(date +%Y)
+COPYRIGHT="${CYEAR} by ${AUHTOR}"
-# usage
-usage (){
+# usash
+usage () {
test $# = 0 || echo $@
echo "$0 version ${VERSION}"
echo "Copyright (C) ${COPYRIGHT}"
@@ -22,125 +22,71 @@ echo "are welcome to redistribute it under certain conditions. See the BSD 2.0"
echo "license for details"
echo
echo "$0 is a simply shellscript for properly update prosody modules"
-echo
-echo "Usage $0 # With no options/args the script"
-echo " # will use variables from default"
-echo " # configuration file (pupm.config)"
echo
-echo "Usage: $0 [OPTIONS] <args> ... # Using options and args to parse"
-echo" # custom variables from commandline"
+echo "Usage: $0 <configfile>"
echo
-echo "Options"
-echo " Parse <args> from commandline as custom variables."
-echo " See Configuration File to learn syntax."
+echo "Usage: $0 pupm.config"
echo
-echo " -d <path> # 'MODULESPATH'"
-echo " -o <user> # 'DIROWNER'"
-echo " -g <group> # 'DIRGROUP'"
-echo " -p <ABC> # 'DIRPERMISSIONS'"
-echo " -r yes | no # 'RELOAD'"
-echo " -s service | runit | systemd # 'SYSTEMINIT'"
-echo " -c <path>/<file> # 'INPUTFILE' or Configuration File"
-echo " -h HELP # Print this help and exit"
-echo
-echo "Example:"
-echo "./pupm.sh -d /home/me/otherpupm.config -g root -p 751 -r yes"
-echo
-echo "The script will be executed reading options from otherpupm.config and"
-echo "will override group with root, permissions with 751 and reload with yes"
-echo "As seen, anyway possible, when '-c file.config' is used, other options are not"
-echo "parsed for obvious reasons."
-echo
-echo "Configuration File"
-echo " pupm.config is provided as example"
-echo
-echo " MODULESPATH <path> # Path to prosody modules. If empty, will default to /usr/lib/prosody/modules"
-echo " DIROWNER <user> # 'MODULESPATH' owner. If empty... root"
-echo " DIRGROUP <group> # 'MODULESPATH' group. If empty... prosody"
-echo " DIRPERMISSIONS <ABC> # 'MODULESPATH' permissions in octal. If empty... 750"
-echo " RELOAD yes | no # yes: reload prosody modules using 'prosodyctl reload'"
-echo " # no: restart prosody service (as 'service prosody restart')"
-echo " # If empty... no"
-echo " SYSTEMINIT service | runit | systemd # service: for sysv, openrc and similar"
-echo " # runit: for void and similar"
-echo " # systemd: if you are stupid enough"
-echo " # If empty... service"
exit $?
-
}
-# service restart
-service_restart () {
- case ${SYSTEMINIT} in
- service) service prosody restart >> /tmp/pupm.log 2>&1;;
- runit) sv restart prosody >> /tmp/pupm.log 2>&1;;
- systemd) systemctl restart prosody >> /tmp/pupm.log 2>&1;;
- *) echo "Bad service ${SYSTEMINIT}" >> /tmp/pupm.log 2>&1;;
-
- esac
+# apdeit
+update () {
+ # chek modiulspadz ouunership
+ test -O ${MODULESPATH} \
+ && printf "you own the modulespath" > /dev/null \
+ || chown ${USER} -R ${MODULESPATH} >> ${PUPMLOG} 2>&1
-}
+ # apdeit modiuls
+ cd ${MODULESPATH} || return 2
-# input variables
-INPUTFILE="${PWD}/pupm.config"
-MODULESPATH=`cat ${INPUTFILE} | grep "MODULESPATH=" | sed 's/MODULESPATH=//g; s/ *$//g'`
-DIROWNER=`cat ${INPUTFILE} | grep "DIROWNER=" | sed 's/DIROWNER=//g; s/ *$//g'`
-DIRGROUP=`cat ${INPUTFILE} | grep "DIRGROUP=" | sed 's/DIRGROUP=//g; s/ *$//g'`
-DIRPERMISSIONS=`cat ${INPUTFILE} | grep "DIRPERMISSIONS=" | sed 's/DIRPERMISSIONS=//g; s/ *$//g'`
-RELOAD=`cat ${INPUTFILE} | grep "RELOAD=" | sed 's/RELOAD=//g; s/ *$//g'`
-SYSTEMINIT=`cat ${INPUTFILE} | grep "SYSTEMINIT=" | sed 's/SYSTEMINIT=//g; s/ *$//g'`
+ test ! -d ${HGDIR} \
+ && printf "abort: no repository found in %s\\n" "${MODULESPAHT}" >> ${PUPMLOG} \
+ && exit 2 \
+ || hg pull --update >> ${PUPMLOG} 2>&1
-# default variables
-: ${MODULESPATH:=/usr/lib/prosody/modules/}
-: ${DIROWNER:=root}
-: ${DIRGROUP:=prosody}
-: ${DIRPERMISSIONS:=750}
-: ${RELOAD:=no}
-: ${SYSTEMINIT:=service}
+ # meik modiulspadz sequiur an ridabel tu prosody
+ chown ${OWNER}:${GROUP} -R ${MODULESPATH} >> ${PUPMLOG} 2>&1
+ chmod ${PERMISSIONS} -R ${MODULESPATH} >> ${PUPMLOG} 2>&1
+}
-# general variables
-DATE=`date +%d.%m.%Y`
-TIME=`date +%H:%M`
+# serviz ristart
+service_restart () {
+ case ${SYSTEMINIT} in
+ service) service prosody restart >> ${PUPMLOG} 2>&1;;
+ runit) sv restart prosody >> ${PUPMLOG} 2>&1;;
+ systemd) systemctl restart prosody >> ${PUPMLOG} 2>&1;;
+ *) printf "init: not supported %s\\n" "${SYSTEMINIT}" >> ${PUPMLOG} 2>&1;;
+ esac
+}
-# get options
-while getopts ":d:o:g:p:r:s:c:h" opt ; do
- case ${opt} in
- d) MODULESPATH="${OPTARG}" ;;
- o) DIROWNER="${OPTARG}" ;;
- g) DIRGROUP="${OPTARG}";;
- p) DIRPERMISSIONS="${OPTARG}" ;;
- r) RELOAD="${OPTARG}";;
- s) SYSTEMINIT=${OPTARG};;
- c) INPUTFILE=${OPTARG};;
- \?) echo "Invalid option: -${OPTARG}" 1>&2; exit 2 ;;
- :) echo "Missing argument for -${OPTARG}" 1>&2; exit 2 ;;
- h) usage ;;
+# variabels dat comz from config
+CONFIG="$1"
+INPUT="/tmp/pupm.input"
+sed '/^#/ d; s/;[ \t].*//g; s/;$//g; s/[ \t]*$//g' ${CONFIG} > ${INPUT}
- esac
+MODULESPATH=$(sed '/MODULESPATH=/ !d; s/MODULESPATH=//' ${INPUT})
+OWNER=$(sed '/OWNER=/ !d; s/OWNER=//' ${INPUT})
+GROUP=$(sed '/GROUP=/ !d; s/GROUP=//' ${INPUT})
+PERMISSIONS=$(sed '/PERMISSIONS=/ !d; s/PERMISSIONS=//' ${INPUT})
+RELOAD=$(sed '/RELOAD=/ !d; s/RELOAD=//' ${INPUT})
+SYSTEMINIT=$(sed '/SYSTEMINIT=/ !d; s/SYSTEMINIT=//' ${INPUT})
-done
+# variabels tu ius ololon
+DATE=$(date "+%d-%m %H:%M")
+HGDIR=".hg"
+PUPMLOG="/tmp/pupm.log"
-shift $(($OPTIND -1))
+# inizial comandz
+test $# -lt 1 && usage
-# clean log and relog date
-echo "${DATE} - ${TIME}" > /tmp/pupm.log
+printf "%s\\n" "${DATE}" > ${PUPMLOG}
+test -d ${MODULESPATH} || printf "%s is not a directory" "${MODULESPATH}" >> ${PUPMLOG}
-REALOWNER=`ls -ld ${MODULESPATH} | awk '{ print $3 }'`
-# checks
-test -d ${MODULESPATH} && echo "exists" || echo "no dir"
-echo $MODULESPATH
-cd ${MODULESPATH}
-test ${REALOWNER} = ${DIROWNER} && echo "ok" || echo "no permissions"
-ISMPHG=`hg pull --update | echo $?`
-test ${ISMPHG} -lt 1 && hg pull --update || echo "no es hg"
-
-# change permissions
-chown ${DIROWNER}:${DIRGROUP} -R ${MODULESPATH} >> /tmp/pupm.log 2>&1
-chmod ${DIRPERMISSIONS} -R ${MODULESPATH} >> /tmp/pupm.log 2>&1
-# reload or restart
-case ${RELOAD} in
- yes) prosodyctl reload >> /tmp/pupm.log 2>&1;;
- no) service_restart >> /tmp/pupm.log 2>&1;;
+update
+# fainal comandz
+case $RELOAD in
+ yes) prosodyctl reload >> ${PUPMLOG} 2>&1;;
+ no) service_restart >> ${PUPMLOG} 2>&1;;
esac
-