-
Notifications
You must be signed in to change notification settings - Fork 0
/
far3-bootstrap.sh
executable file
·217 lines (188 loc) · 6.23 KB
/
far3-bootstrap.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
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
#!/bin/sh
# SPDX-License-Identifier: MIT
## Far Manager v3 + some plugins bootstrap script
## Copyright (C) 2015-2024 Przemyslaw Pawelczyk <[email protected]>
##
## This script is licensed under the terms of the MIT license.
## https://opensource.org/licenses/MIT
# Download zip, extract its content and enter newly created directory:
# https://git.io/far3-bootstrap.zip which redirects to:
# https://github.com/przemoc/far3-bootstrap/zipball/master
# Run
# - On Windows (old):
# far3-bootstrap.cmd
# - On Windows 10+:
# far3-bootstrap.ps1
# - On Linux:
# far3-bootstrap.sh
# Run Far.exe from Far.x?? directory and further update plugins using Renewal (via F11).
set -e
USER_AGENT=far3-bootstrap/0.7
FAR_VARIANT=${1:-x86}
FAR_DIR="Far.$FAR_VARIANT"
[ "$2" = "skip" ] && FAR_SKIP=1 || FAR_SKIP=
[ "$FAR_VARIANT" = "x86" ] && BITS=32 || BITS=64
# Far
FAR_HOST='http://farmanager.com/'
FAR_DLPAGE="$FAR_HOST"'/download.php?l=en'
PRING_HOST='http://plugring.farmanager.com/'
PRING_INFO='plugin.php?pid='
# Tools
CURL_BASE='https://curl.se/windows/'
CURL_PATT="curl for $BITS-bit"
SZIPR_BASE='https://www.7-zip.org/'
SZIPR_HTML='download.html'
SZIPR_PATT='7zr\.exe'
SZIP_BASE='https://www.7-zip.org/'
SZIP_PATT='7z[0-9]*\.exe'
UNRAR_BASE='http://www.rarlab.com/rar/'
UNRAR_FILE='unrarw64.exe'
# Sites
FARPLUGS_BASE='https://sourceforge.net/projects/farplugs/'
# Functions
log() { echo "* $@" >&2; }
exists_or_download() {
if [ -r "$1" ]; then
log "File '$1' already exists."
else
log "Downloading '$1' from '$2'..."
curl -qgRLA "$USER_AGENT" -o "$1" "$2"
fi
}
exists_or_download_insecure() {
if [ -r "$1" ]; then
log "File '$1' already exists."
else
log "Downloading '$1' from '$2'..."
curl -gkRLA "$USER_AGENT" -o "$1" "$2"
fi
}
extract() { # ARCHIVE [FILE]...
ARC=$1
shift
log "Extracting $@ from '$ARC'"
EXT=$(echo ${ARC##*.} | tr A-Z a-z)
if [ "$EXT" = "7z" ] || [ "$EXT" = "exe" ] || [ "$EXT" = "zip" ]; then
# Workaround for NtfsFile which archive does not have root directory
ARCNAME=${ARC##*/}
if [ "${ARCNAME#NtfsFile_}" != "$ARCNAME" ]; then
7z x -r -aoa "$ARC" -oNtfsFile "$@"
else
7z x -r -aoa "$ARC" "$@"
fi
elif [ "$EXT" = "rar" ]; then
unrar x -o+ "$ARC" "$@"
fi
}
extract_no_path() { # ARCHIVE [FILE]
ARC=$1
shift
log "Extracting $@ from '$ARC'"
EXT=$(echo ${ARC##*.} | tr A-Z a-z)
if [ "$EXT" = "7z" ] || [ "$EXT" = "exe" ] || [ "$EXT" = "zip" ]; then
7z e -r -aoa "$ARC" "$@"
elif [ "$EXT" = "rar" ]; then
unrar e -o+ "$ARC" "$@"
fi
}
unzip_no_path() { # ARCHIVE [FILE]
ARC=$1
shift
log "Unzipping $@ from '$ARC'"
unzip -jo "$ARC" "$@" || busybox unzip -jo "$ARC" "$@"
}
download_and_extract_curl() {
CURL_PATH=$(wget -U "$USER_AGENT" -O- "$CURL_BASE" | sed "/$CURL_PATT/!d;s,.*href=\",,;s,\".*,,")
CURL_FILE=${CURL_PATH##*/}
CURL_DIR=${CURL_FILE%.zip}
log "Downloading '$CURL_FILE' from '$CURL_BASE$CURL_PATH'..."
wget -U "$USER_AGENT" -O "$CURL_FILE" "$CURL_BASE$CURL_PATH"
unzip_no_path "$CURL_FILE" "${CURL_DIR}/bin/curl.exe" "${CURL_DIR}/bin/curl-ca-bundle.crt"
}
download_and_extract_7zip() {
SZIPR_PATH=$(curl -qgRLA "$USER_AGENT" "$SZIPR_BASE$SZIPR_HTML" | sed "/$SZIPR_PATT/!d;s,.*href=\",,;s,\".*,," | head -1)
SZIPR_FILE=${SZIPR_PATH##*/}
exists_or_download "$SZIPR_FILE" "$SZIPR_BASE$SZIPR_PATH"
SZIP_PATH=$(curl -qgRLA "$USER_AGENT" "$SZIP_BASE" | sed "/$SZIP_PATT/!d;s,.*href=\",,;s,\".*,," | head -1)
SZIP_FILE=${SZIP_PATH##*/}
exists_or_download "$SZIP_FILE" "$SZIP_BASE$SZIP_PATH"
7zr e -r -aoa "$SZIP_FILE" 7z.exe 7z.dll
}
download_plugring() { # PID [PATTERN]
PLUGIN_INFO="$(curl -qgRLA "$USER_AGENT" "$PRING_HOST$PRING_INFO$1" | sed \
-e '/.*\(Version\|Far version\|Filename\|<a href="download.php?\)/!d;s,,\1,;' \
-e 's,</td></tr>,,;' \
-e '/^<a /{s,<[^"]*",Url=,;s,">.*,,};' \
-e 's,<.*>,=,;' \
-e '/^Far v/s, ,,;' \
| grep 'Farversion=3' -B1 -A2 \
)"
PLUGIN_VER="$(echo "$PLUGIN_INFO" | sed '/^Version=/!d;s,,,' | tail -1)"
PLUGIN_INFO="$(echo "$PLUGIN_INFO" | grep "^Version=$PLUGIN_VER$" -A3 | \
grep "Filename=.*$2" -B2 -A1 | tail -4)"
PLUGIN_FILE="$(echo "$PLUGIN_INFO" | sed '/^Filename=/!d;s,,,')"
PLUGIN_URL="$(echo "$PLUGIN_INFO" | sed '/^Url=/!d;s,,'"$PRING_HOST"',')"
exists_or_download "$PLUGIN_FILE" "$PLUGIN_URL"
echo "$PLUGIN_FILE"
}
download_farplugs_plugins() {
curl -qgRLA "$USER_AGENT" -o farplugs.rss "${FARPLUGS_BASE}rss"
# sort -V depends on strverscmp() that is not always present, so...
sed '/ *<link>/!d;s,,,;s,</link>.*,,;/_'"$FAR_VARIANT"'/!d' farplugs.rss \
| sed -r 's,^([^0-9]*)([0-9]*[^0-9.])?(.*),\2\3@.\1,' \
| sort -nrt . -k 1,1 -k 2,2 -k 3,3 -k 4,4 -k 5,5 -k 6,6 \
| sort -st @ -k 2,2 \
| sed -r 's,^(.*)@\.(.*),\2\1,' \
>farplugs.txt
URLS=$(cat farplugs.txt)
for PLUGIN_URL in $URLS; do
PLUGIN_FILE=${PLUGIN_URL%/download}
PLUGIN_FILE=${PLUGIN_FILE##*/}
PLUGIN_NAME=${PLUGIN_FILE%%_*}
[ "$PLUGIN_NAME" != "$PLUGIN_NAME_PREV" ] || continue
exists_or_download "$PLUGIN_FILE" "$PLUGIN_URL"
PLUGIN_NAME_PREV=$PLUGIN_NAME
echo "$PLUGIN_FILE"
done
}
# Start
if [ "$PATH" != "${PATH#*;}" ]; then
export PATH="$PWD;$PATH"
else
export PATH="$PWD:$PATH"
fi
curl --version || download_and_extract_curl
download_and_extract_7zip
if [ -z "$FAR_SKIP" ]; then
FAR_FILES="$(curl -qgRLA "$USER_AGENT" "$FAR_DLPAGE" \
| sed \
-e '/Stable builds/,/Nightly builds/!d;' \
-e '/^[ \t]*<li>/!d;' \
-e 's,<a ,\n,g;' \
| sed \
-e '/^class="body_link" href="/!d;s,,,;s,".*,,;' \
)"/
FAR_DLFILE="$(echo "$FAR_FILES" | grep "\.$FAR_VARIANT\.[^.]*\.7z$")"
FAR_FILE="${FAR_DLFILE##*/}"
log "Far Manager stable builds files"
echo "$FAR_FILES"
exists_or_download "$FAR_FILE" "$FAR_HOST$FAR_DLFILE"
fi
exists_or_download "$UNRAR_FILE" "$UNRAR_BASE$UNRAR_FILE"
extract "$UNRAR_FILE" unrar.exe
FARPLUGS=$(download_farplugs_plugins)
INTCHECKER=$(download_plugring 893 $FAR_VARIANT)
RESEARCH=$(download_plugring 246)
if [ -z "$FAR_SKIP" ]; then
( mkdir -p "$FAR_DIR" && cd "$FAR_DIR" \
&& extract ../"$FAR_FILE" \
)
fi
( mkdir -p "$FAR_DIR/Plugins" && cd "$FAR_DIR/Plugins" \
&& for PLUGIN in $FARPLUGS; do extract ../../$PLUGIN; done \
&& extract ../../"$INTCHECKER" \
&& ( mkdir -p RESearch && cd RESearch \
&& extract ../../../"$RESEARCH" \
&& ( [ "$FAR_VARIANT" = "x86" ] && rm "RESearchU3 x64.dll" || rm "RESearchU3.dll" ) \
) \
)