-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
executable file
·62 lines (50 loc) · 1.43 KB
/
main.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
#!/bin/bash
# ** imessages-datasette **
# Description: enable reading imessages in the browser.
# Usage:
# -h : display help and exit
# -p : specify datasette port, default 9000
#
# Bash strict mode
set -euo pipefail
# Command Line Options
port=9000
# Configuration constants
CHAT_DB=~/Library/Messages/chat.db
ADDRESS_BOOK=~/Library/Application\ Support/AddressBook/AddressBook-v22.abcddb
display_help() {
# Displays the help message from the top of this file
head -n6 "${BASH_SOURCE[0]}" | tail -n5 | sed -E 's/# ?//g'
}
parse_args() {
while getopts 'p:h' flag; do
case "${flag}" in
h) display_help && exit 0 ;;
p) port="${OPTARG}" ;;
*) error "Unexpected option ${flag}" ;;
esac
done
}
log_error() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]|E|: $@" >&2
}
validate_setup() {
dpath="$(command -v datasette)"
if [[ ! "$dpath" ]]; then
log_error "datasette does not appear to be installed" && exit 1
fi
if [[ "$dpath" == ~/.pyenv/shims/datasette ]] && [[ $(command -v pyenv) ]] && [[ ! $(pyenv which datasette 2>/dev/null) ]]; then
PYENV_VERSION="$(pyenv whence datasette)"
export PYENV_VERSION
fi
}
run_datasette() {
set -x
datasette -p $port --crossdb --plugins-dir=plugins/ --template-dir=templates/ --metadata metadata.json $CHAT_DB "$ADDRESS_BOOK"
}
main() {
parse_args "$@"
validate_setup
run_datasette
}
main "$@"