-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.sh
More file actions
executable file
·86 lines (72 loc) · 1.95 KB
/
common.sh
File metadata and controls
executable file
·86 lines (72 loc) · 1.95 KB
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
if [ -n "$CONFIGFILE" ]; then
source "$CONFIGFILE" || exit 1
fi
SCRIPTDIR=${SCRIPTDIR:-$(dirname "$0")}
if [ -z "$CONFIGFILE" ]; then
CONFIGFILE=$SCRIPTDIR/config.sh
if [ -e "$CONFIGFILE" ]; then
source "$CONFIGFILE" || exit 1
else
CONFIGFILE=
fi
fi
PROJECTDIR=${PROJECTDIR:-$SCRIPTDIR/..}
DBDIR=${DBDIR:-$PROJECTDIR/db}
SITEDIR=${SITEDIR:-$PROJECTDIR/site}
DIAGRAMSUBDIR=${DIAGRAMSUBDIR:-theories}
DIAGRAMDIR=${DIAGRAMDIR:-$SITEDIR/$DIAGRAMSUBDIR/%s/%s}
DIAGRAM_FILTERS=${DIAGRAM_FILTERS:-}
DEFAULT_DBDSN=${DEFAULT_DBDSN:-$DBDIR/exploratorium.db}
MASTER_NAME=${MASTER_NAME:-master-%s.md}
DEPLOY_HOST=${DEPLOY_HOST:-remo}
DEPLOY_REMOTEDIR=${DEPLOY_REMOTEDIR:-Exploratorium}
if [ -n "$CONFIGFILE" ]; then
source "$CONFIGFILE" || exit 1
fi
function test_dbfile {
local dbfile="$1"
if [ ! -e "$dbfile" ]; then
echo "$0: DBDSN '$dbfile' does not exist" >&2
exit 1
fi
if [ "$(sqlite3 "$dbfile" "SELECT 'OK'")" != OK ]; then
echo "$0: Error opening DBDSN '$dbfile'" >&2
exit 1
fi
}
function require_sqlite {
local sqlite_version=$(sqlite3 --version 2>/dev/null | cut -f1 -d\ )
IFS=. read major minor rel <<< $sqlite_version
if [ $(printf %02d%03d $major $minor) -lt 3040 ]; then
echo "$0: sqlite3 version $sqlite_version is older than 3.40, which is needed for STRICT tables" >&2
exit 1
fi
local dbfile="$1"
if [ -n "$dbfile" ]; then
test_dbfile "$dbfile"
fi
}
function require_inkscape {
if [ -e "/Applications/Inkscape.app/Contents/MacOS/inkscape" ]; then
echo "/Applications/Inkscape.app/Contents/MacOS/inkscape"
elif [ -e "$HOME"/bin/[Ii]nkscape* ]; then
echo "$HOME"/bin/[Ii]nkscape*
elif ! which inkscape; then
echo "$0: inkscape not found" >&2
exit 1
fi
}
function get_diagram_dir {
printf "$DIAGRAMDIR" "$@"
}
function filter_contexts {
if [ -z "$DIAGRAM_FILTERS" ]; then
cat
return
fi
grep $(
for i in $DIAGRAM_FILTERS; do
echo "-e $i"
done
)
}