aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorziggys <ziggys@autistici.org>2018-06-10 17:11:07 -0400
committerziggys <ziggys@autistici.org>2018-06-10 17:11:07 -0400
commit0b65462c3bcb1b5f318c6f7e98154cb34b8063a1 (patch)
tree7e07dc7c6b04f998c372757dbbcfe02b60d26768
parente950dc73c75511fc7c54fdb07e987ab2dd74aa7e (diff)
downloadpupm-0b65462c3bcb1b5f318c6f7e98154cb34b8063a1.tar
pupm-0b65462c3bcb1b5f318c6f7e98154cb34b8063a1.zip
Check some sytax and fix minor bugs
-rw-r--r--LICENSE25
-rw-r--r--README.txt42
-rw-r--r--pupm.config19
-rwxr-xr-xpupm.sh85
4 files changed, 110 insertions, 61 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..36c8053
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,25 @@
+# Licence BSD License 2.0
+#Copyright (c) 2017, 2018 ziggys
+#All rights reserved.
+
+#Redistribution and use in source and binary forms, with or without
+#modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the <organization> nor the
+# names of its contributors may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+#DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+#ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.txt b/README.txt
index 91a39c9..02978cb 100644
--- a/README.txt
+++ b/README.txt
@@ -1,29 +1,45 @@
Properly Update Prosody Modules
+-------------------------------
+A very simple way to update core and community modules for prosody xmpp server
+from 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).
+Install
+-------
+Script doesn't requires installation, simply download the script into the host
+where prosody is running, configure and execute with root privileges.
-Download the script into your localhost and execute (need root access).
+~$ git clone https://git.p4g.club/git/pupm.git pupm
-Run it:
+Execute
+-------
+Change to 'pupm' directory and run script:
-./pupm.sh <config>
+~$ cd pupm && ./pupm.sh pupm.config
-./pupm.sh pupm.config
+Run with no arguments to show help.
-Run it with no arguments for help.
+~$ cd pupm && ./pupm.sh
-Config example is provided within repository
+----------------
+pupm.shh version 3.0.2
+ Copyright (C) 2018 by
+
+pupm.sh comes with ABSOLUTELY NO WARRANTY. This is free software, and you
+ are welcome to redistribute it under certain conditions. See the BSD 2.0
+ license for details
+
+pupm.sh is a simple shellscript to properly update prosody modules
+
+Usage: ./pupm.sh <configfile>
+
+Usage: ./pupm.sh pupm.config
+----------------
-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.
+Config example is provided within repository.
-# TODO
-# check syntax
diff --git a/pupm.config b/pupm.config
index a08389e..29e2404 100644
--- a/pupm.config
+++ b/pupm.config
@@ -1,10 +1,13 @@
# pupm configuration file
-# use it to define script variables
-# empty ones will fall to these default
+# use to define script variables
+# empty ones will default to this ones
+# commented lines and inline comments
+# will be ignored
-MODULESPATH=/usr/lib/prosody/modules
-OWNER=root
-GROUP=prosody
-PERMISSIONS=750
-RELOAD=no
-SYSTEMINIT=service
+MODULESPATH=/usr/lib/prosody/modulesi; # modules dir
+OWNER=root; # modules dir owner
+GROUP=prosody; # modules dir group
+PERMISSIONS=750; # modues dir permissions in octal
+RELOAD=no; # yes | no (wether if reload or restart prosody server)
+SYSTEMINIT=service; # service | runit | systemd (your service manager daemon)
+VERBOSE=yes; # yes | no (verbosity)
diff --git a/pupm.sh b/pupm.sh
index 6466389..34602e9 100755
--- a/pupm.sh
+++ b/pupm.sh
@@ -6,22 +6,22 @@
# License BSD 2.0 (3-Clause)
# scriptinfo
-VERSION='3.0.1' # Define default value for empty vars
+VERSION='3.0.2' # Check some sintax and fix minor bugs
AUTHOR="ziggys"
CYEAR=$(date +%Y)
COPYRIGHT="${CYEAR} by ${AUHTOR}"
# usash
-usage () {
-test $# = 0 || echo $@
-echo "$0 version ${VERSION}"
-echo "Copyright (C) ${COPYRIGHT}"
+show_help () {
+test "${#}" = 0 || echo "${@}"
+echo "${0##*/} version ${VERSION}"
+echo " Copyright (C) ${COPYRIGHT}"
echo
-echo "$0 comes with ABSOLUTELY NO WARRANTY. This is free software, and you"
-echo "are welcome to redistribute it under certain conditions. See the BSD 2.0"
-echo "license for details"
+echo "${0##*/} comes with ABSOLUTELY NO WARRANTY. This is free software, and you"
+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 "${0##*/} is a simply shellscript for properly update prosody modules"
echo
echo "Usage: $0 <configfile>"
echo
@@ -33,45 +33,46 @@ exit $?
# apdeit
update () {
# chek modiulspadz ouunership
- test -O ${MODULESPATH} \
+ test -O "${MODULESPATH}" \
&& printf "you own the modulespath" > /dev/null \
- || chown ${USER} -R ${MODULESPATH} >> ${PUPMLOG} 2>&1
+ || chown "${USER}" -R "${MODULESPATH}" >> "${PUPMLOG}" 2>&1
# apdeit modiuls
- cd ${MODULESPATH} || return 2
+ cd "${MODULESPATH}" || return 2
- test ! -d ${HGDIR} \
- && printf "abort: no repository found in %s\\n" "${MODULESPAHT}" >> ${PUPMLOG} \
+ test ! -d "${HGDIR}" \
+ && printf "abort: no repository found in %s\\n" "${MODULESPAHT}" >> "${PUPMLOG}" \
&& exit 2 \
- || hg pull --update >> ${PUPMLOG} 2>&1
+ || hg pull --update >> "${PUPMLOG}" 2>&1
# meik modiulspadz sequiur an ridabel tu prosody
- chown ${OWNER}:${GROUP} -R ${MODULESPATH} >> ${PUPMLOG} 2>&1
- chmod ${PERMISSIONS} -R ${MODULESPATH} >> ${PUPMLOG} 2>&1
+ chown "${OWNER}":"${GROUP}" -R "${MODULESPATH}" >> "${PUPMLOG}" 2>&1
+ chmod "${PERMISSIONS}" -R "${MODULESPATH}" >> "${PUPMLOG}" 2>&1
}
# 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;;
+ 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
}
# variabels dat comz from config
-CONFIG="$1"
-INPUT="/tmp/pupm.input"
-sed '/^#/ d; s/;[ \t].*//g; s/;$//g; s/[ \t]*$//g' ${CONFIG} > ${INPUT}
-
-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})
+CONFIG="${1}"
+test -z "${CONFIG}" && show_help
+INPUT="$(mktemp)"
+sed '/^#/ d; s/;[ \t].*//g; s/;$//g; s/[ \t]*$//g' "${CONFIG}" > "${INPUT}"
+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}")"
+VERBOSE="$(sed '/VERBOSE=/ !d; s/VERBOSE=//' "${INPUT}")"
# difoult valius for variabels
: ${MODULESPATH:=/usr/lib/prosody/modules}
: ${ONWER:=root}
@@ -79,22 +80,26 @@ SYSTEMINIT=$(sed '/SYSTEMINIT=/ !d; s/SYSTEMINIT=//' ${INPUT})
: ${PERMISSIONS:=750}
: ${RELOAD:=no}
: ${SYSTEMINIT:=service}
+: ${VERBOSE:=yes}
# variabels tu ius ololon
-DATE=$(date "+%d-%m %H:%M")
+DATE="$(date "+%d-%m %H:%M")"
HGDIR=".hg"
-PUPMLOG="/tmp/pupm.log"
+PUPMLOG="$(mktemp)"
# inizial comandz
-test $# -lt 1 && usage
+test "${#}" -lt 1 && show_help
-printf "%s\\n" "${DATE}" > ${PUPMLOG}
-test -d ${MODULESPATH} || printf "%s is not a directory" "${MODULESPATH}" >> ${PUPMLOG}
+printf "%s\\n" "${DATE}" > "${PUPMLOG}"
+test -d "${MODULESPATH}" || printf "%s is not a directory" "${MODULESPATH}" >> "${PUPMLOG}"
update
# fainal comandz
-case $RELOAD in
- yes) prosodyctl reload >> ${PUPMLOG} 2>&1;;
- no) service_restart >> ${PUPMLOG} 2>&1;;
+case "${RELOAD}" in
+ yes) prosodyctl reload >> "${PUPMLOG}" 2>&1;;
+ no) service_restart >> "${PUPMLOG}" 2>&1;;
esac
+test "${VERBOSE}" = "yes" && cat "${PUPMLOG}"
+rm -f "${INPUT}" "${PUPMLOG}"
+exit 0