-
Notifications
You must be signed in to change notification settings - Fork 5
/
INSTALL.sh
executable file
·89 lines (69 loc) · 2.78 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
#!/bin/bash
set -e -o pipefail
BASE=$(dirname "$(readlink -fm "$0")")
RULES_DIR="$BASE/tools/_install_/"
DISTRIB=$(cat /etc/lsb-release | grep "DISTRIB_ID" | awk -F "=" '{print $2}')
DISTRIB_RELEASE=$(cat /etc/lsb-release | grep "DISTRIB_RELEASE" | awk -F "=" '{print $2}')
prepare_host() {
local hostdeps="libusb-dev git parted lib32z1 lib32stdc++6 libusb-0.1-4 libusb-1.0-0-dev libusb-1.0-0 ccache libncurses5 pv base-files linux-base"
local deps=()
local installed=$(dpkg-query -W -f '${db:Status-Abbrev}|${binary:Package}\n' '*' 2>/dev/null | grep '^ii' | awk -F '|' '{print $2}' | cut -d ':' -f 1)
if [[ "$DISTRIB" == "Ubuntu" ]] && [[ "$DISTRIB_RELEASE" == "18.10" || "$DISTRIB_RELEASE" =~ "20" ]]; then
hostdeps="$hostdeps lib32ncurses6"
else
hostdeps="$hostdeps lib32ncurses5"
fi
for packet in $hostdeps; do
if ! grep -q -x -e "$packet" <<< "$installed"; then deps+=("$packet"); fi
done
if [[ ${#deps[@]} -gt 0 ]]; then
echo "Installing dependencies"
echo "Requires root privileges, please enter your passowrd!"
sudo apt update
sudo apt -y --no-install-recommends install "${deps[@]}"
sudo update-ccache-symlinks
fi
}
RULE=
RED='\033[0;31m'
YELLOW="\e[0;33m"
RESET='\033[m'
echo ""
echo "==============================================="
echo ""
echo "Host PC: $DISTRIB $DISTRIB_RELEASE"
echo ""
echo "==============================================="
echo ""
prepare_host
error_msg() {
echo -e ${RED}Error:${RESET} $1
}
warning_msg() {
echo -e ${YELLOW}Warning:${RESET} $1
}
if [ "$DISTRIB" != "Ubuntu" ] \
|| ! [[ "$DISTRIB_RELEASE" =~ "12" || "$DISTRIB_RELEASE" =~ "14" || "$DISTRIB_RELEASE" =~ "16" || "$DISTRIB_RELEASE" =~ "19" || "$DISTRIB_RELEASE" =~ "19" || "$DISTRIB_RELEASE" =~ "20" || "$DISTRIB_RELEASE" =~ "21" ]] ; then
warning_msg "This flash tool just support Ubuntu LTS now, other distributions haven't been verified!"
read -p "Continue any way? [No/yes] " answer
if [[ "$answer" != "yes" && "$answer" != "Yes" ]]; then
exit 1
else
IGNORE_CHECK=yes
warning_msg "You choose to not check the system environment, the installation may be failed!!!"
fi
fi
echo "Installing USB rules..."
if [[ "$DISTRIB_RELEASE" =~ "12" ]]; then
RULE="$RULES_DIR/70-persistent-usb-ubuntu12.rules"
sudo cp $RULE /etc/udev/rules.d
sudo sed -i s/OWNER=\"amlogic\"/OWNER=\"`whoami`\"/g /etc/udev/rules.d/$(basename $RULE)
elif [[ "$IGNORE_CHECK" == "yes" || "$DISTRIB_RELEASE" =~ "14" || "$DISTRIB_RELEASE" =~ "16" || "$DISTRIB_RELEASE" =~ "18" || "$DISTRIB_RELEASE" =~ "19" || "$DISTRIB_RELEASE" =~ "20" || "$DISTRIB_RELEASE" =~ "21" ]]; then
RULE="$RULES_DIR/70-persistent-usb-ubuntu14.rules"
sudo cp $RULE /etc/udev/rules.d
else
error_msg "Ubuntu $DISTRIB_RELEASE haven't been verified! Please copy USB rules yourself"
exit 1
fi
sudo udevadm control --reload-rules
echo "Done!"