forked from tomogoma/cockroach-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystemdInstaller.sh
executable file
·76 lines (63 loc) · 1.9 KB
/
systemdInstaller.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
#!/bin/bash
APP_DIR="/usr/local/bin"
SYSTEMD_DIR="/etc/systemd/system"
DATA_DIR="/var/data/cockroachdb"
ETC="/etc/cockroachdb"
CERT_DIR="$ETC/certs"
CERT_PRIVATE_DIR="$CERT_DIR/private"
function usage {
printf "Cockroachdb Installer\nUsage: $1 /path/to/cockroachdb.tgz [user]\n"
echo "download cockroachdb tgz file from https://www.cockroachlabs.com"
}
function extractRoach {
mkdir -p "$APP_DIR" || exit 1
tar -xzf "$1" || exit 1
}
function setInstallDirs {
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"
mv -f "$filename/cockroach" "$APP_DIR/cockroach" || exit 1
rm -rf "$filename"
mkdir -p "$DATA_DIR" || exit 1
}
function installCerts {
mkdir -p "$CERT_DIR" || exit 1
mkdir -p "$CERT_PRIVATE_DIR" || exit 1
"$APP_DIR/cockroach" cert create-ca --certs-dir="$CERT_DIR" --ca-key="$CERT_PRIVATE_DIR/ca.key" || exit 1
"$APP_DIR/cockroach" cert create-client root --certs-dir="$CERT_DIR" --ca-key="$CERT_PRIVATE_DIR/ca.key" || exit 1
"$APP_DIR/cockroach" cert create-node localhost $(hostname) --certs-dir="$CERT_DIR" --ca-key="$CERT_PRIVATE_DIR/ca.key" || exit 1
}
function changePerms {
usr=$1
if [ -z "$usr" ];then
return
fi
chown -R "$usr:$usr" "$ETC" #remove the need for sudo when accessing cockroachdb
}
function installService {
mkdir -p "$SYSTEMD_DIR" || exit 1
cp -f cockroach.service "$SYSTEMD_DIR" || exit 1
systemctl enable cockroach.service || exit 1
}
#create cconnect script for easier access to the sql console
function outputConnectUtil {
touch "/usr/local/bin/cconnect"
echo "cockroach sql --certs-dir=/etc/cockroachdb/certs" > "/usr/local/bin/cconnect"
chmod +x "/usr/local/bin/cconnect"
}
## Begin processing script
if [ -z "$1" ]; then
usage $0
exit 1
fi
./systemdUninstaller.sh
echo "Installing..."
extractRoach $1
setInstallDirs $1
installCerts
changePerms $2
installService
outputConnectUtil
echo "Done!"
exit 0