-
Notifications
You must be signed in to change notification settings - Fork 124
/
install.sh
executable file
·159 lines (125 loc) · 3.96 KB
/
install.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
set -e
VERSION="v1.3.0"
gitDir=$(realpath `dirname $BASH_SOURCE`/..)
echo $gitDir
# uname -s, uname -m
# Deb 32: Linux i686
# Ubuntu 64: Linux x86_64
# FreeBSD: FreeBSD amd64
if [[ "$UID" != 0 ]]; then
echo NOTE: sudo needed to set up and run start service
exit 1
fi
if [[ ! "`which git 2> /dev/null`" == "" ]]; then
thisGit=`git -C "${gitDir}" config --get remote.origin.url`
thisGit=${thisGit::-4}
GITHUB_BINARY_BASE="${thisGit}/releases/download"
GITHUB_RAW_BASE="${thisGit/github.com/raw.githubusercontent.com}/releases/download"
fi
if [[ $thisGit == "" ]]; then
GITHUB_URL_PARTS="MatchbookLab/local-persist"
GITHUB_BINARY_BASE="https://github.com/${GITHUB_URL_PARTS}/releases/download"
GITHUB_RAW_BASE="https://raw.githubusercontent.com/${GITHUB_URL_PARTS}/"
GITHUB_URL_PARTS=
fi
function setenv {
OS=$(uname -s | tr "[:upper:]" "[:lower:]")
ARCH=$(uname -m)
SUPPORTED=false
if [[ $OS == "linux" ]]; then
case $ARCH in
"x86_64")
ARCH="amd64"
SUPPORTED=true
;;
"aarch64")
ARCH="arm64"
SUPPORTED=true
;;
"i686")
# ARCH="386"
SUPPORTED=false
;;
# untested
arm*)
# ARCH="arm"
SUPPORTED=false
;;
esac
elif [[ $OS == 'freebsd' ]]; then
ARCH=$(uname -m)
SUPPORTED=false
fi
if [[ $SUPPORTED == false ]]; then
echo $OS $ARCH is not supported
exit 2
fi
}
function install-binary {
echo Stopping docker-volume-local-persist service if running
echo ''
if [[ $* == *--upstart* ]]; then
(sudo service docker-volume-local-persist stop || true)
else
(sudo systemctl stop docker-volume-local-persist || true)
fi
BINARY_URL="${GITHUB_BINARY_BASE}/${VERSION}/local-persist-${OS}-${ARCH}"
BINARY_DEST="/usr/bin/docker-volume-local-persist"
echo Downloading binary:
echo " From: $BINARY_URL"
echo " To: $BINARY_DEST"
curl -fLsS "$BINARY_URL" > $BINARY_DEST
chmod +x $BINARY_DEST
echo Binary download
echo ''
}
# Systemd (default)
function setup-systemd {
SYSTEMD_CONFIG_URL="${GITHUB_RAW_BASE}/${VERSION}/init/systemd.service"
SYSTEMD_CONFIG_DEST="/etc/systemd/system/docker-volume-local-persist.service"
echo Downloading Systemd service conf:
echo " From: $SYSTEMD_CONFIG_URL"
echo " To: $SYSTEMD_CONFIG_DEST"
sudo curl -fLsS "$SYSTEMD_CONFIG_URL" > $SYSTEMD_CONFIG_DEST
echo Systemd conf downloaded
echo ''
}
function start-systemd {
echo Starting docker-volume-local-persist service...
sudo systemctl daemon-reload
sudo systemctl enable docker-volume-local-persist
sudo systemctl start docker-volume-local-persist
sudo systemctl status --full --no-pager docker-volume-local-persist
echo ''
echo Done! If you see this message, that should mean everything is installed and is running.
}
# Upstart
function setup-upstart {
UPSTART_CONFIG_URL="${GITHUB_RAW_BASE}/${VERSION}/init/upstart.conf"
UPSTART_CONFIG_DEST="/etc/init/docker-volume-local-persist.conf"
echo Downloading binary:
echo " From: $UPSTART_CONFIG_URL"
echo " To: $UPSTART_CONFIG_DEST"
sudo curl -fLsS "$UPSTART_CONFIG_URL" > $UPSTART_CONFIG_DEST
echo Upstart conf downloaded
echo ''
}
function start-upstart {
echo Reloading Upstart config and starting docker-volume-local-persist service...
sudo initctl reload-configuration
sudo service docker-volume-local-persist start
sudo service docker-volume-local-persist status
echo ''
echo Done! If you see this message, that should mean everything is installed and is running.
}
setenv
if [[ $* == *--upstart* ]]; then
install-binary --upstart
setup-upstart
start-upstart
else
install-binary
setup-systemd
start-systemd
fi