Repository navigation
Expand file tree
/
Copy pathdevtools
More file actions
executable file
·131 lines (111 loc) · 4.41 KB
/
Copy pathdevtools
File metadata and controls
executable file
·131 lines (111 loc) · 4.41 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
BTCMAP_DATA_DIR="$HOME/.local/share/btcmap"
echo "BTCMAP_DATA_DIR=$BTCMAP_DATA_DIR"
case "$1" in
main-db)
if [ "$#" -eq 1 ]
then
sqlite3 "$BTCMAP_DATA_DIR/main.db"
else
sqlite3 "$BTCMAP_DATA_DIR/main.db" "$2"
fi
;;
image-db)
if [ "$#" -eq 1 ]
then
sqlite3 "$BTCMAP_DATA_DIR/image.db"
else
sqlite3 "$BTCMAP_DATA_DIR/image.db" "$2"
fi
;;
log-db)
if [ "$#" -eq 1 ]
then
sqlite3 "$BTCMAP_DATA_DIR/log.db"
else
sqlite3 "$BTCMAP_DATA_DIR/log.db" "$2"
fi
;;
fetch-db)
sqlite3_rsync -v --wal-only btcmap-api:.local/share/btcmap/main.db "$BTCMAP_DATA_DIR/main.db"
sqlite3_rsync -v --wal-only btcmap-api:.local/share/btcmap/image.db "$BTCMAP_DATA_DIR/image.db"
sqlite3_rsync -v --wal-only btcmap-api:.local/share/btcmap/log.db "$BTCMAP_DATA_DIR/log.db"
;;
fetch-main-db)
sqlite3_rsync -v --wal-only btcmap-api:.local/share/btcmap/main.db "$BTCMAP_DATA_DIR/main.db"
;;
fetch-image-db)
sqlite3_rsync -v --wal-only btcmap-api:.local/share/btcmap/image.db "$BTCMAP_DATA_DIR/image.db"
;;
fetch-log-db)
sqlite3_rsync -v --wal-only btcmap-api:.local/share/btcmap/log.db "$BTCMAP_DATA_DIR/log.db"
;;
deploy)
cargo test \
&& cargo build --release \
&& rsync -v --progress --stats target/release/btcmap-api btcmap-api:/usr/local/bin/btcmap-api \
&& ssh btcmap-api 'systemctl restart btcmap-api.service'
;;
self-deploy)
# Same as `deploy`, but run on the target machine: no rsync/ssh, just
# rebuild, replace the installed binary and restart the service.
as_root=()
if [ "$(id -u)" -ne 0 ]; then
as_root=(sudo)
fi
cargo test \
&& cargo build --release \
&& "${as_root[@]}" systemctl stop btcmap-api.service \
&& "${as_root[@]}" install -m 755 target/release/btcmap-api /usr/local/bin/btcmap-api \
&& "${as_root[@]}" systemctl start btcmap-api.service
;;
gen-main-schema)
# Generate schema.sql from migrations using temporary SQLite database
rm -f /tmp/schema_gen.db
for f in $(ls -1 src/db/main/migrations/*.sql | sort -V); do
sqlite3 /tmp/schema_gen.db < "$f" 2>/dev/null
done
sqlite3 /tmp/schema_gen.db ".dump" > src/db/main/schema.sql
rm -f /tmp/schema_gen.db
;;
gen-image-schema)
# Generate schema.sql from migrations using temporary SQLite database
rm -f /tmp/schema_gen.db
for f in $(ls -1 src/db/image/migrations/*.sql | sort -V); do
sqlite3 /tmp/schema_gen.db < "$f" 2>/dev/null
done
sqlite3 /tmp/schema_gen.db ".dump" > src/db/image/schema.sql
rm -f /tmp/schema_gen.db
;;
export-ts-types)
# Export the ts-rs TypeScript bindings into a btcmap.org checkout
# (or any target directory). The frontend commits the result.
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$script_dir"
target="${2:-../btcmap.org/src/types/btcmap-api}"
mkdir -p "$target"
TS_RS_EXPORT_DIR="$(cd "$target" && pwd)" cargo test export_bindings \
&& echo "exported TypeScript bindings to $target"
;;
install-completions)
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ "$(id -u)" -ne 0 ]; then
echo "this command must be run as root (use sudo)" >&2
exit 1
fi
user_home=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6)
if [ ! -L /usr/local/bin/devtools ]; then
ln -s "$script_dir/devtools" /usr/local/bin/devtools
echo "created symlink: /usr/local/bin/devtools -> $script_dir/devtools"
else
echo "symlink already exists: /usr/local/bin/devtools"
fi
completion_dir="$user_home/.bash_completion.d"
mkdir -p "$completion_dir"
cp "$script_dir/devtools_completion.bash" "$completion_dir/devtools"
echo "installed completions to: $completion_dir/devtools"
echo ""
echo "add this to your ~/.bashrc to enable completions:"
echo " source $completion_dir/devtools"
;;
esac