Skip to content

Commit 942fb67

Browse files
authored
Merge pull request #39 from grantma/main
Changes to latest scripts which grommunio is distributing - Fixes issues when apt repos already set up.
2 parents f4ab7e2 + 60a3da2 commit 942fb67

File tree

4 files changed

+169
-9
lines changed

4 files changed

+169
-9
lines changed

common/dialogs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,13 @@ get_relayhost(){
9494
dialog_exit $?
9595

9696
}
97+
98+
apt_already_setup_notice ()
99+
{
100+
101+
dialog --no-mouse --colors --clear --backtitle "grommunio Setup" \
102+
--title "Apt already setup" \
103+
--msgbox 'It looks like a grommunio apt respository is already defined. Clear these settings, or use the --no-apt-setup flag to run grommunio-setup.' 0 0
104+
dialog_exit $?
105+
106+
}

common/repo

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
setup_repo() {
77
local uri kr count krtemp
8+
9+
# Check if ther eare already grommunio apt repos defined
10+
RELEASE_CODENAME=$(lsb_release -sc)
11+
SOURCES_FOUND=0
12+
PATTERN='^[^#]+download\.grommunio\.com'
13+
[ -e /etc/apt/sources.list ] && grep -qP "$PATTERN" /etc/apt/sources.list && SOURCES_FOUND=1
14+
grep -qPr "$PATTERN" /etc/apt/sources.list.d && SOURCES_FOUND=1
15+
if [ $SOURCES_FOUND -gt 0 ]; then
16+
return 2
17+
fi
18+
819
. /etc/os-release
920
mirror=https://download.grommunio.com
1021
uri="$mirror"/RPM-GPG-KEY-grommunio
@@ -118,4 +129,64 @@ echo
118129
# keep visual output on the screen for a glimpse so admin can decide
119130
# if the logfile needs to be inspected.
120131
sleep 1
132+
return 0
133+
}
134+
135+
repos_usage () {
136+
echo "$USAGE" 1>&2
137+
exit 2
138+
}
139+
140+
repos_usage_full () {
141+
echo "$USAGE" 1>&2
142+
echo "" 1>&2
143+
echo " -f force overwrite" 1>&2
144+
echo " -h This help" 1>&2
145+
exit 2
121146
}
147+
148+
repos_main () {
149+
PROGNAME=`basename "$0"`
150+
USAGE="Usage: $PROGNAME [-h]"
151+
152+
# Process command line arguments
153+
OPTIND=1
154+
while getopts h F; do
155+
case $F in
156+
h)
157+
repos_usage_full
158+
;;
159+
\?)
160+
repos_usage
161+
;;
162+
esac
163+
done
164+
shift $(( OPTIND - 1 ))
165+
if [ $# != 0 ]; then
166+
repos_usage
167+
fi
168+
169+
# bail out if we are not root
170+
if [ "`id -un`" != "root" ] ; then
171+
echo 1>&2
172+
echo " `basename $0`: you must be 'root' to run this command." 1>&2
173+
echo 1>&2
174+
exit 1
175+
fi
176+
177+
setup_repo
178+
RETVAL=$?
179+
if [ $RETVAL -ne 0 ]; then
180+
echo "${PROGNAME}: grommunio apt repository definitions already exist"
181+
exit $RETVAL
182+
fi
183+
184+
exit 0
185+
}
186+
187+
# Execute if stand alone
188+
case "$0" in
189+
*grommunio-setup-repos)
190+
repos_main "$@"
191+
;;
192+
esac

etc/grommunio-setup.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# grommunio-setup config file
3+
#
4+
# Whether to not to set up apt repositories or not
5+
# Values are 0 for false, and 1 for true
6+
# Set to 1 if grommunio-setup installed from a deb package as
7+
# apt probably already set up
8+
NO_APT_SETUP=0
9+

grommunio-setup

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,72 @@
88
# Interactive grommunio setup
99

1010
if [ "$(id -u)" -ne 0 ]; then
11-
exec sudo "${BASH_SOURCE[0]}"
11+
exec sudo "${BASH_SOURCE[0]}"
12+
fi
13+
14+
CFG_FILE='/etc/grommunio-setup/grommunio-setup.conf'
15+
PKGED_CFG_FILE='/etc/grommunio-setup/packaged.conf'
16+
PROGNAME=`basename "$0"`
17+
18+
# Process command line arguments
19+
USAGE="Usage: $PROGNAME [-ahx]"
20+
usage () {
21+
echo "$USAGE" 1>&2
22+
exit 2
23+
}
24+
25+
usage_full () {
26+
echo "$USAGE" 1>&2
27+
echo "" 1>&2
28+
echo " -a --apt-setup Set up apt" 1>&2
29+
echo " -h --help This help" 1>&2
30+
echo " -x --no-apt-setup Don't set up apt" 1>&2
31+
echo "" 1>&2
32+
exit 2
33+
}
34+
35+
OPTS=$(getopt -o ahx -l apt-setup,help,no-apt-setup -n "$PROGNAME" -- "$@")
36+
if [ $? -ne 0 ]; then
37+
echo "${PROGNAME}: Failed to parse options." 1>&2
38+
exit 2
39+
fi
40+
# Reset the positional parameters to the parsed options
41+
eval set -- "$OPTS"
42+
43+
# setable settings here
44+
NO_APT_SETUP=0
45+
[ -e "$CFG_FILE" ] && . "$CFG_FILE"
46+
# override various settings for packaged setup script
47+
[ -e "$PKGED_CFG_FILE" ] && . "$PKGED_CFG_FILE"
48+
# Unsettable settings here
49+
# Process the options
50+
while true; do
51+
case "$1" in
52+
-a | --apt-setup)
53+
NO_APT_SETUP=0
54+
shift
55+
;;
56+
-h | --help)
57+
usage_full
58+
shift
59+
;;
60+
-x | --no-apt-setup)
61+
NO_APT_SETUP=1
62+
shift
63+
;;
64+
--)
65+
shift
66+
break
67+
;;
68+
*)
69+
echo "${PROGNAME}: Internal error!"
70+
exit 2
71+
;;
72+
esac
73+
done
74+
75+
if [ $# -ne 0 ]; then
76+
usage
1277
fi
1378

1479
export DEBIAN_FRONTEND=noninteractive
@@ -26,9 +91,6 @@ if ! test -e "$LOGFILE"; then
2691
true >"$LOGFILE"
2792
chmod 0600 "$LOGFILE"
2893
fi
29-
if [ "$1" = "JUSTDOIT" ]; then
30-
SKIPDIALOG=1
31-
fi
3294

3395
apt-get() {
3496
if [ "$1" = "update" ]; then
@@ -106,17 +168,17 @@ You can abort or delete all data and setup everything from scratch. If so, confi
106168
\Z1If you continue, ALL data wil be removed!\Z1' \
107169
0 0 3>&1 1>&2 2>&3)
108170
dialog_exit $?
109-
110171
if [ "${DELCONFIRM}" != "removealldata" ]; then
111172
writelog "Aborted deletion after detected existing installation"
112173
exit 0
113174
else
114175
writelog "Deleting existing installation after confirmation"
115176
echo "drop database grommunio;" | mysql
116-
# remove folders
177+
# remove folders etc
117178
rm -Rf /var/lib/gromox/* \
118179
/etc/grommunio-common/ssl/* \
119180
/etc/grommunio-common/setup_done \
181+
/etc/apt/sources.list.d/grommunio.sources \
120182
/var/lib/grommunio-web/*
121183

122184
# recreate them..
@@ -172,7 +234,15 @@ PACKAGES=(gromox grommunio-admin-api grommunio-admin-web grommunio-index
172234
grommunio-admin-common grommunio-common grommunio-web grommunio-sync
173235
grommunio-dav grommunio-dbconf nginx-module-vts)
174236
. "${DATADIR}/common/repo"
175-
setup_repo
237+
if [ $NO_APT_SETUP -eq 0 ]; then
238+
setup_repo
239+
if [ $? -ne 0 ]; then
240+
writelog "Exiting - trying to set up apt repos when already defined"
241+
apt_already_setup_notice
242+
clear
243+
exit 2
244+
fi
245+
fi
176246
writelog "Installing Grommunio-Packages"
177247
apt-get update
178248
# reinstall in case of "removealldata"
@@ -370,8 +440,8 @@ choose_ssl_selfprovided() {
370440
writelog "Dialog: data for self-provided TLS cert"
371441
dialog --no-mouse --colors --backtitle "grommunio Setup" --title "TLS certificate (self-provided)" --ok-label "Submit" \
372442
--form "Enter the paths to the TLS certificates" 0 0 0 \
373-
"PEM encoded certificate bundle: " 1 1 "${SSL_BUNDLE}" 1 35 35 0 \
374-
"PEM encoded private key: " 2 1 "${SSL_KEY}" 2 35 35 0 2>"${TMPF}"
443+
"PEM encoded certificate bundle: " 1 1 "${SSL_BUNDLE}" 1 35 120 0 \
444+
"PEM encoded private key: " 2 1 "${SSL_KEY}" 2 35 120 0 2>"${TMPF}"
375445
dialog_exit $?
376446

377447
}

0 commit comments

Comments
 (0)