Featured image of post 一堆简单 Shell 脚本

一堆简单 Shell 脚本

加速

PIP

1
2
3
4
5
6
7
8
# Python 包
# 使用清华镜像加速PIP
pipBoost(){
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn
pip install pip -U
}

APT

 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
# Ubantu 软件包
# 使用清华镜像源加速APT,注意部分参数值在不同Ubantu版本下可能有所不同
aptBoost(){
cp /etc/apt/sources.list /etc/apt/sources.bak
cat > /etc/apt/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 http://archive.ubuntu.com/ubuntu/ focal main restricted
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
deb http://security.ubuntu.com/ubuntu/ focal-security universe
deb http://security.ubuntu.com/ubuntu/ focal-security multiverse
EOF
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
apt-get update
}

YUM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# CentOS 软件包
# 使用腾讯镜像加速YUM
yumBoost(){
path=/etc/yum.repos.d/
mkdir ${path}bak
mv ${path}\*.repo ${path}bak
curl -o ${path}base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
yum clean all
yum makecache
yum update -y
yum upgrade -y
}

Docker

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Docker 仓库
# 使用腾讯镜像加速Docker
dockerBoost(){
file=/etc/docker/daemon.json
cp ${file} ${file}.bak
cat > ${file} << EOF
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
]
}
EOF
systemctl daemon-reload
service docker restart
}

安装

Docker

1
2
3
4
5
6
7
8
9
# 安装Docker-CE
dockerInstall(){
path=/etc/yum.repos.d/
curl -o ${path}docker.repo https://download.docker.com/linux/centos/docker-ce.repo
yum clean all & yum makecache & yum update -y & yum upgrade -y
yum install docker-ce
systemctl enable docker
systemctl start docker
}

杂项

更改 DNS

1
2
3
4
5
6
7
8
# 更改DNS
dnsUp(){
cat > /etc/resolv.conf << EOF
search localdomain
nameserver 223.5.5.5
nameserver 8.8.8.8
EOF
}

设置环境参数

1
2
3
4
5
6
7
8
# 设置环境参数
envSet(){
cat >> /etc/profile <<EOF
KEY=value
export KEY
EOF
. /etc/profile
}

GitHub代理下载

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 从GitHub获取最新发行版且符合当前系统的包
# 详细命令和参数需要修改
# 仅供参考
add(){
curl $1 |\
grep -i "browser_download_url.\*`uname -s`-`uname -m`\"" |\
cut -d '"' -f 4 |\
xargs -I {} echo https://ghproxy.com/{} |\
xargs curl -b - > $2
}

url=https://api.github.com/repos/docker/compose/releases/latest
file=/usr/local/bin/docker-compose
add url file