forked from andersdd/xtuple-utility
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.sh
More file actions
189 lines (165 loc) · 6.01 KB
/
common.sh
File metadata and controls
189 lines (165 loc) · 6.01 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
do_exit() {
log "Exiting xTuple Admin Utility"
exit 0
}
die() {
TRAPMSG="$@"
log $@
exit 1
}
# catch user hitting control-c during operation, exit gracefully.
trap ctrlc INT
ctrlc() {
log "Breaking due to user CTRL-C"
do_exit
}
# $1 is the URL
# $2 is the name of what is downloading to show on the window
# $3 is the output file name
dlf() {
log "Downloading $1 to file $3 using wget"
wget "$1" 2>&1 -O "$3" | stdbuf -o0 awk '/[.] +[0-9][0-9]?[0-9]?%/ { print substr($0,63,3) }' | whiptail --backtitle "$( window_title )" --gauge $2 0 0 100;
return ${PIPESTATUS[0]}
}
# $1 is the URL
# $2 is the name of what is downloading to show on the window
# $3 is the output file name
dlf_fast() {
log "Downloading $1 to file $3 using axel"
axel -n 5 "$1" -o "$3" 2>&1 | stdbuf -o0 awk '/[0-9][0-9]?%+/ { print substr($0,2,3) }' | whiptail --backtitle "$( window_title )" --gauge "$2" 0 0 100;
return ${PIPESTATUS[0]}
}
# $1 is the URL
# $3 is the output file name
dlf_fast_console() {
log "Downloading $1 to file $2 using axel console output only"
axel -n 5 "$1" -o "$2" > /dev/null
}
# $1 is the msg
msgbox() {
log "MessageBox >> ""$1"
[ $MODE = "manual" ] && whiptail --backtitle "$( window_title )" --msgbox "$1" 0 0 0
}
# $1 is the product
latest_version() {
VER=`curl -s http://files.xtuple.org/latest_$1`
echo $VER
}
window_title() {
if [ -z "$PGHOST" ] && [ -z "$POSTPORT" ] && [ -z "$PGUSER" ] && [ -z "$PGPASSWORD" ]; then
echo "xTuple Admin Utility v$_REV -=- Current Connection Info: Not Connected"
elif [ ! -z "$PGHOST" ] && [ ! -z "$POSTPORT" ] && [ ! -z "$PGUSER" ] && [ -z "$PGPASSWORD" ]; then
echo "xTuple Admin Utility v$_REV -=- Current Server $PGUSER@$PGHOST:$POSTPORT -=- Password Is Not Set"
else
echo "xTuple Admin Utility v$_REV -=- Current Server $PGUSER@$PGHOST:$POSTPORT -=- Password Is Set"
fi
}
# $1 is text to display
menu_title() {
cat "$WORKDIR"/xtuple.asc
echo "$1"
}
# used whenever a command needs elevated privileges as we can't always rely on sudo
runasroot() {
if [[ $UID -eq 0 ]]; then
"$@"
elif sudo -v &>/dev/null && sudo -l "$@" &>/dev/null; then
sudo -E "$@"
else
echo -n "root "
su -c "$(printf '%q ' "$@")"
fi
}
# these are both the same currently, but the structure may change eventually
# as we add more supported distros
install_prereqs() {
case "$DISTRO" in
"ubuntu")
install_pg_repo
sudo apt-get update
sudo apt-get -y install axel git whiptail unzip bzip2 wget curl build-essential libssl-dev postgresql-client-$POSTVER cups python-software-properties openssl libnet-ssleay-perl libauthen-pam-perl libpam-runtime libio-pty-perl perl libavahi-compat-libdnssd-dev python xvfb jq s3cmd python-magic
RET=$?
if [ $RET -ne 0 ]; then
msgbox "Something went wrong installing prerequisites for $DISTRO/$CODENAME. Check the log for more info. "
do_exit
fi
# Install LE prerequsites
source letsencrypt/installLE.sh
# fix the background color
sudo sed -i 's/magenta/blue/g' /etc/newt/palette.ubuntu
;;
"debian")
install_pg_repo
sudo apt-get update
sudo apt-get -y install python-software-properties software-properties-common xvfb
if [ ! "$(find /etc/apt/ -name *.list | xargs cat | grep ^[[:space:]]*deb | grep backports)" ]; then
sudo add-apt-repository -y "deb http://ftp.debian.org/debian $(lsb_release -cs)-backports main"
sudo apt-get update
fi
sudo apt-get -y install axel git whiptail unzip bzip2 wget curl build-essential libssl-dev postgresql-client-$POSTVER
RET=$?
if [ $RET -ne 0 ]; then
msgbox "Something went wrong installing prerequisites for $DISTRO/$CODENAME. Check the log for more info. "
do_exit
fi
;;
"centos")
log "Maybe one day we will support CentOS..."
do_exit
;;
*)
log "Shouldn't reach here! Please report this on GitHub. install_prereqs"
do_exit
;;
esac
}
install_pg_repo() {
case "$CODENAME" in
"trusty") ;&
"utopic") ;&
"wheezy") ;&
"jessie") ;&
"xenial")
# check to make sure the PostgreSQL repo is already added on the system
if [ ! -f /etc/apt/sources.list.d/pgdg.list ] || ! grep -q "apt.postgresql.org" /etc/apt/sources.list.d/pgdg.list; then
sudo bash -c "wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -"
sudo bash -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
fi
;;
esac
}
# $1 is the port
# $2 is protocol
is_port_open() {
(echo >/dev/$2/localhost/$1) &>/dev/null && return 0 || return 1
}
new_postgres_port() {
POSTPORT=$(for i in $(seq 5432 5500) $(sudo pg_lsclusters -h | awk '{print $3}') ; do echo $i; done | sort | uniq -u | head -1)
}
new_nginx_port() {
NGINX_PORT=$(for i in $(seq 8443 8500) $(head -2 /etc/nginx/sites-available/* | grep -Po '8[0-9]{3}') ; do echo $i; done | sort | uniq -u | head -1)
}
test_connection() {
log "Testing internet connectivity..."
wget -q --tries=5 --timeout=10 -O - http://files.xtuple.org > /dev/null
if [[ $? -eq 0 ]]; then
log "Internet connectivity detected."
return 0
else
log "Internet connectivity not detected."
return 1
fi
}
# define some colors if the tty supports it
if [[ -t 1 && ! $COLOR = "NO" ]]; then
COLOR1='\e[1;39m'
COLOR2='\e[1;32m'
COLOR3='\e[1;35m'
COLOR4='\e[1;36m'
COLOR5='\e[1;34m'
COLOR6='\e[1;33m'
COLOR7='\e[1;31m'
ENDCOLOR='\e[0m'
S='\\'
fi