-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·257 lines (213 loc) · 5.64 KB
/
install
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
# set -e
# @TODO fix sudo in docker
command -v sudo >>/dev/null 2>&1
if [ $? -ne 0 ]; then
sudo() {
if [ "$1" = "-E" ]; then
shift
fi
eval "$@"
}
chown() {
echo "ignore chown" >>/dev/null 2>&1
}
tput() {
echo "ignore tput" >>/dev/null 2>&1
}
export -f sudo
export -f chown
export -f tput
fi
IS_PM_SOURCE_UPDATED=false
CHOWN_USER=$CHOWN_USER
# fix env CHOWN_USER not found
if [ -z "$CHOWN_USER" ]; then
# export CHOWN_USER=root
CHOWN_USER=$(id -u)
fi
has_command() {
command -v $1 >>/dev/null 2>&1
if [ "$?" = "0" ]; then
echo "true"
else
echo "false"
fi
}
depends() {
local cli=$1
if [ "$(has_command $cli)" = "false" ]; then
echo "[dependencies] install $cli ..."
# macos
if [ "$(uname -s)" = "Darwin" ]; then
if [ "$(has_command brew)" = "false" ]; then
if [ "$GITHUB_ACTIONS" = "true" ]; then
echo "in GitHub Actions, not necessary to change homebrew mirror"
else
# mirror: https://github.com/eryajf/Thanks-Mirror#homebrew
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
fi
sudo -E curl -o- https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash
fi
brew install -f $cli
if [ "$?" != "0" ]; then
exit 1
fi
return
fi
# ubuntu
if [ "$(has_command apt)" = "true" ]; then
if [ "$IS_PM_SOURCE_UPDATED" = "false" ]; then
IS_PM_SOURCE_UPDATED=true
sudo apt update -y
fi
sudo apt install -y $cli
if [ "$?" != "0" ]; then
exit 1
fi
return
fi
# debian
if [ "$(has_command apt-get)" = "true" ]; then
if [ "$IS_PM_SOURCE_UPDATED" = "false" ]; then
IS_PM_SOURCE_UPDATED=true
sudo apt-get update -y
fi
sudo apt-get install -y $cli
if [ "$?" != "0" ]; then
exit 1
fi
return
fi
# centos
if [ "$(has_command yum)" = "true" ]; then
if [ "$IS_PM_SOURCE_UPDATED" = "false" ]; then
IS_PM_SOURCE_UPDATED=true
sudo yum update -y
fi
sudo yum install -y $cli
if [ "$?" != "0" ]; then
exit 1
fi
return
fi
# alpine
if [ "$(has_command apk)" = "true" ]; then
if [ "$IS_PM_SOURCE_UPDATED" = "false" ]; then
IS_PM_SOURCE_UPDATED=true
sudo apk update
fi
sudo apk add $cli
if [ "$?" != "0" ]; then
exit 1
fi
return
fi
# federa
if [ "$(has_command dnf)" = "true" ]; then
sudo dnf install -y $cli
if [ "$?" != "0" ]; then
exit 1
fi
return
fi
# archlinux
if [ "$(has_command pacman)" = "true" ]; then
sudo pacman -Syu --noconfirm $cli
if [ "$?" != "0" ]; then
exit 1
fi
return
fi
echo "unkown linux package manager: $(uname -a)"
exit 1
fi
}
set -e
export ZMICRO_HOME_PARENT_DIR=${ZMICRO_HOME_PARENT_DIR:-"/usr/local/lib"}
export ZMICRO_HOME=${ZMICRO_HOME:-"${ZMICRO_HOME_PARENT_DIR}/zmicro"}
export ZMICRO_USER_LOCAL_BIN_DIR=${ZMICRO_USER_LOCAL_BIN_DIR:-"/usr/local/bin"}
export ZMICRO_GLOBAL_RC_DIR=${ZMICRO_GLOBAL_RC_DIR:-"/etc/zmicro"}
export ZMICRO_GLOBAL_RC=$ZMICRO_GLOBAL_RC_DIR/.zmicrorc
export ZMICRO_LOG_DIR=${ZMICRO_LOG_DIR:-"/var/log/zmicro"}
export ZMICRO_LOCAL_BIN=$ZMICRO_USER_LOCAL_BIN_DIR/zmicro
export ZMICRO_ROOT_BIN_DIR=${ZMICRO_ROOT_BIN_DIR:-"/bin"}
export OLD_ZMICRO_HOME=$HOME/.zmicro
export OLD_ZMICRO_HOME_BAK=${ZMICRO_HOME}.bak
if [ ! -d "$ZMICRO_USER_LOCAL_BIN_DIR" ]; then
sudo mkdir -p $ZMICRO_USER_LOCAL_BIN_DIR
fi
# @TO_REMOVE
if [ ! -d "$ZMICRO_HOME_PARENT_DIR" ]; then
sudo mkdir -p $ZMICRO_HOME_PARENT_DIR
fi
# Backup
if [ -d "$OLD_ZMICRO_HOME" ]; then
sudo mv $OLD_ZMICRO_HOME $OLD_ZMICRO_HOME_BAK
fi
depends bash
depends curl
# depends wget
depends git
# Create
if [ ! -d "$ZMICRO_HOME" ]; then
sudo -E git clone https://github.com/zcorky/zmicro.git $ZMICRO_HOME
if [ "$?" != "0" ]; then
echo "error: failed to install zmicro (1)"
exit 1
fi
fi
# Permission
if [ ! -w "$ZMICRO_HOME" ]; then
sudo chown -R $CHOWN_USER $ZMICRO_HOME
fi
# Logs
# if [ ! -w $ZMICRO_LOG_DIR ]; then
# @TODO ensure log permissions
if [ ! -d $ZMICRO_LOG_DIR ]; then
sudo mkdir -p $ZMICRO_LOG_DIR
fi
if [ ! -w $ZMICRO_LOG_DIR ]; then
sudo chmod -R 777 $ZMICRO_LOG_DIR
fi
# fi
# GLOBAL RC
if [ ! -d "$ZMICRO_GLOBAL_RC_DIR" ]; then
sudo mkdir -p $ZMICRO_GLOBAL_RC_DIR
fi
if [ ! -w "$ZMICRO_GLOBAL_RC_DIR" ]; then
sudo chown -R $CHOWN_USER $ZMICRO_GLOBAL_RC_DIR
fi
if [ ! -f "$ZMICRO_GLOBAL_RC" ]; then
sudo touch $ZMICRO_GLOBAL_RC
fi
if [ ! -w "$ZMICRO_GLOBAL_RC" ]; then
sudo chown $CHOWN_USER $ZMICRO_GLOBAL_RC
fi
# Bin
if [ -f $ZMICRO_LOCAL_BIN ]; then
sudo rm -f $ZMICRO_LOCAL_BIN
fi
sudo ln -s $ZMICRO_HOME/bin/zmicro $ZMICRO_LOCAL_BIN
if [ "$(uname -s)" = "Darwin" ]; then
export ZMICRO_ROOT_BIN_DIR=/usr/local/bin
fi
# MacOS cannot ln to /bin
if [ ! -d "$ZMICRO_ROOT_BIN_DIR" ]; then
sudo mkdir -p $ZMICRO_ROOT_BIN_DIR
fi
sudo ln -sf $ZMICRO_HOME/bin/zmicro $ZMICRO_ROOT_BIN_DIR/zmicro >>/dev/null # 2>&1
# . $ZMICRO_HOME/config/config
# Init
zmicro initialize $@
echo "Congratualation. Zmicro install successfully"
echo "Now you can see play with zmicro."
# echo ""
# echo "First install, you should source profile:"
# echo " bash: source \$HOME/.bashrc"
# echo " zsh: source \$HOME/.zshrc"
# echo "Then run update:"
# echo " zmicro update"
# echo ""