This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-tak2flac.sh
executable file
·255 lines (238 loc) · 6.71 KB
/
install-tak2flac.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
# =============================================================
# tak2flac install script by github@appleneko2001
# version 0.5 beta
# For allow use script required chmod +x ./install-tak2flac.sh
# =============================================================
ENV_PATH="/home/$USER/.profile"
INSTALL_PATH="/home/$USER/.local"
RELEASE_LINK='https://github.com/appleneko2001/tak2flac/releases/download/1.0_Core/tak2flac_linux-x64.zip'
TMPFILE_PATH="/tmp/tak2flac_release.zip"
TMPBIN_PATH="/tmp/tak2flac_release/bin"
OS_NAME="Unknown"
OS_VERS="00.00"
OS_ARCH=$(uname -m)
PACKAGEMAN=apt-get
# Detect distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_NAME=$NAME
OS_VERS=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
OS_NAME=$(lsb_release -si)
OS_VERS=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
OS_NAME=$DISTRIB_ID
OS_VERS=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
OS_NAME=Debian
OS_VERS=$(cat /etc/debian_version)
else
OS_NAME=$(uname -s)
OS_VERS=$(uname -r)
fi
# Check system requirements
if [ $OS_ARCH != 'x86_64' ];
then
echo dotNet Core does not support other architecture except x86_64 \(x64\)...
echo Aborting...
exit
fi
case ${OS_NAME} in
Ubuntu)
if [ $OS_VERS = '16.04' ] || [ $OS_VERS = '18.04' ] || [ $OS_VERS = '19.04' ] || [ $OS_VERS = '19.10' ] || [ $OS_VERS = '20.04' ];
then
PACKAGEMAN=apt-get
else
echo $OS_NAME $OS_VERS are not supported... Aborting...
exit
fi
;;
Debian)
if [ $OS_VERS = '10' ] || [ $OS_VERS = '9' ];
then
PACKAGEMAN=apt-get
else
echo $OS_NAME $OS_VERS are not supported... Aborting...
exit
fi
;;
Fedora)
if [ $OS_VERS = '32' ] || [ $OS_VERS = '31' ] || [ $OS_VERS = '30' ] || [ $OS_VERS = '29' ];
then
PACKAGEMAN=dnf
else
echo $OS_NAME $OS_VERS are not supported... Aborting...
exit
fi
;;
'Red Hat Enterprise Linux Server')
if [ $OS_VERS = '8' ] || [ $OS_VERS = '7' ];
then
PACKAGEMAN=dnf
else
echo $OS_NAME $OS_VERS are not supported... Aborting...
exit
fi
;;
esac
# Detecting elevated privileges
if [ $USER != 'root' ];
then
echo You are using username \"$USER\" running this script,
echo That means you want install tak2flac only for this user
echo Continue? \(yes or no\)
WaitAnswer=true
while [ $WaitAnswer = 'true' ]
do
read Answer
if [ $Answer = 'yes' ] || [ $Answer = 'y' ];
then
WaitAnswer=false
echo Install tak2flac for \"$USER\"
elif [ $Answer = 'no' ] || [ $Answer = 'n' ];
then
WaitAnswer=false
echo Canceled.
exit
fi
done
else
echo Install tak2flac for all users
ENV_PATH="/etc/environment"
INSTALL_PATH="/usr"
fi
# Start install process
FFMPEG_PATH=""
FFPROBE_PATH=""
while true;
do
/bin/echo -ne Check FFMPEG is installed...
if [ -f "$(command -v ffmpeg)" ];
then
echo "Found"
FFMPEG_PATH=$(command -v ffmpeg)
break
else
echo "Not found"
if [ $USER != 'root' ];
then
echo Install cannot continue, due not found required components
echo and we can\'t install it for you.
echo Aborting...
exit
else
echo Installing...
$PACKAGEMAN update
if ! $PACKAGEMAN install ffmpeg -y
then
echo Install failed. Aborting...
fi
fi
fi
done
echo Check ability TAK feature of current FFMPEG Version...
for item in ffmpeg ffprobe;
do
if [ -z "$("$item" -v quiet -formats | grep tak)" ]
then
echo Current version of FFMPEG are not supported TAK format.
echo Update it for support this feature.
echo Aborting...
exit
else
echo $item Passed
if [ "$item" = "ffprobe" ]
then
FFPROBE_PATH=$(command -v ffprobe)
fi
fi
done
/bin/echo -ne Check dotNet \(.Net Core\) runtime...
while true
do
if [ -f "$(command -v dotnet)" ];
then
echo "Found"
DETECTED_NETCOREAPP=false
for item in $(dotnet --list-runtimes);
do
if [ "$item" = "Microsoft.NETCore.App" ];
then
DETECTED_NETCOREAPP=true
elif [ "$DETECTED_NETCOREAPP" = "true" ];
then
if [[ "$item" =~ '3.1' ]];
then
DETECTED_NETCOREAPP=false
break
else
echo
echo dotNet 3.1 or newer are not installed.
echo Detected version: $item
echo Aborting...
exit
fi
fi
done
break
else
echo "Not found"
if [ $USER != 'root' ];
then
echo Install cannot continue, due not found required components
echo and we can\'t install it for you.
echo Aborting...
exit
else
echo Installing...
$PACKAGEMAN update
if ! $PACKAGEMAN install dotnet-runtime-3.1 -y
then
echo Install failed. Aborting...
fi
fi
fi
done
# read -ra A <<< "$(cat ~/.profile | grep -hn FFMPEG_BINARY)"; for i in "${A}";do echo $i; done
for item in FFMPEG_BINARY FFPROBE_BINARY;
do
RESULT=$(cat "$ENV_PATH" | grep -hn $item);
while IFS= read -r line;
do
IFS=':'
read -ra lineNum <<< "$line";
if ! [ -z "$lineNum" ]
then
echo Found variable $item in line $lineNum, removing...;
sed -i ${lineNum}d $ENV_PATH
fi
done <<< "$RESULT"
done
IFS=
echo "FFMPEG_BINARY=$FFMPEG_PATH" >> $ENV_PATH
echo "FFPROBE_BINARY=$FFPROBE_PATH" >> $ENV_PATH
echo "Downloading release file..."
CurlExitCode=$(curl -sSLk $RELEASE_LINK > $TMPFILE_PATH)
if ! $CurlExitCode
then
echo "Download failed... Aborting..."
exit $CurlExitCode
fi
mkdir -p "$TMPBIN_PATH"
echo "Extracting file..."
unzip -xoq "$TMPFILE_PATH" -d "$TMPBIN_PATH"
rm $TMPFILE_PATH
mv -f "$TMPBIN_PATH/tak2flac" "$INSTALL_PATH/bin/tak2flac"
echo "Applying file mode..."
chmod 0755 "$INSTALL_PATH/bin/tak2flac"
# Determine binary are installed successfully or not
if [ -f "$(command -v tak2flac)" ];
then
echo "Install complete! You can use tak2flac now!"
elif [ -f "$INSTALL_PATH/bin/tak2flac" ];
then
echo "Install complete! But required restart computer or login again."
elseS
fi
# End of file