-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathdefault.txt
719 lines (650 loc) · 23.7 KB
/
default.txt
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#!/bin/bash -
#===============================================================================
#
# FILE: default.txt
#
# USAGE: curl https://getspotifydownload.schollz.com | bash
# OR
# wget -qO- https://getspotifydownload.schollz.com | bash
#
# DESCRIPTION: spotifydownload Installer Script.
#
# This script installs spotifydownload into a specified prefix.
# Default prefix = /usr/local/bin
#
# OPTIONS: -p, --prefix "${INSTALL_PREFIX}"
# Prefix to install spotifydownload into. Defaults to /usr/local/bin
# REQUIREMENTS: bash, uname, tar/unzip, curl/wget, sudo (if not run
# as root), install, mktemp, sha256sum/shasum/sha256
#
# BUGS: ...hopefully not. Please report.
#
# NOTES: Homepage: https://schollz.com/software/spotifydownload
# Issues: https://github.com/schollz/spotifydownload/issues
#
# CREATED: 08/10/2019 16:41
# REVISION: 0.9.1
#===============================================================================
set -o nounset # Treat unset variables as an error
#-------------------------------------------------------------------------------
# DEFAULTS
#-------------------------------------------------------------------------------
PREFIX="${PREFIX:-}"
ANDROID_ROOT="${ANDROID_ROOT:-}"
# Termux on Android has ${PREFIX} set which already ends with '/usr'
if [[ -n "${ANDROID_ROOT}" && -n "${PREFIX}" ]]; then
INSTALL_PREFIX="${PREFIX}/bin"
else
INSTALL_PREFIX="/usr/local/bin"
fi
#-------------------------------------------------------------------------------
# FUNCTIONS
#-------------------------------------------------------------------------------
#--- FUNCTION ----------------------------------------------------------------
# NAME: print_banner
# DESCRIPTION: Prints a banner
# PARAMETERS: none
# RETURNS: 0
#-------------------------------------------------------------------------------
print_banner() {
cat <<-'EOF'
==================================================
spotifydownload installer
==================================================
EOF
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: print_help
# DESCRIPTION: Prints out a help message
# PARAMETERS: none
# RETURNS: 0
#-------------------------------------------------------------------------------
print_help() {
local help_header
local help_message
help_header="spotifydownload Installer Script"
help_message="Usage:
-p INSTALL_PREFIX
Prefix to install spotifydownload into. Directory must already exist.
Default = /usr/local/bin ('\${PREFIX}/bin' on Termux for Android)
-h
Prints this helpfull message and exit."
echo "${help_header}"
echo ""
echo "${help_message}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: print_message
# DESCRIPTION: Prints a message all fancy like
# PARAMETERS: $1 = Message to print
# $2 = Severity. info, ok, error, warn
# RETURNS: Formatted Message to stdout
#-------------------------------------------------------------------------------
print_message() {
local message
local severity
local red
local green
local yellow
local nc
message="${1}"
severity="${2}"
red='\e[0;31m'
green='\e[0;32m'
yellow='\e[1;33m'
nc='\e[0m'
case "${severity}" in
"info" ) echo -e "${nc}${message}${nc}";;
"ok" ) echo -e "${green}${message}${nc}";;
"error" ) echo -e "${red}${message}${nc}";;
"warn" ) echo -e "${yellow}${message}${nc}";;
esac
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: make_tempdir
# DESCRIPTION: Makes a temp dir using mktemp if available
# PARAMETERS: $1 = Directory template
# RETURNS: 0 = Created temp dir. Also prints temp file path to stdout
# 1 = Failed to create temp dir
# 20 = Failed to find mktemp
#-------------------------------------------------------------------------------
make_tempdir() {
local template
local tempdir
local tempdir_rcode
template="${1}.XXXXXX"
if command -v mktemp >/dev/null 2>&1; then
tempdir="$(mktemp -d -t "${template}")"
tempdir_rcode="${?}"
if [[ "${tempdir_rcode}" == "0" ]]; then
echo "${tempdir}"
return 0
else
return 1
fi
else
return 20
fi
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: determine_os
# DESCRIPTION: Attempts to determin host os using uname
# PARAMETERS: none
# RETURNS: 0 = OS Detected. Also prints detected os to stdout
# 1 = Unkown OS
# 20 = 'uname' not found in path
#-------------------------------------------------------------------------------
determine_os() {
local uname_out
if command -v uname >/dev/null 2>&1; then
uname_out="$(uname)"
if [[ "${uname_out}" == "" ]]; then
return 1
else
echo "${uname_out}"
return 0
fi
else
return 20
fi
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: determine_arch
# DESCRIPTION: Attempt to determin architecture of host
# PARAMETERS: none
# RETURNS: 0 = Arch Detected. Also prints detected arch to stdout
# 1 = Unkown arch
# 20 = 'uname' not found in path
#-------------------------------------------------------------------------------
determine_arch() {
local uname_out
if command -v uname >/dev/null 2>&1; then
uname_out="$(uname -m)"
if [[ "${uname_out}" == "" ]]; then
return 1
else
echo "${uname_out}"
return 0
fi
else
return 20
fi
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: download_file
# DESCRIPTION: Downloads a file into the specified directory. Attempts to
# use curl, then wget. If neither is found, fail.
# PARAMETERS: $1 = url of file to download
# $2 = location to download file into on host system
# RETURNS: If curl or wget found, returns the return code of curl or wget
# 20 = Could not find curl and wget
#-------------------------------------------------------------------------------
download_file() {
local url
local dir
local filename
local rcode
url="${1}"
dir="${2}"
filename="${3}"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "${url}" -o "${dir}/${filename}"
rcode="${?}"
elif command -v wget >/dev/null 2>&1; then
wget --quiet "${url}" -O "${dir}/${filename}"
rcode="${?}"
else
rcode="20"
fi
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: checksum_check
# DESCRIPTION: Attempt to verify checksum of downloaded file to ensure
# integrity. Tries multiple tools before faling.
# PARAMETERS: $1 = path to checksum file
# $2 = location of file to check
# $3 = working directory
# RETURNS: 0 = checkusm verified
# 1 = checksum verification failed
# 20 = failed to determine tool to use to check checksum
# 30 = failed to change into or go back from working dir
#-------------------------------------------------------------------------------
checksum_check() {
local checksum_file
local file
local dir
local rcode
local shasum_1
local shasum_2
local shasum_c
checksum_file="${1}"
file="${2}"
dir="${3}"
cd "${dir}" || return 30
if command -v sha256sum >/dev/null 2>&1; then
## Not all sha256sum versions seem to have --ignore-missing, so filter the checksum file
## to only include the file we downloaded.
grep "$(basename "${file}")" "${checksum_file}" > filtered_checksum.txt
shasum_c="$(sha256sum -c "filtered_checksum.txt")"
rcode="${?}"
elif command -v shasum >/dev/null 2>&1; then
## With shasum on FreeBSD, we don't get to --ignore-missing, so filter the checksum file
## to only include the file we downloaded.
grep "$(basename "${file}")" "${checksum_file}" > filtered_checksum.txt
shasum_c="$(shasum -a 256 -c "filtered_checksum.txt")"
rcode="${?}"
elif command -v sha256 >/dev/null 2>&1; then
## With sha256 on FreeBSD, we don't get to --ignore-missing, so filter the checksum file
## to only include the file we downloaded.
## Also sha256 -c option seems to fail, so fall back to an if statement
grep "$(basename "${file}")" "${checksum_file}" > filtered_checksum.txt
shasum_1="$(sha256 -q "${file}")"
shasum_2="$(awk '{print $1}' filtered_checksum.txt)"
if [[ "${shasum_1}" == "${shasum_2}" ]]; then
rcode="0"
else
rcode="1"
fi
shasum_c="Expected: ${shasum_1}, Got: ${shasum_2}"
else
return 20
fi
cd - >/dev/null 2>&1 || return 30
if [[ "${rcode}" -gt "0" ]]; then
echo "${shasum_c}"
fi
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: extract_file
# DESCRIPTION: Extracts a file into a location. Attempts to determine which
# tool to use by checking file extention.
# PARAMETERS: $1 = file to extract
# $2 = location to extract file into
# $3 = extention
# RETURNS: Return code of the tool used to extract the file
# 20 = Failed to determine which tool to use
# 30 = Failed to find tool in path
#-------------------------------------------------------------------------------
extract_file() {
local file
local dir
local ext
local rcode
file="${1}"
dir="${2}"
ext="${3}"
case "${ext}" in
"zip" ) if command -v unzip >/dev/null 2>&1; then
unzip "${file}" -d "${dir}"
rcode="${?}"
else
rcode="30"
fi
;;
"tar.gz" ) if command -v tar >/dev/null 2>&1; then
tar -xf "${file}" -C "${dir}"
rcode="${?}"
else
rcode="31"
fi
;;
* ) rcode="20";;
esac
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: create_prefix
# DESCRIPTION: Creates the install prefix (and any parent directories). If
# EUID not 0, then attempt to use sudo.
# PARAMETERS: $1 = prefix
# RETURNS: Return code of the tool used to make the directory
# 0 = Created the directory
# >0 = Failed to create directory
# 20 = Could not find mkdir command
# 21 = Could not find sudo command
#-------------------------------------------------------------------------------
create_prefix() {
local prefix
local rcode
prefix="${1}"
if command -v mkdir >/dev/null 2>&1; then
if [[ "${EUID}" == "0" ]]; then
mkdir -p "${prefix}"
rcode="${?}"
else
if command -v sudo >/dev/null 2>&1; then
sudo mkdir -p "${prefix}"
rcode="${?}"
else
rcode="21"
fi
fi
else
rcode="20"
fi
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: install_file_freebsd
# DESCRIPTION: Installs a file into a location using 'install'. If EUID not
# 0, then attempt to use sudo.
# PARAMETERS: $1 = file to install
# $2 = location to install file into
# RETURNS: 0 = File Installed
# 1 = File not installed
# 20 = Could not find install command
# 21 = Could not find sudo command
#-------------------------------------------------------------------------------
install_file_freebsd() {
local file
local prefix
local rcode
file="${1}"
prefix="${2}"
if command -v install >/dev/null 2>&1; then
if [[ "${EUID}" == "0" ]]; then
install -C -b -B '_old' -m 755 "${file}" "${prefix}"
rcode="${?}"
else
if command -v sudo >/dev/null 2>&1; then
sudo install -C -b -B '_old' -m 755 "${file}" "${prefix}"
rcode="${?}"
else
rcode="21"
fi
fi
else
rcode="20"
fi
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: install_file_linux
# DESCRIPTION: Installs a file into a location using 'install'. If EUID not
# 0, then attempt to use sudo (unless on android).
# PARAMETERS: $1 = file to install
# $2 = location to install file into
# RETURNS: 0 = File Installed
# 1 = File not installed
# 20 = Could not find install command
# 21 = Could not find sudo command
#-------------------------------------------------------------------------------
install_file_linux() {
local file
local prefix
local rcode
file="${1}"
prefix="${2}"
if command -v install >/dev/null 2>&1; then
if [[ "${EUID}" == "0" ]]; then
install -C -b -S '_old' -m 755 -t "${prefix}" "${file}"
rcode="${?}"
else
if command -v sudo >/dev/null 2>&1; then
sudo install -C -b -S '_old' -m 755 "${file}" "${prefix}"
rcode="${?}"
elif [[ "${ANDROID_ROOT}" != "" ]]; then
install -C -b -S '_old' -m 755 -t "${prefix}" "${file}"
rcode="${?}"
else
rcode="21"
fi
fi
else
rcode="20"
fi
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: install_file_cygwin
# DESCRIPTION: Installs a file into a location using 'install'. If EUID not
# 0, then attempt to use sudo.
# Not really 100% sure this is how to install spotifydownload in cygwin.
# PARAMETERS: $1 = file to install
# $2 = location to install file into
# RETURNS: 0 = File Installed
# 20 = Could not find install command
# 21 = Could not find sudo command
#-------------------------------------------------------------------------------
install_file_cygwin() {
local file
local prefix
local rcode
file="${1}"
prefix="${2}"
if command -v install >/dev/null 2>&1; then
if [[ "${EUID}" == "0" ]]; then
install -m 755 "${prefix}" "${file}"
rcode="${?}"
else
if command -v sudo >/dev/null 2>&1; then
sudo install -m 755 "${file}" "${prefix}"
rcode="${?}"
else
rcode="21"
fi
fi
else
rcode="20"
fi
return "${rcode}"
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: main
# DESCRIPTION: Put it all together in a logical way
# ...at least that is the hope...
# PARAMETERS: 1 = prefix
# RETURNS: 0 = All good
# 1 = Something done broke
#-------------------------------------------------------------------------------
main() {
local prefix
local tmpdir
local tmpdir_rcode
local spotifydownload_arch
local spotifydownload_arch_rcode
local spotifydownload_os
local spotifydownload_os_rcode
local spotifydownload_base_url
local spotifydownload_url
local spotifydownload_file
local spotifydownload_checksum_file
local spotifydownload_bin_name
local spotifydownload_version
local spotifydownload_dl_ext
local download_file_rcode
local download_checksum_file_rcode
local checksum_check_rcode
local extract_file_rcode
local install_file_rcode
local create_prefix_rcode
spotifydownload_bin_name="spotifydownload"
spotifydownload_version="0.7.9"
spotifydownload_dl_ext="tar.gz"
spotifydownload_base_url="https://github.com/schollz/spotifydownload/releases/download"
prefix="${1}"
print_banner
print_message "== Install prefix set to ${prefix}" "info"
tmpdir="$(make_tempdir "${spotifydownload_bin_name}")"
tmpdir_rcode="${?}"
if [[ "${tmpdir_rcode}" == "0" ]]; then
print_message "== Created temp dir at ${tmpdir}" "info"
elif [[ "${tmpdir_rcode}" == "1" ]]; then
print_message "== Failed to create temp dir at ${tmpdir}" "error"
else
print_message "== 'mktemp' not found in path. Is it installed?" "error"
exit 1
fi
spotifydownload_arch="$(determine_arch)"
spotifydownload_arch_rcode="${?}"
if [[ "${spotifydownload_arch_rcode}" == "0" ]]; then
print_message "== Architecture detected as ${spotifydownload_arch}" "info"
elif [[ "${spotifydownload_arch_rcode}" == "1" ]]; then
print_message "== Architecture not detected" "error"
exit 1
else
print_message "== 'uname' not found in path. Is it installed?" "error"
exit 1
fi
spotifydownload_os="$(determine_os)"
spotifydownload_os_rcode="${?}"
if [[ "${spotifydownload_os_rcode}" == "0" ]]; then
print_message "== OS detected as ${spotifydownload_os}" "info"
elif [[ "${spotifydownload_os_rcode}" == "1" ]]; then
print_message "== OS not detected" "error"
exit 1
else
print_message "== 'uname' not found in path. Is it installed?" "error"
exit 1
fi
case "${spotifydownload_os}" in
"Darwin" ) spotifydownload_os="macOS";;
"CYGWIN"* ) spotifydownload_os="Windows";
spotifydownload_dl_ext="zip";
print_message "== Cygwin is currently unsupported." "error";
exit 1;;
esac
case "${spotifydownload_arch}" in
"x86_64" ) spotifydownload_arch="64bit";;
"amd64" ) spotifydownload_arch="64bit";;
"aarch64" ) spotifydownload_arch="ARM64";;
"armv7l" ) spotifydownload_arch="ARM";;
"i686" ) spotifydownload_arch="32bit";;
* ) spotifydownload_arch="unknown";;
esac
spotifydownload_file="${spotifydownload_bin_name}_${spotifydownload_version}_${spotifydownload_os}-${spotifydownload_arch}.${spotifydownload_dl_ext}"
spotifydownload_checksum_file="${spotifydownload_bin_name}_${spotifydownload_version}_checksums.txt"
spotifydownload_url="${spotifydownload_base_url}/v${spotifydownload_version}/${spotifydownload_file}"
spotifydownload_checksum_url="${spotifydownload_base_url}/v${spotifydownload_version}/${spotifydownload_checksum_file}"
download_file "${spotifydownload_url}" "${tmpdir}" "${spotifydownload_file}"
download_file_rcode="${?}"
if [[ "${download_file_rcode}" == "0" ]]; then
print_message "== Downloaded spotifydownload archive into ${tmpdir}" "info"
elif [[ "${download_file_rcode}" == "1" ]]; then
print_message "== Failed to download spotifydownload archive" "error"
exit 1
elif [[ "${download_file_rcode}" == "20" ]]; then
print_message "== Failed to locate curl or wget" "error"
exit 1
else
print_message "== Return code of download tool returned an unexpected value of ${download_file_rcode}" "error"
exit 1
fi
download_file "${spotifydownload_checksum_url}" "${tmpdir}" "${spotifydownload_checksum_file}"
download_checksum_file_rcode="${?}"
if [[ "${download_checksum_file_rcode}" == "0" ]]; then
print_message "== Downloaded spotifydownload checksums file into ${tmpdir}" "info"
elif [[ "${download_checksum_file_rcode}" == "1" ]]; then
print_message "== Failed to download spotifydownload checksums" "error"
exit 1
elif [[ "${download_checksum_file_rcode}" == "20" ]]; then
print_message "== Failed to locate curl or wget" "error"
exit 1
else
print_message "== Return code of download tool returned an unexpected value of ${download_checksum_file_rcode}" "error"
exit 1
fi
checksum_check "${tmpdir}/${spotifydownload_checksum_file}" "${tmpdir}/${spotifydownload_file}" "${tmpdir}"
checksum_check_rcode="${?}"
if [[ "${checksum_check_rcode}" == "0" ]]; then
print_message "== Checksum of ${tmpdir}/${spotifydownload_file} verified" "ok"
elif [[ "${checksum_check_rcode}" == "1" ]]; then
print_message "== Failed to verify checksum of ${tmpdir}/${spotifydownload_file}" "error"
exit 1
elif [[ "${checksum_check_rcode}" == "20" ]]; then
print_message "== Failed to find tool to verify sha256 sums" "error"
exit 1
elif [[ "${checksum_check_rcode}" == "30" ]]; then
print_message "== Failed to change into working directory ${tmpdir}" "error"
exit 1
else
print_message "== Unknown return code returned while checking checksum of ${tmpdir}/${spotifydownload_file}. Returned ${checksum_check_rcode}" "error"
exit 1
fi
extract_file "${tmpdir}/${spotifydownload_file}" "${tmpdir}/" "${spotifydownload_dl_ext}"
extract_file_rcode="${?}"
if [[ "${extract_file_rcode}" == "0" ]]; then
print_message "== Extracted ${spotifydownload_file} to ${tmpdir}/" "info"
elif [[ "${extract_file_rcode}" == "1" ]]; then
print_message "== Failed to extract ${spotifydownload_file}" "error"
exit 1
elif [[ "${extract_file_rcode}" == "20" ]]; then
print_message "== Failed to determine which extraction tool to use" "error"
exit 1
elif [[ "${extract_file_rcode}" == "30" ]]; then
print_message "== Failed to find 'unzip' in path" "error"
exit 1
elif [[ "${extract_file_rcode}" == "31" ]]; then
print_message "== Failed to find 'tar' in path" "error"
exit 1
else
print_message "== Unknown error returned from extraction attempt" "error"
exit 1
fi
if [[ ! -d "${prefix}" ]]; then
create_prefix "${prefix}"
create_prefix_rcode="${?}"
if [[ "${create_prefix_rcode}" == "0" ]]; then
print_message "== Created install prefix at ${prefix}" "info"
elif [[ "${create_prefix_rcode}" == "20" ]]; then
print_message "== Failed to find mkdir in path" "error"
exit 1
elif [[ "${create_prefix_rcode}" == "21" ]]; then
print_message "== Failed to find sudo in path" "error"
exit 1
else
print_message "== Failed to create the install prefix: ${prefix}" "error"
exit 1
fi
else
print_message "== Install prefix already exists. No need to create it." "info"
fi
case "${spotifydownload_os}" in
"Linux" ) install_file_linux "${tmpdir}/${spotifydownload_bin_name}" "${prefix}/";
install_file_rcode="${?}";;
"FreeBSD" ) install_file_freebsd "${tmpdir}/${spotifydownload_bin_name}" "${prefix}/";
install_file_rcode="${?}";;
"macOS" ) install_file_freebsd "${tmpdir}/${spotifydownload_bin_name}" "${prefix}/";
install_file_rcode="${?}";;
"Windows" ) install_file_cygwin "${tmpdir}/${spotifydownload_bin_name}" "${prefix}/";
install_file_rcode="${?}";;
esac
if [[ "${install_file_rcode}" == "0" ]]; then
print_message "== Installed ${spotifydownload_bin_name} to ${prefix}/" "ok"
elif [[ "${install_file_rcode}" == "1" ]]; then
print_message "== Failed to install ${spotifydownload_bin_name}" "error"
exit 1
elif [[ "${install_file_rcode}" == "20" ]]; then
print_message "== Failed to locate 'install' command" "error"
exit 1
elif [[ "${install_file_rcode}" == "21" ]]; then
print_message "== Failed to locate 'sudo' command" "error"
exit 1
else
print_message "== Install attempt returned an unexpected value of ${install_file_rcode}" "error"
exit 1
fi
print_message "== Installation complete" "ok"
exit 0
}
#-------------------------------------------------------------------------------
# ARGUMENT PARSING
#-------------------------------------------------------------------------------
OPTS="hp:"
while getopts "${OPTS}" optchar; do
case "${optchar}" in
'h' ) print_help
exit 0
;;
'p' ) INSTALL_PREFIX="${OPTARG}"
;;
/? ) print_message "Unknown option ${OPTARG}" "warn"
;;
esac
done
#-------------------------------------------------------------------------------
# CALL MAIN
#-------------------------------------------------------------------------------
main "${INSTALL_PREFIX}"