-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsetup.sh
executable file
·132 lines (111 loc) · 3.33 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
#!/bin/sh
[ "$(whoami)" = "root" ] || sudo=sudo
osType=$(uname -s)
Color_Purple='\033[0;35m' # Purple
Color_Off='\033[0m' # Reset
msg() {
printf "%b\n" "$1"
}
info() {
msg "${Color_Purple}[❉]${Color_Off} $1$2"
}
installOrUpdateHomeBrew() {
if command -v brew > /dev/null ; then
info "Updating HomeBrew..."
brew update
else
info "Installing HomeBrew..."
printf "\n\n" | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
}
checkDependencies() {
info "Checking Dependencies..."
command -v curl > /dev/null || pkgNames="curl"
(command -v bash > /dev/null || command -v zsh > /dev/null) || pkgNames="$pkgNames zsh"
}
installDependencies() {
info "Installing Dependencies $pkgNames"
if [ "$osType" = "Darwin" ] ; then
installOrUpdateHomeBrew &&
brew install $@
return $?
elif [ "$osType" = "Linux" ] ; then
# Termux
if [ "$(uname -o 2> /dev/null)" = "Android" ] ; then
pkg update -y &&
pkg install -y $@
return $?
fi
# ArchLinux、ManjaroLinux
command -v pacman > /dev/null && {
$sudo pacman -Syyuu --noconfirm &&
$sudo pacman -S --noconfirm $@
return $?
}
# AlpineLinux
command -v apk > /dev/null && {
$sudo apk update &&
$sudo apk add $@
return $?
}
# Debian GNU/LInux系
command -v apt-get > /dev/null && {
$sudo apt-get -y update &&
$sudo apt-get -y install $@
return $?
}
# Fedora、CentOS8
command -v dnf > /dev/null && {
$sudo dnf -y update &&
$sudo dnf -y install $@
return $?
}
# RHEL CentOS 7、6
command -v yum > /dev/null && {
$sudo yum -y update &&
$sudo yum -y install $@
return $?
}
# OpenSUSE
command -v zypper > /dev/null && {
$sudo zypper update -y &&
$sudo zypper install -y $@
return $?
}
fi
# FreeBSD
command -v pkg > /dev/null && {
$sudo pkg update -y &&
$sudo pkg install -y $@
return $?
}
}
installNVM() {
info "Installing nvm..."
bash=$(command -v bash)
[ -z "$bash" ] && bash=$(command -v zsh)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | "$bash"
}
changeNPMRegistryToChineseMirrorIfPossible() {
command -v npm > /dev/null || return 0
if [ "$(npm config get registry)" = "https://registry.npmjs.org/" ] ; then
npm config set registry "https://registry.npm.taobao.org/" &&
info "change npm registry to https://registry.npm.taobao.org/"
fi
}
configEnv() {
str="export NVM_DIR=~/.nvm && source \"\$NVM_DIR/nvm.sh\""
printf "%s\n" "$str" >> ~/.bashrc
printf "%s\n" "$str" >> ~/.bash_profile
printf "%s\n" "$str" >> ~/.zshrc
}
main() {
command -v nvm > /dev/null && {
changeNPMRegistryToChineseMirrorIfPossible
info "nvm already installed!"
exit
}
checkDependencies
([ -z "$pkgNames" ] || installDependencies "$pkgNames") && installNVM && configEnv
}
main