-
Notifications
You must be signed in to change notification settings - Fork 1
/
oip
executable file
·214 lines (197 loc) · 6.1 KB
/
oip
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
#!/bin/sh
abort() {
printf "%s\n" "$@" >&2
exit 1
}
finish() {
printf "%s\n" "$@" >&2
exit 0
}
# shellcheck disable=SC2046
OTL_HOME="$(dirname $(dirname "$0"))"
# shellcheck disable=SC2034
case "${SHELL}" in
"/bin/bash"|*bash*) ALIAS=~/.bashrc ;;
"/bin/zsh"|*zsh*) ALIAS=~/.zshrc ;;
*) abort "${SHELL} - Unsupported Shell." ;;
esac
installFile() {
wget https://github.com/OTLanguage/module/raw/main/"${1}" -P "${2}"
}
# 1 : url, 2 : file name
urlCheck() {
URL="$(wget "${1}" -q -O -)"
if [ -z "${URL}" ]; then
abort "The '${2}' file was not found"
fi
}
# ex) 1 : ".class", 2 : "file path"
removeDir() {
rm -f "${2}/"*"${1}"
for dir in "${2}/"* ; do
if [ -d "${dir}" ]; then
removeDir "${1}" "${dir}"
fi
done
rm -d "${2}"
}
# shellcheck disable=SC2039 disable=SC2162
install1() {
READ_HTTP="$(wget https://raw.githubusercontent.com/OTLanguage/module/main/"${1}"/system.otls -q -O -)"
if [ -z "${READ_HTTP}" ]; then
abort "The '${1}' module was not found"
elif [ -d "${OTL_HOME}/module/${1}" ] || [ -d "${OTL_HOME}/analyzer/cos/${1}" ] ; then
# 설치 되어 있는지 확인
read -p "The ${1} file already exists. Do you want to reinstall? (y/n) : " CHECK
if [ "${CHECK}" = "y" ]; then
rm -rf "${OTL_HOME}/module/${1}"
rm -rf "${OTL_HOME}/analyzer/cos/${1}"
else
finish "Cancel the install"
fi
fi
TYPE=""
for line in ${READ_HTTP} ; do
if [[ "$line" == *: ]]; then
# class, jar, other
TYPE="${line:0:${#line}-1}"
elif [ -z "${TYPE}" ] || [ -z "${line}" ]; then
continue
else
case "${TYPE}" in
"class") FILE_PATH="${OTL_HOME}/analyzer/cos/$(echo "$line" | sed -e "s/~/\//g")" ;;
"jar") FILE_PATH="${OTL_HOME}/module/${1}/${line}" ;;
"other") FILE_PATH="${OTL_HOME}/module/${1}/${line}" ;;
*) abort "This type cannot be downloaded ${TYPE}" ;;
esac
FILE_NAME=$(basename "${FILE_PATH}") # ex) Reset.class
DOWNLOAD_PATH="${FILE_PATH:0:${#FILE_PATH}-${#FILE_NAME}-1}"
installFile "${1}/${FILE_NAME}" "${DOWNLOAD_PATH}"
fi
done
finish "install finish"
}
# 1 : model name, 2 : add model
# shellcheck disable=SC2162 disable=SC2039
install2() {
EXT="$(wget https://raw.githubusercontent.com/OTLanguage/module/main/"${1}"/add.otls -q -O -)"
if [ -z "${EXT}" ]; then
abort "${1} is a module that does not exist"
fi
FILE_NAME="${2}${EXT}"
# 추가 파일이 존재하는지 확인
if [ -f "${OTL_HOME}/module/${1}/${FILE_NAME}" ]; then
# 파일이 존재할때 재설치 확인
read -p "The ${FILE_NAME} file already exists. Do you want to reinstall? (y/n) : " CHECK
if [ "${CHECK}" = "y" ]; then
rm "${OTL_HOME}/module/${1}/${FILE_NAME}"
wget https://github.com/OTLanguage/module/raw/main/"${1}"/"${FILE_NAME}" -P "${OTL_HOME}/module/${1}"
finish "reinstall finish"
else
finish "Cancel the install"
fi
else
wget https://github.com/OTLanguage/module/raw/main/"${1}"/"${FILE_NAME}" -P "${OTL_HOME}/module/${1}"
finish "install finish"
fi
}
# shellcheck disable=SC2162 disable=SC2039
update0() {
read -p "Do you want to reinstall the OTLanguage file? (y/n) : " CHECK
if [ "${CHECK}" != "y" ]; then
finish "Cancel the deletion"
fi
removeDir ".class" "${OTL_HOME}/analyzer/bin"
removeDir ".class" "${OTL_HOME}/analyzer/work"
rm -f "${OTL_HOME}/analyzer/Main"*".class"
wget https://github.com/OTLanguage/download-tool/raw/main/analyzer.zip -P "${OTL_HOME}"
unzip "${OTL_HOME}/analyzer.zip" -d "${OTL_HOME}/analyzer"
rm -f "${OTL_HOME}/analyzer.zip"
finish "finish update"
}
# shellcheck disable=SC2162 disable=SC2039
update1() {
read -p "Do you want to reinstall the ${1} file? (y/n) : " CHECK
if [ "${CHECK}" != "y" ]; then
finish "Cancel the updates"
fi
modulePath="${OTL_HOME}/analyzer/cos/${1}"
if [ -d "${modulePath}" ]; then
removeDir ".class" "${modulePath}"
rm -f "${OTL_HOME}/module/${1}/"*".jar"
mkdir "${modulePath}"
install1 "${1}"
finish "finish update ${1}"
else
abort "This module is not downloaded"
fi
}
# shellcheck disable=SC2162 disable=SC2039 disable=SC2016 disable=SC2157 disable=SC1090
remove0() {
read -p "Are you sure you want to remove this OTLanguage file? (y/n) : " CHECK
if [ "${CHECK}" != "y" ]; then
finish "Cancel the remove"
fi
if [ "$(basename "${OTL_HOME}")" != "OTLanguage" ] || ! [ -f "${OTL_HOME}/.otl/$(basename "${0}")" ]; then
abort "file path error: ${OTL_HOME}"
fi
rm -rf "${OTL_HOME}"
# check otl path and delete
if [[ "$(cat ${ALIAS})" == *'export PATH="${OTL_HOME}/.otl:${PATH}"'* ]]; then
sed -i '/export PATH="${OTL_HOME}\/.otl:${PATH}"/d' ${ALIAS}
elif [[ "$(cat ${ALIAS})" == *'export PATH="${PATH}:${OTL_HOME}/.otl"'* ]]; then
sed -i '/export PATH="${PATH}:${OTL_HOME}\/.otl"/d' ${ALIAS}
fi
# check OTL_HOME and delete
if [[ "$(cat ${ALIAS})" == *"export OTL_HOME="* ]]; then
sed -i '/export OTL_HOME=/d' ${ALIAS}
fi
source "${ALIAS}"
finsh "finish remove OTLanguage"
}
# shellcheck disable=SC2039 disable=SC2162
remove1() {
if [ -d "${OTL_HOME}/analyzer/cos/${1}" ] || [ -d "${OTL_HOME}/module/${1}" ]; then
read -p "Are you sure you want to remove this ${1} file? (y/n) : " CHECK
if [ "${CHECK}" != "y" ]; then
finish "Cancel the remove module"
fi
rm -rf "${OTL_HOME}/analyzer/cos/${1}"
rm -rf "${OTL_HOME}/module/${1}"
finish "finish remove ${1} module"
else
abort "error: do not find ${1}"
fi
}
# 1 : module name, 2 : add name
in="install"
up="update"
re="remove"
# Cancel the deletion
option="${1}"
shift
# shellcheck disable=SC2039
case "${option}" in
"${in}")
case ${#@} in
1) install1 "${1}" ;;
2) install2 "${1}" "${2}" ;;
esac
;;
"${up}")
case ${#@} in
0) update0 ;;
1) update1 "${1}" ;;
esac
;;
"${re}")
case ${#@} in
0) remove0 ;;
1) remove1 "${1}" ;;
esac
;;
esac
filename="$(basename "${0}")"
abort "Usage: ${filename} <${in}> <module name> [add file]" \
" or ${filename} <${up}> [module name]" \
" or ${filename} <${re}> [module name]"