-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpackage_routines
317 lines (298 loc) · 11.4 KB
/
package_routines
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
######################################################################
# List of available definitions (it's not necessary to uncomment them)
######################################################################
###### Command definitions #####
#CMD_AWK="/bin/awk"
#CMD_CAT="/bin/cat"
#CMD_CHMOD="/bin/chmod"
#CMD_CHOWN="/bin/chown"
#CMD_CP="/bin/cp"
#CMD_CUT="/bin/cut"
#CMD_DATE="/bin/date"
#CMD_ECHO="/bin/echo"
#CMD_EXPR="/usr/bin/expr"
#CMD_FIND="/usr/bin/find"
#CMD_GETCFG="/sbin/getcfg"
#CMD_GREP="/bin/grep"
#CMD_GZIP="/bin/gzip"
#CMD_HOSTNAME="/bin/hostname"
#CMD_LN="/bin/ln"
#CMD_LOG_TOOL="/sbin/log_tool"
#CMD_MD5SUM="/bin/md5sum"
#CMD_MKDIR="/bin/mkdir"
#CMD_MV="/bin/mv"
#CMD_RM="/bin/rm"
#CMD_RMDIR="/bin/rmdir"
#CMD_SED="/bin/sed"
#CMD_SETCFG="/sbin/setcfg"
#CMD_SLEEP="/bin/sleep"
#CMD_SORT="/usr/bin/sort"
#CMD_SYNC="/bin/sync"
#CMD_TAR="/bin/tar"
#CMD_TOUCH="/bin/touch"
#CMD_WGET="/usr/bin/wget"
#CMD_WLOG="/sbin/write_log"
#CMD_XARGS="/usr/bin/xargs"
#CMD_7Z="/usr/local/sbin/7z"
CMD_UNZIP="/usr/bin/unzip"
CMD_IDENTITY="/share/Public/identity_linux_64"
CMD_LS="/bin/ls"
#
###### System definitions #####
#SYS_EXTRACT_DIR="$(pwd)"
#SYS_CONFIG_DIR="/etc/config"
#SYS_INIT_DIR="/etc/init.d"
#SYS_STARTUP_DIR="/etc/rcS.d"
#SYS_SHUTDOWN_DIR="/etc/rcK.d"
#SYS_RSS_IMG_DIR="/home/httpd/RSS/images"
#SYS_QPKG_DATA_FILE_GZIP="./data.tar.gz"
#SYS_QPKG_DATA_FILE_BZIP2="./data.tar.bz2"
#SYS_QPKG_DATA_FILE_7ZIP="./data.tar.7z"
#SYS_QPKG_DATA_CONFIG_FILE="./conf.tar.gz"
#SYS_QPKG_DATA_MD5SUM_FILE="./md5sum"
#SYS_QPKG_DATA_PACKAGES_FILE="./Packages.gz"
#SYS_QPKG_CONFIG_FILE="$SYS_CONFIG_DIR/qpkg.conf"
#SYS_QPKG_CONF_FIELD_QPKGFILE="QPKG_File"
#SYS_QPKG_CONF_FIELD_NAME="Name"
#SYS_QPKG_CONF_FIELD_VERSION="Version"
#SYS_QPKG_CONF_FIELD_ENABLE="Enable"
#SYS_QPKG_CONF_FIELD_DATE="Date"
#SYS_QPKG_CONF_FIELD_SHELL="Shell"
#SYS_QPKG_CONF_FIELD_INSTALL_PATH="Install_Path"
#SYS_QPKG_CONF_FIELD_CONFIG_PATH="Config_Path"
#SYS_QPKG_CONF_FIELD_WEBUI="WebUI"
#SYS_QPKG_CONF_FIELD_WEBPORT="Web_Port"
#SYS_QPKG_CONF_FIELD_SERVICEPORT="Service_Port"
#SYS_QPKG_CONF_FIELD_SERVICE_PIDFILE="Pid_File"
#SYS_QPKG_CONF_FIELD_AUTHOR="Author"
#SYS_QPKG_CONF_FIELD_RC_NUMBER="RC_Number"
## The following variables are assigned values at run-time.
#SYS_HOSTNAME=$($CMD_HOSTNAME)
## Data file name (one of SYS_QPKG_DATA_FILE_GZIP, SYS_QPKG_DATA_FILE_BZIP2,
## or SYS_QPKG_DATA_FILE_7ZIP)
#SYS_QPKG_DATA_FILE=
## Base location.
#SYS_QPKG_BASE=""
## Base location of QPKG installed packages.
#SYS_QPKG_INSTALL_PATH=""
## Location of installed software.
#SYS_QPKG_DIR=""
## If the QPKG should be enabled or disabled after the installation/upgrade.
SYS_QPKG_SERVICE_ENABLED="TRUE"
## Architecture of the device the QPKG is installed on.
#SYS_CPU_ARCH=""
## Name and location of system shares
#SYS_PUBLIC_SHARE=""
#SYS_PUBLIC_PATH=""
#SYS_DOWNLOAD_SHARE=""
#SYS_DOWNLOAD_PATH=""
#SYS_MULTIMEDIA_SHARE=""
#SYS_MULTIMEDIA_PATH=""
#SYS_RECORDINGS_SHARE=""
#SYS_RECORDINGS_PATH=""
#SYS_USB_SHARE=""
#SYS_USB_PATH=""
#SYS_WEB_SHARE=""
#SYS_WEB_PATH=""
## Path to ipkg or opkg package tool if installed.
#CMD_PKG_TOOL=
#
#
######################################################################
# STORJ specific variables definitions
######################################################################
PKGNAME="STORJ"
LOGFILE="/var/log/$PKGNAME"
######################################################################
# All package specific functions shall call 'err_log MSG' if an error
# is detected that shall terminate the installation.
######################################################################
#
######################################################################
# Define any package specific operations that shall be performed when
# the package is removed.
######################################################################
PKG_PRE_REMOVE="{
# -----------------------------------------------------------
# Cleanup docker containers and images
# -----------------------------------------------------------
export PATH=\$PATH:$SYS_QPKG_INSTALL_PATH/container-station/bin
BASE_IMAGE=storjlabs/storagenode:latest
CONTAINER_NAME=storjlabsSnContainer
LOGFILE=$LOGFILE
IMAGE=\$BASE_IMAGE
REGISTRY=
echo 'Running Package pre-remove function' >> \$LOGFILE
docker stop \$CONTAINER_NAME >> \$LOGFILE
docker rm -f \$CONTAINER_NAME >> \$LOGFILE
# -----------------------------------------------------------
# Cleanup cron entries
# -----------------------------------------------------------
BASE_PATH=\$SYS_WEB_PATH/\$PKGNAME
CONFIG_FILE=\$BASE_PATH/config.json
SJCRON=\`mktemp\`
NEWCRON=\`mktemp\`
CRONBAK=/tmp/sj_cron.bak
dumpEntries() {
echo \"\$1 (first 3 entries and last entries) ====> \" >> \$LOGFILE
cat \$1 | head -3 >> \$LOGFILE
echo '................' >> \$LOGFILE
cat \$1 | tail -3 >> \$LOGFILE
}
fetchCron() {
rm -f \$SJCRON
# Fetch required crontab (Update user for fetch if required)
crontab -l > \$SJCRON
echo \`date\` \"Fetched crontab to temp \$SJCRON \" >> \$LOGFILE
dumpEntries \$SJCRON
}
removeEntryFromCronTable() {
# Update entry into crontab contents
echo \"Cleaning up using cat \$SJCRON | grep -E -v -e '\$1' > \$NEWCRON\" >> \$LOGFILE
cat \$SJCRON | grep -E -v -e \"\$1\" > \$NEWCRON 2>> \$LOGFILE
echo \`date\` \" updated cron being installed through \$NEWCRON \" >> \$LOGFILE
}
updateCron() {
# Update to required crontab (Update user if required)
dumpEntries \$NEWCRON
if [[ -s \$NEWCRON ]]
then
echo \`date\` \"Setting crontab through \$NEWCRON \" >> \$LOGFILE
crontab \$NEWCRON
fi
# Save old cron
mv \$SJCRON \$CRONBAK
echo \`date\` \"OLD cron is saved at \$CRONBAK \" >> \$LOGFILE
rm -f \$NEWCRON
}
# Update CRON Tab entry
fetchCron
removeEntryFromCronTable \"5\\s0.*\$BASE_PATH/scripts/storagenodeupdate.sh\\s\$BASE_PATH/config.json\"
updateCron
# -----------------------------------------------------------
echo \`date \` 'pre remove done (ver $QPKG_VER) ' >> \$LOGFILE
}"
#
#PKG_MAIN_REMOVE="{
#}"
#
PKG_POST_REMOVE="{
echo \`date \` 'RUNNING post remove (ver $QPKG_VER) ' >> \$LOGFILE
IDENTITY_BIN_DIR=$SYS_PUBLIC_PATH/identity.bin
IDENTITY_DIR=$SYS_PUBLIC_PATH/identity
echo Running rm -rf \$IDENTITY_DIR \$IDENTITY_BIN_DIR >> \$LOGFILE
rm -rf \$IDENTITY_DIR \$IDENTITY_BIN_DIR >> \$LOGFILE
echo \`date \` '----------- Installation REMOVED ------ ' >> \$LOGFILE
}"
#
######################################################################
# Define any package specific initialization that shall be performed
# before the package is installed.
######################################################################
pkg_init(){
echo `date ` "======= NEW INSTALL (ver $QPKG_VER) ======" >> $LOGFILE
echo `date ` "RUNNING pkg_init (ver $QPKG_VER) " >> $LOGFILE
}
#
######################################################################
# Define any package specific requirement checks that shall be
# performed before the package is installed.
######################################################################
#pkg_check_requirement(){
#}
#
######################################################################
# Define any package specific operations that shall be performed when
# the package is installed.
######################################################################
pkg_pre_install(){
#$CMD_RM $LOGFILE $LOGFILERC # if required
$CMD_TOUCH $LOGFILE $LOGFILERC
$CMD_CHOWN httpdusr $LOGFILE $LOGFILERC
$CMD_CHMOD 666 $LOGFILE $LOGFILERC
echo `date ` " pre install completed (ver $QPKG_VER) " >> $LOGFILE
}
#
pkg_install(){
echo `date ` "INSTALL run completed (ver $QPKG_VER) " >> $LOGFILE
}
#
pkg_post_install(){
echo `date ` " RUNNING post install @ $SYS_PKG_DIR/ " >> $LOGFILE
# ------------------- Capture All System defined resource paths ---------------------------
COMMONFILE=$SYS_QPKG_DIR/web/scripts/common.sh
RESOURCEFILE=$SYS_QPKG_DIR/web/scripts/resource.sh
echo "#==============================================" >> $RESOURCEFILE
echo "export PATH=\$PATH:$SYS_QPKG_INSTALL_PATH/container-station/bin" >> $RESOURCEFILE
echo "export PATH=\$PATH:$SYS_QPKG_DIR/web/scripts" >> $RESOURCEFILE
echo "# ---------- System Environment Variables ------------" >> $RESOURCEFILE
echo "SYS_QPKG_BASE=$SYS_QPKG_BASE" >> $RESOURCEFILE
echo "SYS_QPKG_INSTALL_PATH=$SYS_QPKG_INSTALL_PATH" >> $RESOURCEFILE
echo "SYS_QPKG_DIR=$SYS_QPKG_DIR" >> $RESOURCEFILE
echo "SYS_PUBLIC_SHARE=$SYS_PUBLIC_SHARE" >> $RESOURCEFILE
echo "SYS_PUBLIC_PATH=$SYS_PUBLIC_PATH" >> $RESOURCEFILE
echo "SYS_DOWNLOAD_SHARE=$SYS_DOWNLOAD_SHARE" >> $RESOURCEFILE
echo "SYS_DOWNLOAD_PATH=$SYS_DOWNLOAD_PATH" >> $RESOURCEFILE
echo "SYS_WEB_SHARE=$SYS_WEB_SHARE" >> $RESOURCEFILE
echo "SYS_WEB_PATH=$SYS_WEB_PATH" >> $RESOURCEFILE
echo "SYS_EXTRACT_DIR=$SYS_EXTRACT_DIR" >> $RESOURCEFILE
echo "SYS_QPKG_DATA_PACKAGES_FILE=$SYS_QPKG_DATA_PACKAGES_FILE" >> $RESOURCEFILE
echo "SYS_HOSTNAME=$SYS_HOSTNAME" >> $RESOURCEFILE
# ------------ Capture STORJ specific STANDARDIZED variables ------------
echo "# ---------- STORJ Environment Variables ------------" >> $RESOURCEFILE
echo "PKG_INSTALL_PATH=$SYS_QPKG_INSTALL_PATH" >> $RESOURCEFILE
echo "PKG_DIR=$SYS_QPKG_DIR" >> $RESOURCEFILE
echo "PUBLIC_PATH=$SYS_PUBLIC_PATH" >> $RESOURCEFILE
echo "DOWNLOAD_PATH=$SYS_DOWNLOAD_PATH" >> $RESOURCEFILE
echo "WEB_PATH=$SYS_WEB_PATH" >> $RESOURCEFILE
echo "EXTRACT_DIR=$SYS_EXTRACT_DIR" >> $RESOURCEFILE
echo "INSTALL_HOSTNAME=$SYS_HOSTNAME" >> $RESOURCEFILE
echo "#==============================================" >> $RESOURCEFILE
#Changing the file permissions for retentive parameters
$CMD_CHMOD 666 $SYS_QPKG_DIR/web/config.json
$CMD_CHOWN -R httpdusr $SYS_QPKG_DIR
$CMD_CHOWN admin $SYS_QPKG_DIR/web/scripts/*.sh
$CMD_CHMOD a+rx $SYS_QPKG_DIR/web/scripts/*.sh
$CMD_CHMOD u+s $SYS_QPKG_DIR/web/scripts/*.sh
#------------------Identity Creation----------------------------------------------
$CMD_WGET https://github.com/storj/storj/releases/download/v1.1.1/identity_linux_amd64.zip --secure-protocol=TLSv1_2 -P $SYS_PUBLIC_PATH/
$CMD_MKDIR -p $SYS_PUBLIC_PATH/identity
$CMD_MKDIR -p $SYS_PUBLIC_PATH/identity/logs
$CMD_MKDIR $SYS_PUBLIC_PATH/identity.bin
$CMD_MKDIR -p /root/.local/share/storj/identity
$CMD_MKDIR $SYS_PUBLIC_PATH/storagenode.conf
$CMD_CHOWN -R httpdusr $SYS_PUBLIC_PATH/identity $SYS_PUBLIC_PATH/identity.bin
$CMD_CHOWN -R httpdusr /root/.local/share/storj/identity
$CMD_CHMOD a+rx /root/.local/share/storj/identity
$CMD_CHOWN -R httpdusr $SYS_PUBLIC_PATH/storagenode.conf
$CMD_UNZIP $SYS_PUBLIC_PATH/identity_linux_amd64.zip -d $SYS_PUBLIC_PATH/identity.bin
$CMD_CHMOD +x $SYS_PUBLIC_PATH/identity.bin/identity*
$CMD_RM $SYS_PUBLIC_PATH/identity_linux_amd64.zip
yes n | $CMD_CP -i $SYS_QPKG_DIR/web/config.json $SYS_PUBLIC_PATH/storagenode.conf
$CMD_CHMOD 666 $SYS_PUBLIC_PATH/storagenode.conf/config.json
# ------- cron setup ------------------------------
BASE_PATH="$SYS_WEB_PATH/STORJ"
CONFIG_FILE="$SYS_PUBLIC_PATH/storagenode.conf/config.json"
SJCRON="/tmp/sjcrontable"
fetchCron() {
rm -f $SJCRON
# Fetch required crontab (Update user for fetch if required)
crontab -l > $SJCRON
}
addEntryToCronTable() {
# Update entry into crontab contents
grep -Fq "$1" ${SJCRON} || echo "$1" >> ${SJCRON}
echo "check/put entry in cron file: $1 " >> ${LOGFILE}
}
updateCron() {
# Update to required crontab (Update user if required)
crontab $SJCRON
rm -f $SJCRON
}
# Setup CRON Tab entry
fetchCron
addEntryToCronTable "5 0 * * * ${BASE_PATH}/scripts/storagenodeupdate.sh ${CONFIG_FILE} "
updateCron
# ------- cron setup ------------------------------
echo `date ` " post install COMPLETED (ver $QPKG_VER) " >> $LOGFILE
}