blob: 20fe342d057e54de852bc7cae62db422bbbec581 (
plain) (
blame)
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
|
#!/usr/bin/env sh
set -euo pipefail
getconfig() {
nix eval --impure --expr "(import ./settings.nix { lib = (import <nixpkgs> {}).lib; })$@" | jq -r
}
HOME_HOST="$(getconfig .network.host)"
SSH_PORT="$(getconfig .network.ports.ssh)"
SSH_TARGET="bacchus@$HOME_HOST"
SCRIPT_PATH="$(readlink -f "$0")"
run_ssh() { ssh -t "$SSH_TARGET" -p "$SSH_PORT" "$@"; }
copy() { rsync -ravh --delete --exclude '.git' -e "ssh -p $SSH_PORT" "$@"; }
waittostart() {
echo "Waiting...";
until timeout 2 nc -z "$HOME_HOST" "$SSH_PORT" 2> /dev/null; do
echo -n '.';
sleep 1
done;
echo -e "\nReady to connect";
}
copy_in() { copy "$1" "$SSH_TARGET:$2"; }
copy_out() { copy "$SSH_TARGET:$1" "$2"; }
config_sync() {
copy_out '~/nixos/flake.lock' .;
copy_in . '~/nixos';
}
rebuild() {
run_ssh sudo nixos-rebuild switch --flake 'path:/home/bacchus/nixos#bacchus';
}
update_system() {
run_ssh nix flake update --flake 'path:/home/bacchus/nixos';
rebuild;
}
restart() { run_ssh sudo systemctl reboot; }
chaincmds() {
for arg in "$@"; do
echo "Running: $arg...";
"$SCRIPT_PATH" "$arg";
done
}
gen_test_dash() {
nix eval --impure \
--expr 'import ./modules/dashboard/dashboard-template.nix { title = "Dashboard"; links = [{ title = "Google"; url = "https://google.com"; altUrl = "http://foobar.com"; key = "g"; } { title = "DuckDuckGo"; url = "https://duckduckgo.com"; key = "d"; color = "#4c82cf"; } { title = "Google"; url = "https://google.com"; altUrl = "http://foobar.com"; key = "g"; } { title = "Google"; url = "https://google.com"; altUrl = "http://foobar.com"; key = "g"; }]; }' \
| jq -r > index.ignore.html
}
open_test_dash() { brave "file://$PWD/index.ignore.html"; }
cmd="$1"; shift;
case "$cmd" in
sync) config_sync ;;
run) run_ssh "$@" ;;
build) rebuild ;;
update) update_system ;;
restart) restart && sleep 3 && waittostart ;;
wait) waittostart ;;
clean) run_ssh sudo nix-collect-garbage -d ;;
top) run_ssh btm ;;
fs) run_ssh lf ;;
test-dash) gen_test_dash ;;
open-test-dash) open_test_dash ;;
dash) brave "http://$HOME_HOST" ;;
copy_in) copy_in "$@" ;;
copy_out) copy_out "$@" ;;
_) chaincmds "$@" ;;
*) echo "Invalid cmd: $cmd" && exit 1 ;;
esac
|