aboutsummaryrefslogtreecommitdiff
path: root/pupm.sh
blob: 798bd2eeb0bbc40e736d2e9bd3d8e6567673fafc (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/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
SCRIPTNAME="${0##*/}"
SCRIPTNAME="${SCRIPTNAME%%.sh}"

VERSION="3.0.5"           # Fix version
AUTHOR="ziggys"
LICENSE="BSD 2.0 (3-Clause)"

# usage
usage () {
test "$#" = 0 || printf "%s %s\\n" "${SCRIPTNAME}" "$@"
cat << EOF | fold -s
${SCRIPTNAME} version ${VERSION}
  by ${AUTHOR}
  License: ${LICENSE}

${SCRIPTNAME} comes with ABSOLUTELY NO WARRANTY. This is free software, and you
  you are welcome to redistribute it under certain conditions. See the BSD 2.0
  license for details.

${SCRIPTNAME} is a symply shellscript for properly update prosody modules

Usage:  ${SCRIPTNAME} <configile>
Usage:  ${SCRIPTNAME} pupm.config

For more details about this script go to
Official Repository: https://git.p4g.club/git/pupm
Mirror Repository: https://gitgud.io/ziggys/pupm
EOF
exit 0 
}

# apdeit
update () {
  # chek modiulspadz ouunership
  if [ -O "${MODULESPATH}" ]; then
    printf "you own the modulespath" > /dev/null
  else
    chown "${USER}" -R "${MODULESPATH}" >> "${PUPMLOG}" 2>&1
  fi

  # apdeit modiuls
  cd "${MODULESPATH}" || return 2

  if [ ! -d "${HGDIR}" ]; then
    printf "err: no repository found in %s\\n" "${MODULESPATH}" >> "${PUPMLOG}"
    exit 2
  else
    hg pull --update >> "${PUPMLOG}" 2>&1
  fi

  # 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}";;
  esac
}

# variabels dat comz from config
CONFIG="${1?"Usage:  ${0} <configfile>"}"
test -z "${CONFIG}" && usage "$@"
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}"i
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