-
Notifications
You must be signed in to change notification settings - Fork 19
/
mkpm
executable file
·77 lines (76 loc) · 2.09 KB
/
mkpm
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
#!/bin/sh
MKPM_VERSION="1.0.0"
MKPM_SH_URL="${MKPM_SH_URL:-https://gitlab.com/api/v4/projects/48207162/packages/generic/mkpm/${MKPM_VERSION}/mkpm.sh}"
alias download="$(curl --version >/dev/null 2>&1 && echo curl -Lo || echo wget -O)"
alias echo="$([ "$(echo -e)" = "-e" ] && echo "echo" || echo "echo -e")"
_SUPPORTS_COLORS=$( (which tput >/dev/null 2>&1 && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]) && echo 1 || true)
_CWD="$(pwd)"
if [ "$_SUPPORTS_COLORS" = "1" ]; then
export C_END='\033[0m'
export C_RED='\033[31m'
export C_YELLOW='\033[33m'
fi
_error() { echo "${C_RED}MKPM [E]:${C_END} $@" 1>&2; }
_debug() { [ "$MKPM_DEBUG" = "1" ] && echo "${C_YELLOW}MKPM [D]:${C_END} $@" || true; }
_project_root() {
_ROOT="$1"
if [ "$_ROOT" = "" ]; then
_ROOT="$(pwd)"
fi
if [ -f "$_ROOT/mkpm.json" ]; then
echo "$_ROOT"
return
fi
_PARENT="$(echo "$_ROOT" | sed 's|\/[^\/]\+$||g')"
if ([ "$_PARENT" = "" ] || [ "$_PARENT" = "/" ]); then
echo "/"
return
fi
echo "$(_project_root "$_PARENT")"
return
}
_is_mkpm_proxy_required() {
while test $# -gt 0; do
case "$1" in
-h | --help)
return 1
;;
-*)
shift
;;
v | version | init)
return 1
;;
*)
break
;;
esac
done
[ "$1" = "" ] && return 1 || true
}
export PROJECT_ROOT="$(_project_root)"
if [ "$PROJECT_ROOT" = "/" ]; then
if _is_mkpm_proxy_required "$@"; then
_error "not an mkpm project" && exit 1
else
PROJECT_ROOT="$_CWD"
fi
fi
MKPM_ROOT="$PROJECT_ROOT/.mkpm"
MKPM="$MKPM_ROOT/mkpm"
MKPM_BIN="$MKPM/.bin"
if [ ! -f "$MKPM_BIN/mkpm" ]; then
mkdir -p "$MKPM_BIN"
if [ -f "$MKPM_ROOT/cache.tar.gz" ]; then
mkdir -p "$MKPM"
cd "$MKPM"
tar -xzf "$MKPM_ROOT/cache.tar.gz"
cd "$_CWD"
_debug restored cache
else
download "$MKPM_BIN/mkpm" "$MKPM_SH_URL" >/dev/null
_debug downloaded mkpm.sh
fi
chmod +x "$MKPM_BIN/mkpm"
fi
exec "$MKPM_BIN/mkpm" "$@"