-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsetup.sh
executable file
·166 lines (142 loc) · 4.6 KB
/
setup.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
#!/bin/sh
url=https://github.com/Microsoft/vcpkg.git
destDir=/usr/local/opt/vcpkg
sudo=$(command -v sudo 2> /dev/null)
osType=$(uname -s)
Color_Red='\033[0;31m' # Red
Color_Green='\033[0;32m' # Green
Color_Purple='\033[0;35m' # Purple
Color_Off='\033[0m' # Reset
msg() {
printf "%b\n" "$1"
}
info() {
msg "${Color_Purple}[❉]${Color_Off} $1$2"
}
success() {
msg "${Color_Green}[✔]${Color_Off} $1$2"
}
error() {
msg "${Color_Red}[✘]${Color_Off} $1$2"
exit 1
}
install_macOS_SDK_headers_IfNeeded() {
[ -d /usr/include ] || $sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
}
checkDependencies() {
info "checkDependencies..."
command -v curl > /dev/null || pkgNames="$pkgNames curl"
command -v git > /dev/null || pkgNames="$pkgNames git"
command -v unzip > /dev/null || pkgNames="$pkgNames unzip"
command -v gzip > /dev/null || pkgNames="$pkgNames gzip"
if [ "$osType" = "Drawin" ] ; then
install_macOS_SDK_headers_IfNeeded
command -v sed > /dev/null || pkgNames="$pkgNames gnu-sed"
command -v tar > /dev/null || pkgNames="$pkgNames gnu-tar"
command -v g++-9 > /dev/null || pkgNames="$pkgNames gcc"
else
command -v sed > /dev/null || pkgNames="$pkgNames sed"
command -v tar > /dev/null || pkgNames="$pkgNames tar"
if ( command -v dnf > /dev/null ||
command -v yum > /dev/null ||
command -v zypper > /dev/null ) ; then
command -v g++ > /dev/null || pkgNames="$pkgNames gcc gcc-c++"
elif command -v apt-get > /dev/null ; then
command -v g++ > /dev/null || pkgNames="$pkgNames gcc g++"
else
command -v g++ > /dev/null || pkgNames="$pkgNames gcc"
fi
fi
}
installDependencies() {
info "installDependencies $pkgNames"
if [ "$osType" = "Linux" ] ; then
# ArchLinux、ManjaroLinux
command -v pacman > /dev/null && {
$sudo pacman -Syyuu --noconfirm &&
$sudo pacman -S --noconfirm $@
return 0
}
# Debian GNU/Linux系
command -v apt-get > /dev/null && {
$sudo apt-get -y update &&
$sudo apt-get -y install $@
return 0
}
# Fedora、CentOS8
command -v dnf > /dev/null && {
$sudo dnf -y update &&
$sudo dnf -y install $@
return 0
}
# CentOS7、6
command -v yum > /dev/null && {
$sudo yum -y update &&
$sudo yum -y install $@
return 0
}
# OpenSUSE
command -v zypper > /dev/null && {
$sudo zypper update -y &&
$sudo zypper install -y $@
return 0
}
# AlpineLinux
command -v apk > /dev/null && {
$sudo apk update &&
$sudo apk add $@
return 0
}
elif [ "$osType" = "Darwin" ] ; then
if command -v brew > /dev/null; then
brew update
else
printf "\n\n" | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew install $@
return 0
fi
}
link() {
linkedDir=/usr/local/bin
if [ -d "$linkedDir" ] ; then
if [ -w "$linkedDir" ] ; then
ln -sf "$destDir/vcpkg" "$linkedDir/vcpkg"
else
sudo ln -sf "$destDir/vcpkg" "$linkedDir/vcpkg" &&
sudo chown "$(whoami)" "$linkedDir/vcpkg"
fi
else
$sudo install -d -o "$(whoami)" "$linkedDir" &&
ln -sf "$destDir/vcpkg" "$linkedDir/vcpkg"
fi
}
main() {
if [ -d "$destDir" ] ; then
if [ -d "$destDir/.git" ] ; then
checkDependencies &&
([ -z "$pkgNames" ] || installDependencies "$pkgNames") &&
cd "$destDir" &&
info "Updateing vcpk..." &&
git pull &&
info "Reinstalling vcpkg..." &&
./bootstrap-vcpkg.sh &&
link &&
success "Done!"
else
error "$destDir already exsit, but not a git repo."
fi
else
checkDependencies &&
([ -z "$pkgNames" ] || installDependencies "$pkgNames") &&
$sudo install -d -o "$(whoami)" "$destDir" &&
info "Downloading vcpk..." &&
git clone "$url" "$destDir" &&
cd "$destDir" &&
info "Installing vcpkg..." &&
./bootstrap-vcpkg.sh &&
link &&
success "Done!"
fi
}
main