File size: 2,119 Bytes
2e3030d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/sh

# Code updated based on a bug report in Ubuntu:
#   Bug #1999259 reported by Kyler Laird on 2022-12-09

set -e

# Get the effective UID, but do so in a compatible way (we may be running dash)
euid=${EUID:-$(id -u)}

if [ "${euid}" -ne 0 ]; then
	echo "Please run as root"
	exit 1
fi

if [ -f "@CIFPP_ETC_DIR@/libcifpp.conf" ]; then
	. "@CIFPP_ETC_DIR@/libcifpp.conf"
fi

# check to see if we're supposed to run at all
if [ "$update" != "true" ]; then
	exit 0
fi

# if cache directory doesn't exist, exit.
if ! [ -d "@CIFPP_CACHE_DIR@" ]; then
	echo "Cache directory '@CIFPP_CACHE_DIR@' does not exist"
	exit 1
fi

# Create a temp file in the right directory and
# make sure it is cleaned up when this script exits

tmpfile=$(mktemp)
trap "rm -f \"${tmpfile}\"" EXIT

update_dictionary() {
	dict=$1
	source=$2

	# Using curl with
	# --location (follow redirects)
	# --silent (no diagnostic output at all)
	# --time-cond (only fetch if source is newer)
	#
	# Output is extracted and written to $tmpfile and when successful 
	# the tmpfile is placed at the desired location and updated is set
	# to true

	curl --silent --location --compressed --time-cond "${dict}" "${source}" | (
		# uncompress the file on the fly, if it is compressed
		if [ "${source%.gz}" != "${source}" ]; then
			gunzip -c > "${tmpfile}" 2>/dev/null
		else
			cat > "${tmpfile}"
		fi
	) && (
		mv "${tmpfile}" "${dict}" && chmod a+r "${dict}"
	) || true
}

# Update the dictionaries

update_dictionary "@CIFPP_CACHE_DIR@/components.cif" "https://files.wwpdb.org/pub/pdb/data/monomers/components.cif.gz"
update_dictionary "@CIFPP_CACHE_DIR@/mmcif_pdbx.dic" "https://mmcif.wwpdb.org/dictionaries/ascii/mmcif_pdbx_v50.dic.gz"
update_dictionary "@CIFPP_CACHE_DIR@/mmcif_ma.dic" "https://github.com/ihmwg/ModelCIF/raw/master/dist/mmcif_ma.dic"

# notify subscribers, using find instead of run-parts to make it work on FreeBSD as well

if [ -d "@CIFPP_ETC_DIR@/libcifpp/cache-update.d" ]; then
	find "@CIFPP_ETC_DIR@/libcifpp/cache-update.d" \
		-exec test -x {} \; -and -not -exec test -d {} \; \
		-exec {} "@CIFPP_CACHE_DIR@" \;
fi

exit 0