forked from download-online-video/chrome-avgle-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·89 lines (72 loc) · 3.1 KB
/
install.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
#!/usr/bin/env bash
# ==================================================================
# Notes:
# Please execute this script in any one of following environment:
# Most Linux Systems / OS X
# Windows Subsytem for Linux / Git Bash on Windows / Cygwin
# ==================================================================
INSTALL_TO="$1";
SCRIPT_NAME="${BASH_SOURCE[0]}";
THIS_DIR=`cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd`;
function throw() { echo -e "[-] FATAL: $1\nexit with code 1"; exit 1; }
# ===========================
# Is Windows User
uname -s > /dev/null || throw "get system information failed! (uname -s)";
UNAME_S="$(uname -s)";
if [[ "$UNAME_S" == MINGW* ]] || [[ "$UNAME_S" == CYGWIN* ]]; then
# Windows (Git Bash/Cygwin) User
echo "=====================================================";
echo " Install Script for Windows User (Git Bash/Cygwin)";
echo "=====================================================";
RUN_AS_ADMIN="(Have you \"Run as administrator\"?)"
INSTALL_DEPS="(How to fix this error: read windows-libs/README.md)";
pushd "$THIS_DIR"> /dev/null;
echo "[.] checking windows libraries (dependencies) ...";
echo "[.] ffmpeg.exe";
[[ -z "$(find windows-libs -type f -name 'ffmpeg.exe')" ]] && throw "ffmpeg.exe is missing! $INSTALL_DEPS";
echo "[.] aria2c.exe"
if [[ -z "$(find windows-libs -type f -name 'aria2c.exe')" ]]; then
echo "[.] wget.exe";
[[ -z "$(find windows-libs -type f -name 'wget.exe')" ]] && throw "aria2c.exe/wget.exe is missing! $INSTALL_DEPS";
fi
echo "[~] dependencies have been checked!";
if [[ -z "$INSTALL_TO" ]]; then
[[ -z "$HOME" ]] && throw "get user home directory from env \$HOME failed!";
INSTALL_TO="$HOME/bin";
echo -e "INFO: Files will be installed to the default location: \n";
echo -e " $INSTALL_TO\n";
if [[ ! -e "$INSTALL_TO" ]]; then
echo "[.] creating install directory ...";
mkdir -p "$INSTALL_TO" || throw "create directory failed! $RUN_AS_ADMIN";
else
[[ -w "$INSTALL_TO" ]] || throw "directory is not writable! $RUN_AS_ADMIN";
fi
else
echo "INFO: install into: $INSTALL_TO\n";
[[ -d "$INSTALL_TO" ]] || throw "$INSTALL_TO is not a directory!";
[[ -w "$INSTALL_TO" ]] || throw "$INSTALL_TO is not writable! $RUN_AS_ADMIN";
fi
echo '[.] copying `windows-libs` ...';
cp -r windows-libs "$INSTALL_TO/" || throw 'Copy `windows-libs` failed!';
echo '[~] copied `windows-libs`';
else # Linux/WSL/OS X User
if [[ -z "$INSTALL_TO" ]]; then
echo;
echo "Usage: $SCRIPT_NAME \${install_to}";
echo;
echo ' Install `Avgle` and `AvgleDownloader to special directory`';
echo " For example: $SCRIPT_NAME ~/bin";
echo;
exit 0;
fi
[[ -d "$INSTALL_TO" ]] || throw "$INSTALL_TO is not a directory!";
[[ -w "$INSTALL_TO" ]] || throw "$INSTALL_TO is not writable!";
fi
pushd "$THIS_DIR" > /dev/null;
echo '[.] copying `Avgle` ...';
cp Avgle "$INSTALL_TO/" || throw 'Copy `Avgle` failed!';
echo '[~] copied `Avgle`';
echo '[.] copying `AvgleDownloader` ...';
cp AvgleDownloader "$INSTALL_TO/" || throw 'Copy `AvgleDownloader` failed!';
echo '[~] copied `AvgleDownloader`';
echo "[+] success: installed to $INSTALL_TO";