aboutsummaryrefslogtreecommitdiff
path: root/pupm.sh
blob: 1f8abaa4ea0b7caa186fafab24c5e07211c5d6e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
# -*- ENCODING: UTF-8 -*-
# Properly Update Prosody Modules
# a very simple script to do that
# by ziggys (c) 2018
# License BSD 2.0 (3-Clause)

# scriptinfo
VERSION='3.0.2'                   # Check some sintax and fix minor bugs
AUTHOR="ziggys"

# usash
show_help () {
test "${#}" = 0 || echo "${@}"
echo "${0##*/} version ${VERSION}"
echo "  Copyright (C) 2018 by ${AUTHOR}"
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
echo "${0##*/} is a simply shellscript for properly update prosody modules"
echo
echo "Usage:  "${0}" <configfile>"
echo
echo "Usage:  "${0}" pupm.config"
echo
exit "${?}"
}

# 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

  test ! -d "${HGDIR}" \
    && printf "abort: no repository found in %s\\n" "${MODULESPATH}" >> "${PUPMLOG}" \
    && exit 2 \
    || 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
}

# 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
}

# variabels dat comz from config
CONFIG="${1?"Usage:  ${0} <configfile>"}"
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}"
: "${GROUP:=prosody}"
: "${PERMISSIONS:=750}"
: "${RELOAD:=no}"
: "${SYSTEMINIT:=service}"
: "${VERBOSE:=yes}"

# variabels tu ius ololon
DATE="$(date "+%d-%m %H:%M")"
HGDIR=".hg"
PUPMLOG="$(mktemp)"

# inizial comandz
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;;
esac
test "${VERBOSE}" = "yes"  && cat "${PUPMLOG}"
rm -f "${INPUT}" "${PUPMLOG}"
exit 0