-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubuntu.sh
133 lines (107 loc) · 3.75 KB
/
ubuntu.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
#!/bin/bash
CARGO_CONFIG_DIR=$HOME/.cargo
CARGO=$(command -v cargo 2>/dev/null)
CARGO_TOOLS=(starship fd-find exa bat)
function tools() {
sudo apt install zsh shellcheck lua5.3 jq git make curl tig silversearcher-ag -y
return $?
}
function apt_source {
cat > /tmp/sources.list << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
EOF
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
sudo mv /tmp/sources.list /etc/apt/sources.list
}
function rust() {
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ||
{
echo "error install rust: " "$?"
return 1
}
if [[ ! -d "${CARGO_CONFIG_DIR}" ]]; then
mkdir "${CARGO_CONFIG_DIR}"
fi
cat > "${CARGO_CONFIG_DIR}"/config << EOF
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
# registry = "https://mirrors.ustc.edu.cn/crates.io-index"
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"
EOF
source "${HOME}"/.cargo/env
CARGO=$(command -v cargo 2>/dev/null)
if [[ "${CARGO}" == "" ]]; then
echo "error install rust"
return 1
fi
}
function rust_tools() {
# TODO: check if cargo has been installed.
for tool in "${CARGO_TOOLS[@]}"; do
"${CARGO}" install --locked "${tool}" ||
{
echo "error install ${tool}"
return 1
}
done
}
function zsh() {
if ! command -v zsh >/dev/null 2>&1; then
echo "zsh is not installed, install it first"
return 1
fi
# oh-my-zsh
curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -o /tmp/install.sh ||
{
echo "curl oh-my-zsh install script failed."
return 1
}
bash /tmp/install.sh --unattended ||
{
rm -rf /tmp/install.sh
echo "install oh-my-zsh failed."
return 1
}
rm -rf /tmp/install.sh
# apply starship prompt
echo 'eval "$(starship init zsh)"' >> "${HOME}"/.zshrc
# source "${HOME}"/.zshrc
}
function bashrc() {
cat >> $HOME/.bashrc << EOF
export GOPATH=$HOME/.go
export GOMODCACHE=$GOPATH/pkg/mod
export GOPROXY=https://goproxy.io,direct
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
eval "$(starship init bash)"
. "$HOME/.cargo/env"
EOF
cat >> $HOME/.bash_profile << EOF
if [ -f $HOME/.bashrc ]; then
source $HOME/.bashrc
fi
EOF
}
#apt_source
tools || exit 1
# rust || exit 1
# rust_tools || exit 1
# zsh || exit 1
bashrc || exit 1