-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-modules.sh
executable file
·147 lines (128 loc) · 5.85 KB
/
update-modules.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
#!/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 *modules* directory
# Update process for modules:
# For each module every file found is checked against the MD5 file. If the file
# was part of the old distribution and was not changed it is deleted. Empty
# folders are deleted. Afterwards the new files are transferred to the module
# folder. If a file already exists, the existing file is renamed to
# FILENAME.backup.VERSION_OLD and replaced by the new file.
# The resulting folder contains all new files, backups of old modified files,
# and any extra files created by the user.
#
# Short version:
# Unmodified files => Replace with new files
# Modified files => Rename to FILENAME.backup.VERSION_OLD and replace with new files
# Unknown files => Keep
#
# TODO Explain how files are handled that were removed from the distribution?
set -o errexit
source update-common.sh
setVars
MODULES_PATH="opus4/modules"
OLD_MODULES="$BASEDIR/$MODULES_PATH"
NEW_MODULES="$BASE_SOURCE/$MODULES_PATH"
echo "Updating $OLD_MODULES ..."
# =============================================================================
# Update or delete existing files
# =============================================================================
# Hinweise zum Update des "modules" Verzeichnisses.
# In frontdoor/view/scripts/index kann es eine Datei index_custom.xslt geben,
# die beim Update nicht gelöscht werden darf. Die Datei wird von Nutzern lokal
# angelegt.
# Iterate through module files
find "$OLD_MODULES" -type f -print0 | while read -r -d $'\0' FILE_PATH; do
FILE=$(echo "$FILE_PATH" | sed -e "s|$OLD_MODULES/||")
DEBUG "Update $FILE"
# Get reference MD5 for file
FILE_MD5_REFERENCE="$(getMD5 $MODULES_PATH/$FILE $MD5_OLD)"
DEBUG "MD5 ref = $FILE_MD5_REFERENCE"
# Calculate MD5 for existing file
FILE_MD5_ACTUAL="$(getActualMD5 $OLD_MODULES/$FILE)"
DEBUG "MD5 cur = $FILE_MD5_ACTUAL" # TODO Why get spaces lost?
# Get reference MD5 for new file
FILE_MD5_NEW="$(getMD5 $MODULES_PATH/$FILE $MD5_NEW)"
DEBUG "MD5 new = $FILE_MD5_NEW"
# Check if file is part of old distribution (MD5 reference exists)
if [ ! -z "$FILE_MD5_REFERENCE" ]; then
# MD5 reference found; File part of old distribution
# Check if File was modified
if [ "$FILE_MD5_REFERENCE" == "$FILE_MD5_ACTUAL" ]; then
# File was not modified
# Check if new version exists
if [ ! -z "$FILE_MD5_NEW" ]; then
# New version of file exists; Replace it
copyFile "$NEW_MODULES/$FILE" "$OLD_MODULES/$FILE"
else
# File no longer part of new distribution; Delete it
deleteFile "$OLD_MODULES/$FILE"
fi
else
# Log conflict requiring manual attention
addConflict "$OLD_MODULES/$FILE"
# File was modified
# Check if new version exists
if [ ! -z "$FILE_MD5_NEW" ]; then
# New version of file exists; Rename file, copy new file
renameFile "$OLD_MODULES/$FILE" "$OLD_MODULES/$FILE.backup.$VERSION_OLD"
# Copy new file
copyFile "$NEW_MODULES/$FILE" "$OLD_MODULES/$FILE"
else
# File no longer part of new distribution; Rename file
renameFile "$OLD_MODULES/$FILE" "$OLD_MODULES/$FILE.backup.$VERSION_OLD"
fi
fi
else
# MD5 reference not found; File not part of old distribution
# Check if new distribution contains file
if [ ! -z "$FILE_MD5_NEW" ]; then
# New distribution contains file; Rename file, copy new file
renameFile "$OLD_MODULES/$FILE" "$OLD_MODULES/$FILE.backup.$VERSION_OLD"
# Copy new file
copyFile "$NEW_MODULES/$FILE" "$OLD_MODULES/$FILE"
else
# File not part of new distribtution either
DEBUG "Unknown file $FILE (do nothing)"
fi
fi
done
# =============================================================================
# Delete empty folders
# =============================================================================
# Iterate through found empty folders
find "$OLD_MODULES" -name '.svn' -prune -o -type d -empty -print0 | while read -r -d $'\0' FILE_PATH; do
FILE=$(echo "$FILE_PATH" | sed -e "s|$OLD_MODULES/||")
DEBUG "Empty folder $FILE found"
# Delete empty folders
# TODO Find way to add message like "(EMPTY)" to UPDATE.log
deleteFolder "$OLD_MODULES/$FILE" empty
done
# =============================================================================
# Add new files from the new distribution
# =============================================================================
# Iterate through all new modules files
find "$NEW_MODULES" -type f -print0 | while read -r -d $'\0' FILE_PATH; do
FILE=$(echo "$FILE_PATH" | sed -e "s|$NEW_MODULES/||")
# Check if file does not exist in old modules folder
# If file exists it has been already processed above.
if [ ! -f "$OLD_MODULES/$FILE" ]; then
# File does not exist in old folder; Add it
copyFile "$NEW_MODULES/$FILE" "$OLD_MODULES/$FILE"
fi
done