-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsk-configuration-manager.sh
executable file
·258 lines (206 loc) · 7.6 KB
/
jsk-configuration-manager.sh
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env sh
# ====================================================== project information ===
# author : jimmy mg lim (mirageglobe@gmail.com)
# source : https://github.com/mirageglobe/swissknife
# version : 0.1.0
# --------------------------------------------------------------------- todo ---
# - support raw folder for custom native shell scripts
# - use default.json, custom.json for input rules. any scroll can be created in camp folder http://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file-in-python
# - check packages option to see a summary of what is installed.
# - add unit test (https://github.com/kward/shunit2)
# - add fail2ban in core scroll
# - add caffeine in linux
# - install to home directory and symlink commands
# - future tooling prototype for sub-scripting
# prototype example:
# ```
# {
# "scrollname" : "myfirstscroll",
# "scrolldescription" : "this scroll does A B C."
# "scrollscript" :
# {
# "command.1" : "",
# "command.2" : "",
# }
# }
# ```
# --------------------------------------------------------------------- main ---
# ----- common functions
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; exit 111; }
try() { "$@" || die "cannot $*"; }
# ----- local functions
buildReport() {
LOCAL_LOGIN=$1
LOCAL_SERVER=$2
if test [ -z "$LOCAL_LOGIN" ] || [ -z "$LOCAL_SERVER" ]; then
echo "missing variables (login name). retype bash command to see."
else
echo "Logging onto server environment ($LOCAL_SERVER)"
ssh $LOCAL_LOGIN@$LOCAL_SERVER 'sudo bash -s' < swissknife.docker-report.sh
ssh $LOCAL_LOGIN@$LOCAL_SERVER 'tail -10 report.yml'
fi
}
# ----- check arguments
DF_VERSION="0.1.0"
DF_TITLE="***"
DF_LINE="*** -----"
DF_TEXT=" "
# ----- check arguments
EXPECTED_ARGS=1 # expected number of arguments in command line
E_BADARGS=65 #
if [ "$#" -lt "$EXPECTED_ARGS" ]; then
printf "\n$DTTEXT"
printf "\n$DTTITLE Jimmys Configuration Manager"
printf "\n$DTTEXT JCM is a configuration tool for building and configuring machines (as well as cloud based VMs). It reads a basic jcm file (json format) which specifies the intended state and ensures the target (which can be remote or local) corresponds to the jot file specification. It WILL automatically install missing applications and highlight ones that already exist."
printf "\n$DTTEXT"
printf "\n$DTTITLE USAGE"
printf "\n$DTTEXT $0 init # initialize generates a sample jot script if none is found"
printf "\n$DTTEXT $0 remote [IP] # execute run default jot file script on remote"
printf "\n$DTTEXT $0 local # execute run default jot file script locally"
printf "\n$DTTEXT $0 help / -h # show commands"
printf "\n$DTTEXT $0 version / -v # show version number"
printf "\n$DTTEXT"
printf "\n$DTTITLE EXAMPLES"
printf "\n$DTTEXT $0 -v"
printf "\n$DTTEXT"
exit $E_BADARGS
fi
# ----- variables
VERSION_NO="0.1.2"
DEFAULT_PASS="defaultpass"
SLIENT_INSTALL=true
#an interactive password updater will run at the end to change this password to one of your choice
#you should change this to one of your own passwords; i recommend using keepassX to generate at least 128bit unique passwords without odd non alphanumberic words; also use lower caps to ensure ease of typing in.
INSTALL_backintime=true
INSTALL_cifs=true #smb client
INSTALL_git=true
INSTALL_graphicsmagick=true
INSTALL_java7=true
INSTALL_java8=true
INSTALL_nginx=true
INSTALL_nvmnodejs=true
INSTALL_postgres=false
INSTALL_postgres93=true
INSTALL_samurai=true
INSTALL_vim=true
INSTALL_x11vncserver=true
SET_java7_default=false
SET_java8_default=true
#INSTALL_mysql=false
#INSTALL_mongodb=false
#INSTALL_sqlite=false
#INSTALL_nginx=true
#do not change variables below
SLIENT_YES="" #slient yes use for slient installs, this just appends -y or nothing
if [ $SLIENT_INSTALL ]; then
sudo export DEBIAN_FRONTEND=noninteractive
SLIENT_YES="-y"
fi
# ----- main code
SK_CMD=$1
SK_LOGIN=$2
case "$SK_CMD" in
opt-1)
echo "Logging onto local server environment"
buildReport $SK_LOGIN 10.131.4.40
;;
ls)
echo "test ls"
;;
*)
die
esac
printf "\n$DTTEXT"
printf "\n$DTTITLE script: terracotta (v$VERSION_NO) - an auto server setup"
printf "\n$DTTEXT"
printf "\n$DTTEXT"
printf "\n$DTTEXT warning: this script is designed specifically for *buntu trusty 14.04 LTS. Lubuntu 14.04 Full highly recommended"
printf "\n$DTTEXT"
# switching to root and installing default applications
printf "\n$DTTITLE updating server as root"
if [ "$(id -u)" != "0" ]; then
printf "\n$DTTEXT this script must be run as root. try sudo <script>" 1>&2
exit 1
fi
sudo apt-get update $SLIENT_YES
sudo apt-get upgrade $SLIENT_YES
sudo apt-get dist-upgrade $SLIENT_YES
sudo apt-get install build-essential $SLIENT_YES
sudo apt-get install python-software-properties $SLIENT_YES
sudo apt-get install curl $SLIENT_YES
# installing selected applications
if [ $INSTALL_backintime ]; then
printf "\n$DTTEXT installing backintime"
sudo add-apt-repository ppa:bit-team/stable
sudo apt-get update $SLIENT_YES
sudo apt-get install backintime-common $SLIENT_YES
fi
if [ $INSTALL_cifs ]; then
printf "\n$DTTEXT installing cifs"
sudo apt-get install cifs-utils $SLIENT_YES
fi
if [ $INSTALL_git ]; then
printf "\n$DTTEXT installing git"
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update $SLIENT_YES
sudo apt-get install git $SLIENT_YES
fi
if [ $INSTALL_graphicsmagick ]; then
printf "\n$DTTEXT installing graphicsmagick"
sudo apt-get install graphicsmagick $SLIENT_YES
fi
if [ $INSTALL_java7 ]; then
printf "\n$DTTEXT installing java7"
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get install oracle-java7-installer $SLIENT_YES
fi
if [ $INSTALL_java8 ]; then
printf "\n$DTTEXT installing java8"
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get install oracle-java8-installer $SLIENT_YES
fi
if [ $INSTALL_nginx ]; then
printf "\n$DTTEXT installing nginx"
sudo add-apt-repository ppa:nginx/stable
sudo apt-get install nginx $SLIENT_YES
fi
if [ $INSTALL_nvmnodejs ]; then
printf "\n$DTTEXT installing nvm for node/iojs management"
sudo curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
fi
if [ $INSTALL_postgres93 ]; then
printf "\n$DTTEXT installing postgres9.3"
sudo curl -vs https://www.postgresql.org/media/keys/ACCC4CF8.asc 2>&1 | apt-key add -
sudo apt-get update $SLIENT_YES
sudo apt-get install postgresql-9.3 pgadmin3 $SLIENT_YES
printf "\ndeb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >> /etc/apt/sources.list.d/postgresql.list
fi
if [ $INSTALL_samurai ]; then
printf "\n$DTTEXT installing samurai"
sudo curl -LO https://raw.githubusercontent.com/mirageglobe/samurai/master/install.sh | bash
fi
if [ $INSTALL_vim ]; then
printf "\n$DTTEXT installing vim"
sudo apt-get install vim $SLIENT_YES
fi
if [ $INSTALL_x11vncserver ]; then
printf "\n$DTTEXT installing x11vnc"
sudo apt-get install x11vnc $SLIENT_YES
fi
# all the settings here
if [ $SET_java7_default ]; then
printf "\n$DTTEXT setting default java7"
sudo apt-get update $SLIENT_YES
sudo apt-get install oracle-java7-set-default $SLIENT_YES
fi
if [ $SET_java8_default ]; then
printf "\n$DTTEXT setting default java8"
sudo apt-get update $SLIENT_YES
sudo apt-get install oracle-java8-set-default $SLIENT_YES
fi
sudo apt-get autoremove $SLIENT_YES
printf "\n$DTTITLE COMPLETE"
# all installations complete. please run setpasswords to update individual passwords for these applications.
printf "\n$DTTEXT all installations are complete"
printf "\n$DTTEXT please reset the passwords for the applications installed."