Upload filebrowser.sh
Browse files- filebrowser.sh +144 -0
filebrowser.sh
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env bash
|
2 |
+
#
|
3 |
+
# File Browser Installer Script
|
4 |
+
#
|
5 |
+
# GitHub: https://github.com/filebrowser/filebrowser
|
6 |
+
# Issues: https://github.com/filebrowser/filebrowser/issues
|
7 |
+
# Requires: bash, mv, rm, tr, type, grep, sed, curl/wget, tar (or unzip on OSX and Windows)
|
8 |
+
#
|
9 |
+
# This script installs File Browser to your path.
|
10 |
+
# Usage:
|
11 |
+
#
|
12 |
+
# $ curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
|
13 |
+
# or
|
14 |
+
# $ wget -qO- https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
|
15 |
+
#
|
16 |
+
# In automated environments, you may want to run as root.
|
17 |
+
# If using curl, we recommend using the -fsSL flags.
|
18 |
+
#
|
19 |
+
# This should work on Mac, Linux, and BSD systems, and
|
20 |
+
# hopefully Windows with Cygwin. Please open an issue if
|
21 |
+
# you notice any bugs.
|
22 |
+
#
|
23 |
+
|
24 |
+
install_filemanager()
|
25 |
+
{
|
26 |
+
trap 'echo -e "Aborted, error $? in command: $BASH_COMMAND"; trap ERR; return 1' ERR
|
27 |
+
filemanager_os="unsupported"
|
28 |
+
filemanager_arch="unknown"
|
29 |
+
install_path="/usr/local/bin"
|
30 |
+
|
31 |
+
# Termux on Android has $PREFIX set which already ends with /usr
|
32 |
+
if [[ -n "$ANDROID_ROOT" && -n "$PREFIX" ]]; then
|
33 |
+
install_path="$PREFIX/bin"
|
34 |
+
fi
|
35 |
+
|
36 |
+
# Fall back to /usr/bin if necessary
|
37 |
+
if [[ ! -d $install_path ]]; then
|
38 |
+
install_path="/usr/bin"
|
39 |
+
fi
|
40 |
+
|
41 |
+
# Not every platform has or needs sudo (https://termux.com/linux.html)
|
42 |
+
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
|
43 |
+
|
44 |
+
#########################
|
45 |
+
# Which OS and version? #
|
46 |
+
#########################
|
47 |
+
|
48 |
+
filemanager_bin="filebrowser"
|
49 |
+
filemanager_dl_ext=".tar.gz"
|
50 |
+
|
51 |
+
# NOTE: `uname -m` is more accurate and universal than `arch`
|
52 |
+
# See https://en.wikipedia.org/wiki/Uname
|
53 |
+
unamem="$(uname -m)"
|
54 |
+
case $unamem in
|
55 |
+
*aarch64*)
|
56 |
+
filemanager_arch="arm64";;
|
57 |
+
*64*)
|
58 |
+
filemanager_arch="amd64";;
|
59 |
+
*86*)
|
60 |
+
filemanager_arch="386";;
|
61 |
+
*armv5*)
|
62 |
+
filemanager_arch="armv5";;
|
63 |
+
*armv6*)
|
64 |
+
filemanager_arch="armv6";;
|
65 |
+
*armv7*)
|
66 |
+
filemanager_arch="armv7";;
|
67 |
+
*)
|
68 |
+
echo "Aborted, unsupported or unknown architecture: $unamem"
|
69 |
+
return 2
|
70 |
+
;;
|
71 |
+
esac
|
72 |
+
|
73 |
+
unameu="$(tr '[:lower:]' '[:upper:]' <<<$(uname))"
|
74 |
+
if [[ $unameu == *DARWIN* ]]; then
|
75 |
+
filemanager_os="darwin"
|
76 |
+
elif [[ $unameu == *LINUX* ]]; then
|
77 |
+
filemanager_os="linux"
|
78 |
+
elif [[ $unameu == *FREEBSD* ]]; then
|
79 |
+
filemanager_os="freebsd"
|
80 |
+
elif [[ $unameu == *NETBSD* ]]; then
|
81 |
+
filemanager_os="netbsd"
|
82 |
+
elif [[ $unameu == *OPENBSD* ]]; then
|
83 |
+
filemanager_os="openbsd"
|
84 |
+
elif [[ $unameu == *WIN* || $unameu == MSYS* ]]; then
|
85 |
+
# Should catch cygwin
|
86 |
+
sudo_cmd=""
|
87 |
+
filemanager_os="windows"
|
88 |
+
filemanager_bin="filebrowser.exe"
|
89 |
+
filemanager_dl_ext=".zip"
|
90 |
+
else
|
91 |
+
echo "Aborted, unsupported or unknown OS: $uname"
|
92 |
+
return 6
|
93 |
+
fi
|
94 |
+
|
95 |
+
########################
|
96 |
+
# Download and extract #
|
97 |
+
########################
|
98 |
+
|
99 |
+
echo "Downloading File Browser for $filemanager_os/$filemanager_arch..."
|
100 |
+
if type -p curl >/dev/null 2>&1; then
|
101 |
+
net_getter="curl -fsSL"
|
102 |
+
elif type -p wget >/dev/null 2>&1; then
|
103 |
+
net_getter="wget -qO-"
|
104 |
+
else
|
105 |
+
echo "Aborted, could not find curl or wget"
|
106 |
+
return 7
|
107 |
+
fi
|
108 |
+
|
109 |
+
filemanager_file="${filemanager_os}-$filemanager_arch-filebrowser$filemanager_dl_ext"
|
110 |
+
filemanager_tag="$(${net_getter} https://api.github.com/repos/filebrowser/filebrowser/releases/latest | grep -o '"tag_name": ".*"' | sed 's/"//g' | sed 's/tag_name: //g')"
|
111 |
+
filemanager_url="https://github.com/filebrowser/filebrowser/releases/download/$filemanager_tag/$filemanager_file"
|
112 |
+
echo "$filemanager_url"
|
113 |
+
|
114 |
+
# Use $PREFIX for compatibility with Termux on Android
|
115 |
+
rm -rf "$PREFIX/tmp/$filemanager_file"
|
116 |
+
|
117 |
+
${net_getter} "$filemanager_url" > "$PREFIX/tmp/$filemanager_file"
|
118 |
+
|
119 |
+
echo "Extracting..."
|
120 |
+
case "$filemanager_file" in
|
121 |
+
*.zip) unzip -o "$PREFIX/tmp/$filemanager_file" "$filemanager_bin" -d "$PREFIX/tmp/" ;;
|
122 |
+
*.tar.gz) tar -xzf "$PREFIX/tmp/$filemanager_file" -C "$PREFIX/tmp/" "$filemanager_bin" ;;
|
123 |
+
esac
|
124 |
+
chmod +x "$PREFIX/tmp/$filemanager_bin"
|
125 |
+
|
126 |
+
echo "Putting filemanager in $install_path (may require password)"
|
127 |
+
$sudo_cmd mv "$PREFIX/tmp/$filemanager_bin" "$install_path/$filemanager_bin"
|
128 |
+
if setcap_cmd=$(PATH+=$PATH:/sbin type -p setcap); then
|
129 |
+
$sudo_cmd $setcap_cmd cap_net_bind_service=+ep "$install_path/$filemanager_bin"
|
130 |
+
fi
|
131 |
+
$sudo_cmd rm -- "$PREFIX/tmp/$filemanager_file"
|
132 |
+
|
133 |
+
if type -p $filemanager_bin >/dev/null 2>&1; then
|
134 |
+
echo "Successfully installed"
|
135 |
+
trap ERR
|
136 |
+
return 0
|
137 |
+
else
|
138 |
+
echo "Something went wrong, File Browser is not in your path"
|
139 |
+
trap ERR
|
140 |
+
return 1
|
141 |
+
fi
|
142 |
+
}
|
143 |
+
|
144 |
+
install_filemanager
|