Skip to content

Commit 6678d00

Browse files
authored
revert function for permissions (#848)
1 parent 50b1796 commit 6678d00

1 file changed

Lines changed: 61 additions & 54 deletions

File tree

‎scripts/lib/utils.sh‎

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,10 @@ make_hash() {
118118

119119
fix_path_ownership() {
120120
local target="$1"
121-
local tmp_list="$2"
122121

123122
[[ -e "$target" ]] || return 0
124123

125-
local owner group start end elapsed
124+
local owner group
126125
owner=$(stat -c '%U' "$target")
127126
group=$(stat -c '%G' "$target")
128127

@@ -132,48 +131,63 @@ fix_path_ownership() {
132131
chown "$USER_NAME:$GEO_GROUP_NAME" "$target"
133132
fi
134133

135-
# If directory, collect mismatches first
136134
[[ -d "$target" ]] || return 0
137135

138-
find "$target" -mindepth 1 \
139-
\( ! -user "$USER_NAME" -o ! -group "$GEO_GROUP_NAME" \) \
140-
> "$tmp_list"
141-
142-
# Iterate mismatches to change permissions
143-
while IFS= read -r file; do
144-
current_user=$(stat -c '%U' "$file")
145-
current_group=$(stat -c '%G' "$file")
146-
147-
if [[ "$current_user" != "$USER_NAME" || "$current_group" != "$GEO_GROUP_NAME" ]]; then
148-
start=$(date +%s)
149-
150-
chown "$USER_NAME:$GEO_GROUP_NAME" "$file"
151-
152-
end=$(date +%s)
153-
elapsed=$((end - start))
136+
if [[ ${VERBOSE_LOGGING} =~ [Tt][Rr][Uu][Ee] ]]; then
137+
find "$target" -mindepth 1 \
138+
\( ! -user "$USER_NAME" -o ! -group "$GEO_GROUP_NAME" \) \
139+
-exec sh -c '
140+
for file do
141+
start=$(date +%s)
142+
chown "$USER_NAME:$GEO_GROUP_NAME" "$file"
143+
end=$(date +%s)
144+
elapsed=$((end - start))
145+
echo -e "\e[32m [Entrypoint] Completed:\033[0m \e[1;31m ${file} \033[0m \e[32m( changed in ${elapsed}s)\033[0m"
146+
done
147+
' sh {} +
148+
else
149+
find "$target" -mindepth 1 \
150+
\( ! -user "$USER_NAME" -o ! -group "$GEO_GROUP_NAME" \) \
151+
-exec chown "$USER_NAME:$GEO_GROUP_NAME" {} +
152+
fi
153+
}
154154

155-
if [[ ${VERBOSE_LOGGING} =~ [Tt][Rr][Uu][Ee] ]]; then
156-
echo -e "\e[32m [Entrypoint] Completed:\033[0m \e[1;31m ${file} \033[0m \e[32m( changed in ${elapsed}s)\033[0m"
155+
gwc_file_perms() {
156+
GEO_USER_PERM=$(stat -c '%U' "${GEOSERVER_DATA_DIR}")
157+
GEO_GRP_PERM=$(stat -c '%G' "${GEOSERVER_DATA_DIR}")
158+
GWC_USER_PERM=$(stat -c '%U' "${GEOWEBCACHE_CACHE_DIR}")
159+
GWC_GRP_PERM=$(stat -c '%G' "${GEOWEBCACHE_CACHE_DIR}")
160+
case "${GEOWEBCACHE_CACHE_DIR}" in ${GEOSERVER_DATA_DIR}/*)
161+
echo -e " \e[32m [Entrypoint] \033[0m \e[1;31m ${GEOWEBCACHE_CACHE_DIR} \033[0m \e[32m is nested in \033[0m \e[1;31m ${GEOSERVER_DATA_DIR} \033[0m"
162+
if [[ ${CHOWN_DATA_DIR} =~ [Tt][Rr][Uu][Ee] ]];then
163+
if [[ ${GEO_USER_PERM} != "${USER_NAME}" ]] && [[ ${GEO_GRP_PERM} != "${GEO_GROUP_NAME}" ]];then
164+
echo -e "\e[32m [Entrypoint] Changing folder permission for:\033[0m \e[1;31m ${GEOSERVER_DATA_DIR} \033[0m"
165+
chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" "${GEOSERVER_DATA_DIR}"
157166
fi
158167
fi
159-
done < "$tmp_list"
168+
;;
169+
*)
170+
echo -e "\e[1;31m ${GEOWEBCACHE_CACHE_DIR} \033[0m is not nested in \e[1;31m ${GEOSERVER_DATA_DIR} \033[0m"
171+
if [[ ${CHOWN_DATA_DIR} =~ [Tt][Rr][Uu][Ee] ]];then
172+
if [[ ${GEO_USER_PERM} != "${USER_NAME}" ]] && [[ ${GEO_GRP_PERM} != "${GEO_GROUP_NAME}" ]];then
173+
echo -e "\e[32m [Entrypoint] Changing folder permission for:\033[0m \e[1;31m ${GEOSERVER_DATA_DIR} \033[0m"
174+
chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" "${GEOSERVER_DATA_DIR}"
175+
fi
176+
fi
177+
if [[ ${CHOWN_GWC_DATA_DIR} =~ [Tt][Rr][Uu][Ee] ]];then
178+
if [[ ${GWC_USER_PERM} != "${USER_NAME}" ]] && [[ ${GWC_GRP_PERM} != "${GEO_GROUP_NAME}" ]];then
179+
echo -e "\e[32m [Entrypoint] Changing folder permission for:\033[0m \e[1;31m ${GEOWEBCACHE_CACHE_DIR} \033[0m"
180+
chown -R "${USER_NAME}":"${GEO_GROUP_NAME}" "${GEOWEBCACHE_CACHE_DIR}"
181+
fi
182+
fi
183+
;;
184+
esac
160185

161-
rm -f "$tmp_list"
162186
}
163187

164-
geo_data_file_perms() {
165-
local target_dir="$1"
166-
[[ -d "$target_dir" ]] || return 1
167-
168-
fix_path_ownership "$target_dir" "/tmp/data_dir_chown_list.txt"
169-
}
170188

171189
fix_permissions() {
172190

173-
change_owner_if_needed() {
174-
fix_path_ownership "$1" "/tmp/fix_ownership_list.txt"
175-
}
176-
177191
if [[ ${RUN_AS_ROOT} =~ [Ff][Aa][Ll][Ss][Ee] ]]; then
178192

179193
dir_ownership=(
@@ -195,38 +209,28 @@ fix_permissions() {
195209
)
196210

197211
for directory in "${dir_ownership[@]}"; do
198-
change_owner_if_needed "$directory"
212+
fix_path_ownership "$directory"
199213
done
200214

201-
change_owner_if_needed "${CLUSTER_CONFIG_DIR}"
202-
change_owner_if_needed "${GEOSERVER_DATA_DIR}/logging.xml"
203-
change_owner_if_needed "${GEOSERVER_DATA_DIR}/jdbcconfig"
204-
change_owner_if_needed "${GEOSERVER_DATA_DIR}/jdbcstore"
205-
change_owner_if_needed "${GEOSERVER_LOG_DIR}"
206-
change_owner_if_needed "${GEOSERVER_DATA_DIR}/cluster"
215+
fix_path_ownership "${CLUSTER_CONFIG_DIR}"
216+
fix_path_ownership "${GEOSERVER_DATA_DIR}/logging.xml"
217+
fix_path_ownership "${GEOSERVER_DATA_DIR}/jdbcconfig"
218+
fix_path_ownership "${GEOSERVER_DATA_DIR}/jdbcstore"
219+
fix_path_ownership "${GEOSERVER_LOG_DIR}"
220+
fix_path_ownership "${GEOSERVER_DATA_DIR}/cluster"
207221
fi
208222

209223
chmod o+rw "${CERT_DIR}"
210224

211225
echo -e "\e[32m [Entrypoint] Fixing Permissions for:\033[0m \e[1;31m ${GEOSERVER_DATA_DIR} && ${GEOWEBCACHE_CACHE_DIR}\033[0m"
212226

213-
if [[ ${CHOWN_DATA_DIR} =~ [Tt][Rr][Uu][Ee] ]];then
214-
geo_data_file_perms "${GEOSERVER_DATA_DIR}"
215-
216-
fi
217-
218-
if [[ ${CHOWN_GWC_DATA_DIR} =~ [Tt][Rr][Uu][Ee] ]];then
219-
geo_data_file_perms "${GEOWEBCACHE_CACHE_DIR}"
220-
fi
221-
222-
227+
gwc_file_perms
223228

224229
find "${CATALINA_HOME}/conf/" -type f -exec chmod 400 {} \;
225230

226-
if [[ ${SAMPLE_DATA} =~ [Tt][Rr][Uu][Ee] ]]; then
227-
change_owner_if_needed "${GEOSERVER_DATA_DIR}"
228-
fi
229231
}
232+
233+
230234
############################################
231235
# 6. FONTS & NATIVE LIBRARIES
232236
############################################
@@ -262,7 +266,10 @@ install_fonts() {
262266

263267
install_sample_data(){
264268
if [[ ${SAMPLE_DATA} =~ [Tt][Rr][Uu][Ee] ]]; then
265-
cp -r "${CATALINA_HOME}"/data/* "${GEOSERVER_DATA_DIR}"
269+
cp -r "${CATALINA_HOME}"/data /tmp/
270+
fix_path_ownership /tmp/data
271+
cp -r /tmp/data/* "${GEOSERVER_DATA_DIR}"
272+
rm -rf /tmp/data
266273
fi
267274
}
268275

0 commit comments

Comments
 (0)