-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmd.sh
executable file
·123 lines (101 loc) · 3.5 KB
/
cmd.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
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
#!/bin/bash
# This is a helper script for performing common nebula operations
set -e
if [ ! -z $DEBUG ]; then set -x; fi
# cd to project's root
cd "$( dirname "${BASH_SOURCE[0]}" )"
function nebula {
docker run \
-it --rm \
-v $(pwd)/config:/etc/nebula \
-w /etc/nebula \
mediocregopher/nebula nebula "$@"
}
function nebula_cert {
docker run \
-it --rm \
-u $UID:$GID \
-v $(pwd)/config:/etc/nebula \
-w /etc/nebula \
mediocregopher/nebula nebula-cert "$@"
}
function construct_env {
# first compose the env files into the .env file. docker-compose only reads
# the .env file when filling template variables in docker-compose.yml.
# Luckily it will only honor the last variable to be defined in the case of
# duplicates, so we can just append the user-defined configuration to the
# default.
cp env.default .env
if [ -f env ]; then cat env >> .env; fi
}
NEBULA_CIDR=10.42.0.0/16
case "$1" in
"new-ca")
echo -n "Name of organization: "; read name
nebula_cert ca -name "$name"
;;
"new-host")
echo -n "Owner of machine: "; read owner
echo -n "Hostname of machine: "; read name
echo -n "IP of host (must be in the $NEBULA_CIDR range): "; read ip
if grep -q "$ip" nebula_hosts.txt; then
echo "!!! The ip $ip is already being used !!!"; exit 1
fi
nebula_cert sign -name "$name" -ip "$ip/16"
outer_tmp_dir="config/nebula_configs"
mkdir -p "$outer_tmp_dir"
echo '*' > "$outer_tmp_dir/.gitignore"
tmp_dir="$outer_tmp_dir/$name"
mkdir -p "$tmp_dir/config"
mv "config/$name.crt" "$tmp_dir/config/host.crt"
mv "config/$name.key" "$tmp_dir/config/host.key"
cp "config/ipfs_cluster_secret.txt" "$tmp_dir/config/ipfs_cluster_secret.txt"
(cd $tmp_dir && tar cvzf "../Cryptorado-Node-$name.tgz" *)
rm -rf "$tmp_dir"
echo "$outer_tmp_dir/Cryptorado-Node-$name.tgz has been created, please give it to $owner (but don't commit the file)"
echo ""
echo -e "$owner\t$name\t$ip/16" >> nebula_hosts.txt
echo "$name has been added to nebula_hosts.txt, please commit and push this change"
;;
"ls-peers")
docker-compose exec ipfs-cluster ipfs-cluster-ctl peers ls
;;
"ls-pins")
docker-compose exec ipfs-cluster ipfs-cluster-ctl pin ls
;;
"pin")
if [ -z $2 ]; then
echo "please give path to file/directory which should be pinned"
exit 1
elif [ ! -e "$2" ]; then
echo "path $2 does not contain a file or directory"
exit 1
fi
path="$2"
dst_path=$(mktemp -d -p $(pwd)/ipfs_data/export)
echo "copying $path into $dst_path"
cp -r "$path" "$dst_path/"
echo "pinning $path"
inner_path="/export/$(basename $dst_path)/$(basename $path)"
dt=$(date '+%Y/%m/%d %H:%M:%S %z')
docker-compose exec ipfs-cluster \
ipfs-cluster-ctl add --metadata "dt=$dt" "$inner_path"
;;
"up")
construct_env
docker-compose up -d
;;
"down")
construct_env
docker-compose down
;;
"update")
git pull
./cmd.sh down
./cmd.sh up
;;
*)
# TODO we should probably use a real command-line parsing framework
echo "Usage: cmd.sh <new-ca|new-host|ls-peers|ls-pins|pin|up|down|update>"
exit 1
esac