-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkp-manager.sh
311 lines (254 loc) · 8.6 KB
/
pkp-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
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
#!/bin/bash
# To-Do:
# * Check if app's config file variable files_dir is same as $pkpAppDataPath (config-local.inc.sh)
# Get the Functions Library
source lib_pkp-manager.inc.sh
while getopts ":a:v:u:l:d:t" opt; do
case $opt in
a) # --application / PKP application name
# as defined in config-local.inc.sh
pkpApp="$OPTARG"
;;
### BEGIN To-Do: commented out on 20240131 - delete if not needed ###
### Variable pkpAppVersion now defined in config.inc.sh
# v) # --version / PKP application version
# # If option is 'local' check locally installed PKP application
# if [[ $OPTARG = 'local' ]]; then
# # pkpAppVersion="${pkpAppCodeVersion}"
# pkpSource="zzff"
# elif [[ $OPTARG = 'latest' ]]; then
# configPostProcessing["pkpAppVersion"]="latest"
# #pkpAppVersion="$(getLatestVersionNumber)"
# pkpSource="release"
# else
# pkpAppVersion="$OPTARG"
# pkpSource="release"
# fi
# ;;
### END commented out on 20240131 - delete if not needed ###
u) # --upgrade-version / PKP application version to upgrade to
# i.e. 3.4.0.5
pkpAppUpgradeVersion="${OPTARG}"
;;
l) # --locale / PKP application locale
pkpAppLocale="$OPTARG"
;;
d) # --database / Use full or trimmed database
# you can use multiple -d optopns: -d latest -d full
if [[ $OPTARG =~ ^(full|trim)$ ]]; then
syncDatabaseVersion="$OPTARG"
elif [[ $OPTARG =~ ^20[0-9]{6}-[0-9]$ ]]; then
databaseBackupDate="$OPTARG"
else
parseOutput warning "\t'$OPTARG' is not an valid value for option '-d'"
exit 1
fi
;;
t) # --test-run / Run script with commands printed out instead of executed
testRun=1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Remove options that have already been handled from $@
shift $((OPTIND -1))
# Parameters
subcommand="${1}"
# Get configurations and application variables
source config.inc.sh "${pkpApp}"
case "$subcommand" in
sync-backup)
# Rsync files from backup server
checkIfRoot "${subcommand}"
checkIfSSHKey
syncBackupFiles
# pkpConvertDatabase
;;
finish-sync)
checkIfRoot "${subcommand}"
emptyDatabase
importDatabase
copyConfigurationFiles
fixCodeFilePermissions
fixDataFilePermissions
;;
revert-upgrade)
checkIfRoot "${subcommand}"
emptyDatabase
importDatabase
copyConfigurationFiles
fixCodeFilePermissions
fixDataFilePermissions
;;
sync-database)
checkIfRoot "${subcommand}"
emptyDatabase
importDatabase
copyConfigurationFile
;;
fix-file-permissions)
fixCodeFilePermissions
fixDataFilePermissions
;;
sync-local-app)
checkIfRoot "${subcommand}"
checkIf_syncDatabaseVersion
syncAppCode
fixConfigurationFile
emptyDatabase
importDatabase
fixCodeFilePermissions
fixDataFilePermissions
;;
prepare-upgrade-core)
checkIfRoot "${subcommand}"
checkIf_pkpAppUpgradeVersion
getVersionReleaseFiles $pkpAppVersion
getVersionReleaseFiles $pkpAppUpgradeVersion
get_customPlugins
download_customPlugins
;;
upgrade-check)
checkIfRoot "${subcommand}"
checkIf_pkpAppUpgradeVersion
upgrade_check
;;
upgrade-core)
checkIfRoot "${subcommand}"
checkIf_pkpAppUpgradeVersion
# prepare_upgradeVersionCode
upgradePkpApp
;;
prepare-core-package)
checkIfRoot "${subcommand}"
checkIf_pkpAppUpgradeVersion
prepare_upgradePackage
# makeUpgradePackage
;;
prepare-upgrade-plugins)
checkIfRoot "${subcommand}"
checkIf_pkpAppUpgradeVersion
prepare_missingCustomPlugins "paperbuzz dates"
;;
upgrade-plugins)
checkIfRoot "${subcommand}"
checkIf_pkpAppUpgradeVersion
prepare_upgradeVersionPlugins
fixCodeFilePermissions
upgradePkpApp
;;
cleanup-failed-upgrade)
parseOutput title "Cleaning up after failed update"
mysqlDump_fileName="$(find ../journals-test.uni-lj.si/ -name "${pkpAppName}-UL-${pkpAppName}-*.sql.gz" | sort | tail -1)"
# Drop database
parseOutput emphasis "Droping all tables from ${mysqlDump_fileName}"
mysqldump --add-drop-table --no-data ${pkpAppDatabaseName} \
| grep -e '^DROP TABLE' \
| (echo "SET FOREIGN_KEY_CHECKS=0;"; cat; echo "SET FOREIGN_KEY_CHECKS=1;") \
| mysql ${pkpAppDatabaseName}
# Import latest local database backup copy
parseOutput emphasis "Importing ${mysqlDump_fileName} to ${mysqlDump_fileName} "
zcat ${mysqlDump_fileName} \
| sed '/INSERT INTO `metrics`/d' \
| sed '/INSERT INTO `submission_search_object_keywords`/d' \
| mysql ${pkpAppDatabaseName}
;;
fix-file-permissions)
fixCodeFilePermissions
fixDataFilePermissions
;;
test)
echo "$syncDatabaseVersion"
echo "$databaseBackupDate"
;;
*)
echo "The subcommand is missing!"
exit 1
;;
##
## Options below are not yet ported or tested with pkp-manager scripts
##
#
# check-locale)
#
# # Check the installed OMP version
# # Returns $ompCodeVersion $ompDatabaseVersion $ompLatestVersion
# checkInstalledOMPVersions
#
# while read localeFile; do
#
# foundFile="$(echo "$localeFile" | sed "s|${ompCode}/||g")"
#
# # Compare with language pack generated from OMP admin interface using Translate plugin
# # if [[ -f ${languagePackRoot}/${ompCodeVersion}/${ompLocale}/$foundFile ]]; then
# # Compare with files in freshly unpacked version package
# if [[ -f ${omara}/downloads/omp-$ompCodeVersion/$foundFile ]]; then
#
# echo 'OK'
#
# else
#
# echo "Missing: $foundFile"
#
# fi
#
# done <<<"$(listLocaleFiles "$ompLocale")"
# ;;
#
save-locale-files)
# Check if all needed variables are set
checkIfVersionSet
checkIfLocaleSet
# Root folder for language pack
if [[ $ompSource == 'zzff' ]]; then
langPackRootSource="$ompCode"
langPackRootDestination="$languagePackRoot/$ompVersion/$ompLocale-zzff"
elif [[ $ompSource == 'release' ]]; then
langPackRootSource="${omara}/downloads/omp-$ompVersion"
langPackRootDestination="$languagePackRoot/$ompVersion/$ompLocale-release"
fi
# Check if language package folder already exsist / create it
if [[ -d $langPackRootDestination ]]; then
echo "Files for version $ompVersion and locale $ompLocale already exist."
# exit 1
else
mkdir -p $langPackRootDestination
fi
while read localeFile; do
# Get relative file path
foundFile="$(echo "$localeFile" | sed "s|${langPackRootSource}/||g")"
# Check if language pack folder exists / create it
if [[ ! -d $(dirname $langPackRootDestination/$foundFile) ]]; then
mkdir -p $(dirname $langPackRootDestination/$foundFile)
fi
# Copy the locale file to $langPackRootDestination
cp $localeFile $langPackRootDestination/$foundFile
done <<<"$(listLocaleFiles)"
# Change language pack file ownership
chown -R mitja:mitja $langPackRootDestination
;;
#
# *)
# echo -e "\n NAME"
# echo -e "\t manage-omp-test-installation.sh - Bash script for managing OMP instlation(s)"
# echo -e "\n SYNOPSIS"
# echo -e "\t manage-omp-test-installation.sh [option]... [command]..."
# echo -e "\n DESCRIPTION"
# echo -e "\t Manage local OMP installation. First list options, then specify the command to be executed."
# echo -e "\n\t -l"
# echo -e "\t\t specify locale"
# echo -e "\n\t -v"
# echo -e "\t\t specify OMP version"
# echo -e "\n"
# exit 3
# ;;
esac
# Izpis časa trajanja
printf "\n |—> Script finished in %d seconds" $SECONDS
convertsecs $SECONDS