-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-public.sh
executable file
·162 lines (126 loc) · 5.7 KB
/
update-public.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
#!/bin/bash
#
# LICENCE
# This code is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# @author Susanne Gottwald <[email protected]>
# @author Jens Schwidder <[email protected]>
# @copyright Copyright (c) 2011, OPUS 4 development team
# @license http://www.gnu.org/licenses/gpl.html General Public License
# @version $Id$
# Updates the OPUS4 *public* folder
#
# The 'opus4' layout is always updated without further questions.
# If the user is using 'opus4' he is given the option of copying the current
# 'opus4' layout as a new theme, before the 'opus4' layout is updated.
#
# In short, the 'opus4' layout is always updated. User can save the old layout.
set -o errexit
source update-common.sh
setVars
PUBLIC_PATH=opus4/public
OLD_PUBLIC="$BASEDIR/$PUBLIC_PATH"
NEW_PUBLIC="$BASE_SOURCE/$PUBLIC_PATH"
OLD_CONFIG="$BASEDIR/opus4/application/configs"
echo "Updating directory $OLD_PUBLIC ..."
LAYOUTS="$OLD_PUBLIC/layouts"
getProperty "$OLD_CONFIG/config.ini" 'theme'
THEME="$PROP_VALUE"
THEME_OPUS='opus4' # "; theme = opus4"
echo "Selected theme: $THEME"
echo " Default theme: $THEME_OPUS"
# echo "Checking default layout (opus4) for modifications ..."
# TODO IMPORTANT use checkForModifications if opus4 layout has been modified
# Check if no theme or default theme has been configured
if [[ -z "$THEME" ]] || [[ "$THEME" == "$THEME_OPUS" ]]; then
# Default theme is configured
echo -e "You are currently using the standard OPUS4 layout. Any"
echo -e " modifications you made to the layout will be lost during the"
echo -e " update. Would you like to create a copy of the current layout"
echo -e " under a different name [Y/n]? \c "
read ANSWER
if [[ -z "$ANSWER" ]]; then
ANSWER='y' # default is update layout
else
ANSWER=${ANSWER,,} # convert to lowercase
ANSWER=${ANSWER:0:1} # get first letter
fi
if [[ "$ANSWER" == 'y' ]]; then
# User wants to create backup of old layout folder
# Ask for name of new theme
while [[ -z "$THEME_NEW" ]] || [[ -d "$LAYOUTS/$THEME_NEW" ]]; do
echo -e "Please enter name of new theme: \c "
read THEME_NEW
if [[ ! -z "$THEME_NEW" ]]; then
# Check if layout folder already exists
if [[ -d "$LAYOUTS/$THEME_NEW" ]]; then
# Folder already exists
echo "A theme with name '$THEME_NEW' already exists."
fi
fi
done
echo "Creating new theme '$THEME_NEW' ..."
# Copy files from 'opus4' to new folder
copyFolder "$LAYOUTS/$THEME_OPUS" "$LAYOUTS/$THEME_NEW"
# Update configuration to use new theme
setProperty "$OLD_CONFIG/config.ini" "theme" "$THEME_NEW"
# TODO log to UPDATE.log
echo "Your config.ini has been updated (theme = $THEME_NEW)."
fi
fi
# =============================================================================
# Update 'opus4' layout
# =============================================================================
# Output 'opus4' layout changes between releases to file
LAYOUT_CHANGES="$BASEDIR"'/LAYOUT_CHANGES_'"$VERSION_OLD"'_to_'"$VERSION_NEW"'.log'
calculateChanges './opus4/public/layouts/opus4' $LAYOUT_CHANGES
# Add and replace files
updateFolder "$NEW_PUBLIC/layouts/$THEME_OPUS" "$LAYOUTS/$THEME_OPUS"
# Delete files no longer needed
deleteFiles "$NEW_PUBLIC/layouts/$THEME_OPUS" "$LAYOUTS/$THEME_OPUS"
# =============================================================================
# Update 'xsl' folder
# =============================================================================
# Add and replace files
updateFolder "$NEW_PUBLIC/xsl" "$OLD_PUBLIC/xsl"
# Delete files no longer needed
deleteFiles "$NEW_PUBLIC/xsl" "$OLD_PUBLIC/xsl"
# =============================================================================
# Create folder 'series_logos' if necessary
# =============================================================================
SERIES_LOGOS="$OLD_PUBLIC/series_logos"
# Create import folder if it does not exit yet
if [[ ! -d $SERIES_LOGOS ]]; then
createFolder "$SERIES_LOGOS"
fi
# Update other files
# TODO Should this be replace by "updateFolder SRC DEST flat" to handle all files in the folder
copyFile "$NEW_PUBLIC/htaccess-template" "$OLD_PUBLIC/htaccess-template"
copyFile "$NEW_PUBLIC/index.php" "$OLD_PUBLIC/index.php"
# Update .htaccess
FILE=".htaccess"
if askYesNo "Would you like to update file $OLD_PUBLIC/$FILE [Y/n]?"; then
echo "Updating $OLD_PUBLIC/$FILE"
# Make backup of old .htaccess file
copyFile "$OLD_PUBLIC/$FILE" "$OLD_PUBLIC/$FILE.backup.$VERSION_OLD"
# Get value for RewriteBase
REWRITE_BASE=$(grep -v '^[[:space:]]*#' $OLD_PUBLIC/$FILE | grep "^[[:space:]]*RewriteBase[[:space:]]*" | sed "s|[[:space:]]*RewriteBase[[:space:]]*||")
ENABLE_UBUNTU=$(grep -v '^[[:space:]]*#' $OLD_PUBLIC/$FILE | grep "session.gc_probability" || true)
# Replace .htaccess with new template
copyFile "$NEW_PUBLIC/htaccess-template" "$OLD_PUBLIC/.htaccess"
# Set RewriteBase
# TODO do not replace <template> in comment
DRYRUN || sed -i "s|<template>|$REWRITE_BASE|" "$OLD_PUBLIC/$FILE"
if [[ ! -z $ENABLE_UBUNTU ]]; then
echo "Enabling for UBUNTU/DEBIAN"
sed -i 's|#Enable for UBUNTU/DEBIAN:# ||' "$OLD_PUBLIC/$FILE"
fi
fi