-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
142 lines (120 loc) · 4.83 KB
/
index.html
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
{
if [ -n "$ZSH_VERSION" ]; then
___x_cmd_inner_cd(){
builtin cd "$@" || return;
};
else
___x_cmd_inner_cd(){
command cd "$@" || return;
};
fi;
___x_cmd_get_log(){
printf "[%s] %s\n" "$(command date +"%Y-%m-%d/%H:%M:%S")" "$1" | command tee -a "$___X_CMD_ROOT/setup.log" >&2 ;
};
___x_cmd_get_download(){
local tmptgt="$1";
local url="https://raw.githubusercontent.com/x-cmd/release/main";
case "$___X_CMD_VERSION" in
latest|alpha|beta) url="$url/dist/${___X_CMD_VERSION}.tgz" ;;
v*) url="$url/dist/${___X_CMD_VERSION}/full.tgz" ;;
*) url="$url/sum/${___X_CMD_VERSION}.tgz" ;;
esac;
local target="$tmptgt/download_tmp.tgz";
[ ! -d "${tmptgt}" ] || {
___x_cmd_get_log "Folder already existed ==> There must be other process is installing x-cmd ==> $tmptgt";
return 1;
};
(
command mkdir -p "${tmptgt}"; ___x_cmd_inner_cd "${tmptgt}";
___x_cmd_get_log "Download script archieve from $url";
if command -v curl >/dev/null; then
command curl --fail "$url" >"$target" 2>/dev/null;
else
command wget -O "$target" "$url" 2>/dev/null;
fi || {
command rm -rf "$tmptgt";
___x_cmd_get_log "Fail to download from: $url";
exit 1;
};
___x_cmd_get_log "Download SUCCESS: $target ( size: $(command wc -c "$target" 2>/dev/null | command awk '{print ((int($1) + 1023 ) / 1024); }') KB )";
command tar vxf "$target" 2>>"$tmptgt/setup.log" 1>&2;
command rm -f "$target";
___x_cmd_get_log "Deflation SUCCESS: $target";
);
};
___x_cmd_get_populate(){
local tmptgt="$1"; local sumfp="$tmptgt/.x-cmd/metadata/version_sum";
[ ! -r "$sumfp" ] || . "$sumfp";
[ -n "$___X_CMD_VERSION_SUM" ] || {
___x_cmd_get_log "Fail to get version sum from: $sumfp";
return 1;
};
___X_CMD_VERSION_SUM8="${___X_CMD_VERSION_SUM%"${___X_CMD_VERSION_SUM#????????}"}";
local sum8dir="$___X_CMD_ROOT/v/.$___X_CMD_VERSION_SUM8";
[ ! -e "$sum8dir" ] || {
___x_cmd_get_log "Folder already existed ==> $sum8dir";
command rm -rf "${tmptgt}";
return 0;
};
command rm -rf "$sum8dir";
command mv "${tmptgt}" "$sum8dir";
};
___x_cmd_get_link(){
local vpath="$___X_CMD_ROOT/v/$___X_CMD_VERSION";
case "$___X_CMD_VERSION" in
latest|alpha|beta|v*)
command rm -rf "$vpath";
command mkdir -p "$vpath";
(
printf "___X_CMD_VERSION0=%s\n" "${___X_CMD_VERSION}";
printf "___X_CMD_VERSION=%s\n" ".${___X_CMD_VERSION_SUM8}";
printf ". \"\$___X_CMD_ROOT/v/%s/X\"\n" ".${___X_CMD_VERSION_SUM8}";
) >"$vpath/X";
;;
*)
[ "$___X_CMD_VERSION" = "$___X_CMD_VERSION_SUM" ] || {
___x_cmd_get_log "Exit for unknown situation when ___X_CMD_VERSION is $___X_CMD_VERSION";
return 1;
};
___X_CMD_VERSION=".${___X_CMD_VERSION_SUM8}";
;;
esac;
};
___x_cmd_get_bootinit()(
___X_CMD_ROOT_V_VERSION_TRICK_0_1="$___X_CMD_ROOT/v/${___X_CMD_VERSION_SUM}";
___X_CMD_ROOT_CODE=;
___X_CMD_ROOT_MOD=;
___X_CMD_XRC_RELOAD=1;
___X_CMD_ADVISE_DISABLE=1;
. "$___X_CMD_ROOT/v/$___X_CMD_VERSION/X";
___X_CMD_ROOT_V_VERSION="$___X_CMD_ROOT_V_VERSION_TRICK_0_1";
[ -z "$___X_CMD_VERSION0" ] || ___X_CMD_VERSION="$___X_CMD_VERSION0";
x boot init "$___X_CMD_ROOT" "$___X_CMD_VERSION";
);
___x_cmd_get_start(){
if [ -n "$___X_CMD_XBINEXP_EXIT" ]; then
___x_cmd_get_log "This installation/upgrade is performed by an external call, so the interactive shell for the new version will not automatically open.";
elif [ -z "$___X_CMD_ROOT_MOD" ]; then
___X_CMD_ROOT_CODE=;
. "$___X_CMD_ROOT/v/$___X_CMD_VERSION/X";
elif [ "${-#*i}" != "$-" ]; then
___x_cmd_get_log "x-cmd detected in current shell env. Opening a new shell to avoid collision.";
___X_CMD_ROOT_MOD= ___X_CMD_ROOT_CODE= ___X_CMD_VERSION="$___X_CMD_VERSION" "${SHELL:-/bin/sh}";
fi;
};
___x_cmd_get_main(){
local ___X_CMD_ROOT="$HOME/.x-cmd.root";
local ___X_CMD_VERSION="${___X_CMD_TOINSTALL_VERSION:-latest}";
local ___X_CMD_VERSION_SUM8=;
local ___X_CMD_CURRENTTIME="$(command date +"%Y-%m-%d_%H-%M-%S")";
command mkdir -p "$___X_CMD_ROOT";
___x_cmd_get_log "------------------ $___X_CMD_CURRENTTIME";
local tmptgt="$___X_CMD_ROOT/v/${___X_CMD_VERSION}.$$.$___X_CMD_CURRENTTIME";
___x_cmd_get_download "$tmptgt" || return;
___x_cmd_get_populate "$tmptgt" || return;
___x_cmd_get_link || return;
___x_cmd_get_bootinit || return;
___x_cmd_get_start || return;
};
___x_cmd_get_main;
}