-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgetcli.sh
134 lines (107 loc) · 2.66 KB
/
getcli.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
#!/bin/sh
# check dependence
if ! [ -x "$(command -v curl)" ]; then
echo 'not found curl' >&2
exit 1
fi
if [ -z "$PROXY" ]; then
PROXY="https://ghproxy.chenshaowen.com/"
fi
echo "Using PROXY: $PROXY"
# Detect architecture
case "$(uname -m)" in
x86_64)
ARCH=amd64
;;
aarch64)
ARCH=arm64
;;
i386 | i686)
ARCH=386
;;
armv7l)
ARCH=arm
GOARM=7
;;
*)
echo "ARCH isn't supported"
exit 1
;;
esac
# Detect OS type
case "$(uname)" in
Linux)
OSTYPE=linux
;;
Darwin)
OSTYPE=darwin
;;
CYGWIN* | MINGW* | MSYS*)
OSTYPE=windows
;;
*)
echo "OS isn't supported"
exit 1
;;
esac
# remove version prefix 'v'
VERSION=$(echo "$VERSION" | sed 's/^[vV]//')
FILENAME="opscli-${VERSION}-${OSTYPE}-${ARCH}.tar.gz"
# get version
if [ "x${VERSION}" = "x" ] || [ "${VERSION}" = "latest" ]; then
VERSION="latest"
DOWNLOAD_URL="https://github.com/shaowenchen/ops/releases/download/${VERSION}/opscli-${VERSION}-${OSTYPE}-${ARCH}.tar.gz"
else
DOWNLOAD_URL="https://github.com/shaowenchen/ops/releases/download/v${VERSION}/opscli-${VERSION}-${OSTYPE}-${ARCH}.tar.gz"
VERSION=v${VERSION}
fi
# download file
http_code=$(curl --connect-timeout 2 -s -o temp.out -w '%{http_code}' https://github.com)
rm -rf temp.out || true
if [ $http_code -ne 302 ]; then
DOWNLOAD_URL="${PROXY}${DOWNLOAD_URL}"
fi
OPSTEMPDIR=$(mktemp -d)
curl -fsL "$DOWNLOAD_URL" -o "$OPSTEMPDIR/$FILENAME"
if [ ! -f "$OPSTEMPDIR/$FILENAME" ]; then
echo "Download error."
exit 1
fi
# install
tar -xzf "$OPSTEMPDIR/$FILENAME" -C "$OPSTEMPDIR"
chmod +x "$OPSTEMPDIR/opscli"
"$OPSTEMPDIR/opscli" version
OPSMANIFESTSDIR=$OPSTEMPDIR/ops-manifests
if [ $? -ne 0 ]; then
echo "Opscli file error"
exit 1
fi
OPSDIR="${HOME}/.ops/"
if [ ! -d "${OPSDIR}" ]; then
mkdir "${OPSDIR}"
fi
if [ -d "${OPSDIR}tasks" ]; then
mv ${OPSDIR}tasks ${OPSDIR}.tasks_upgrade_$(date +%Y-%m-%d-%H-%M-%S)
fi
mv "$OPSMANIFESTSDIR/tasks" ${OPSDIR}
if [ -d "${OPSDIR}taskruns" ]; then
mv ${OPSDIR}taskruns ${OPSDIR}.taskruns_upgrade_$(date +%Y-%m-%d-%H-%M-%S)
fi
mv "$OPSMANIFESTSDIR/taskruns" ${OPSDIR}
if [ -d "${OPSDIR}pipelines" ]; then
mv ${OPSDIR}pipelines ${OPSDIR}.pipelines_upgrade_$(date +%Y-%m-%d-%H-%M-%S)
fi
mv "$OPSMANIFESTSDIR/pipelines" ${OPSDIR}
if [ -d "${OPSDIR}eventhooks" ]; then
mv ${OPSDIR}eventhooks ${OPSDIR}.eventhooks_upgrade_$(date +%Y-%m-%d-%H-%M-%S)
fi
mv "$OPSMANIFESTSDIR/eventhooks" ${OPSDIR}
if [ $(id -u) -eq 0 ]; then
mv -f "$OPSTEMPDIR/opscli" /usr/local/bin/
echo "Congratulations! Opscli live in /usr/local/bin/opscli"
else
mv -f "$OPSTEMPDIR/opscli" $(pwd)
echo "Congratulations! Please run 'sudo mv $(pwd)/opscli /usr/local/bin/' to install."
fi
# clear
rm -rf "$OPSTEMPDIR"