-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
112 lines (98 loc) · 2.59 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
#!/bin/sh
set -e
usage(){
echo 'install.sh linux|darwin|windows [OPTIONS]'
echo 'Install the latest ce-dev version, or the version specified as option'
echo 'Mandatory arguments:'
echo '--platform: linux, darwin(MacOS) or windows'
echo 'Available options:'
echo '--version: ce-dev version to use.'
}
# Parse options arguments.
parse_options(){
while [ "${1:-}" ]; do
case "$1" in
"--version")
shift
VERSION="$1"
;;
"--platform")
shift
PLATFORM="$1"
;;
*)
usage
exit 1
;;
esac
shift
done
}
# Parse options.
parse_options "$@"
# Platform is mandatory.
if [ -z "$PLATFORM" ]; then
echo "You have to specify the platform"
usage
exit 1
fi
# Version is optional.
if [ -z "$VERSION" ]; then
API_URL="https://api.github.com/repos/codeenigma/ce-dev/releases"
VERSION=$(curl -s $API_URL | grep -Eo '"tag_name":\s*"2\.[^"]*"' | grep -Eo '2\.[^"]*' | sort -Vr | head -n 1)
# Check if we found a release
if [ -n "$VERSION" ]; then
echo "Downloading the latest 2.x version: $VERSION"
else
echo "No 2.x release found"
fi
fi
RELEASE=https://github.com/codeenigma/ce-dev/releases/download/$VERSION/ce-dev-v$VERSION-$PLATFORM-x64.tar.gz
WORK_DIR=$(mktemp -d)
# Check if we are updating instead of installing.
if [ -n "$(which ce-dev)" ]; then
CURRENT=$(ce-dev --version | cut -d / -f 2 | cut -d " " -f 1)
if [ "$CURRENT" = "$VERSION" ]; then
echo "Already using the version $VERSION"
exit 0
fi
fi
echo "Checking for dependencies..."
for BINARY in docker mkcert; do
if [ -z "$(which "$BINARY")" ]; then
echo "Could not find $BINARY"
echo "Ensure it is installed and in your \$PATH"
exit 1
fi
done
echo "done."
cd "$WORK_DIR"
echo "Fetching latest release... $RELEASE"
curl --fail -L "$RELEASE" -o ce-dev.tar.gz
echo "done."
echo "Unpacking..."
tar xfz ce-dev.tar.gz
echo "done."
echo "Moving binaries to /opt. This requires sudo privileges..."
if [ -d /opt/ce-dev ]; then
sudo rm -rf /opt/ce-dev
fi
sudo mv "$WORK_DIR/ce-dev" "/opt/"
sudo chmod +x /opt/ce-dev/bin/ce-dev
echo "done."
echo "Creating symlink to /usr/local/bin..."
if [ -f /usr/local/bin/ce-dev ]; then
sudo rm /usr/local/bin/ce-dev
fi
sudo ln -s /opt/ce-dev/bin/ce-dev /usr/local/bin/ce-dev
echo "done."
echo "Killing deprecated running ce_dev_controller container..."
if [ "$(docker ps -q -f name=ce_dev_controller)" ]; then
if [ "$(docker ps -aq -f status=running -f name=ce_dev_controller)" ]; then
# cleanup
docker kill ce_dev_controller
fi
fi
echo "done."
echo
echo "All done."