-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpreflight.sh
52 lines (41 loc) · 1.35 KB
/
preflight.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
#!/usr/bin/env bash
set -e
# shellcheck disable=SC2153
if [ -n "${PATHS}" ]; then
PATH=${PATHS}:$PATH
fi
export PATH=$PATH
_nodepath=$(command -v node || true)
if [ -z "$_nodepath" ]; then
echo '{"items":[{"title":"Did not find Node", "valid":false}]}'
exit
fi
function file_last_modified() {
stat -f '%m' "$1"
}
function store_last_modified() {
file_last_modified "$1" >"$2"
}
# databases live here
_path=$HOME'/Library/Group Containers/group.com.lukilabs.lukiapp.share/Realms'
# main database
_filename=$(ls "$_path" | grep 'LukiMain.*realm$' | grep -v '\|' | head -n 1)
export _spaceID=$(echo "$_filename" | cut -d_ -f2)
_copybase="workflow_$_spaceID.realm"
_orig_db_path="$_path/$_filename"
_copy_db_path="$_path/$_copybase"
_orig_db_stat_snapshot="$_path/workflow_orig_$_spaceID.stat"
# need to copy the original db elsewhere: if opened with Craft, then cannot be accessed by anyone else
# if the file does not exist yet
if [ ! -e "$_copybase" ]; then
cp "$_orig_db_path" "$_copy_db_path"
store_last_modified "$_orig_db_path" "$_orig_db_stat_snapshot"
else
_curr_stat=$(file_last_modified "$_orig_db_path")
_cat_stat=$(cat "$_orig_db_stat_snapshot")
# make a new copy only when the
if [ "$_curr_stat" != "$_cat_stat" ]; then
cp "$_path/$_filename" "$_path/$_copybase"
store_last_modified "$_orig_db_path" "$_orig_db_stat_snapshot"
fi
fi