-
Notifications
You must be signed in to change notification settings - Fork 3
/
pubsuffix.sh
executable file
·81 lines (68 loc) · 1.57 KB
/
pubsuffix.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
#!/bin/sh
# script that gets and updates the Public Suffix List
# enable for debugging
#set -x
# set group permissions
umask 022
WORKDIR=${HOME}/data/pubsuffix
DSTDIR=${HOME}/etc
DST_PUBSUFFIX=${DSTDIR}/pubsuffix.dat
SRC_PUBSUFFIX=https://publicsuffix.org/list/public_suffix_list.dat
PID=$$
PIDFILE=${WORKDIR}/pubsuffix.pid
DISABLED=${WORKDIR}/pubsuffix.DISABLED
PURGE_TIME=7
CURL=/usr/bin/curl
warning() {
echo ${1:-${DEFAULT_WARNING}} >&2
}
error() {
echo ${1:-${DEFAULT_ERROR}} >&2
exit 1
}
# quit if we are already running
if test -r ${PIDFILE}
then
if [ "$(ps -p `cat ${PIDFILE}` | wc -l)" -gt 1 ]
then
error "script already running"
else
# orphaned pid file
rm ${PIDFILE}
fi
fi
# quit if we are disabled
if test -r ${DISABLED}
then
error "script disabled, remove file to enable: ${DISABLED}"
fi
# make sure work directories exist
if test ! -d ${WORKDIR}
then
mkdir -p ${WORKDIR} || error "mkdir: ${WORKDIR}"
fi
if test ! -d ${DSTDIR}
then
mkdir -p ${DSTDIR} || error "mkdir: ${DSTDIR}"
fi
echo $$ > ${PIDFILE}
if test ! -r ${PIDFILE}
then
error "pidfile creation error: ${PIDFILE}"
fi
# PUBSUFFIX
TMPFILE=${WORKDIR}/`basename ${DST_PUBSUFFIX}`.${PID}
SRCFILE=${SRC_PUBSUFFIX}
DSTFILE=${DST_PUBSUFFIX}
${CURL} -k -s -S -o ${TMPFILE} ${SRCFILE}
if [ "$?" -ne 0 ]
then
error "curl ${SRCFILE} failed"
fi
cp ${TMPFILE} ${DSTFILE} || error "cp ${TMPFILE} failed"
rm ${TMPFILE}
# remove old work files if any exist
find ${WORKDIR} -type f -mtime +${PURGE_TIME} -print | xargs rm -f
# clean up and exit
rm ${PIDFILE}
exit 0