Skip to content

Instantly share code, notes, and snippets.

@mutoe mutoe/root.sh
Last active Oct 27, 2019

Embed
What would you like to do?
initial centos server
#!/bin/bash
# CentOS 7
# set locale
echo "export LC_ALL=en_US.UTF-8" >> /etc/profile
echo "export LC_CTYPE=en_US.UTF-8" >> /etc/profile
read -s -p "shadowsocks password:" SS_PASSWD
read -s -p "shadowsocks port:" SS_PORT
# add nginx source
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# add node source
curl -sL https://rpm.nodesource.com/setup_12.x | bash -
# add yarn source
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
# update yum
yum update -y
yum remove -y epel-release
yum clean all
yum install -y epel-release
yum install -y expect zsh
yum install -y wget vim git docker nginx nodejs yarn python
yum install -y certbot python2-certbot-nginx
# set authorization
useradd -s /bin/zsh -G root mutoe
echo "mutoe ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
mkdir /home/mutoe/.ssh
chown mutoe:mutoe /home/mutoe/.ssh
cat >> /home/mutoe/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRO0qNkMpyVRQr9Segke/qesapm+iQU5rZBIJNET4PW4BOcQ4/6/FAcbXmjomdg5Y/fz6z9eby21ywu6/gk65PeLS8YDszxwnTkZMZiVnamhR7HeiSLf3wLoZUZNNHWM+BPKRsHQpaPEWsCAVCoCn+3PjRmUtBzwHnXzv2dOyBwieRqVX6U0JFafT/53yi7X6KvmMgzmKJGMqLWsgnrNTr/nBxZYJoqXwMazw1XjfX2yAiRv7SVeJrSw6endNe8Qowr9gGuhia71eRfB87z73oG4tDcGt5+Xue7n1ClxSexiRkwdeuLleQJTYvHcOnBV9MvrgYTWQjA3Qh4MzsDlND mutoe@foxmail.com
EOF
# install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python git-pip.py
# shadowsocks server
pip install shadowsocks
touch /etc/shadowsocks.json
cat > /etc/shadowsocks.json << EOF
{
"server":"0.0.0.0",
"server_port":$SS_PORT,
"local_port":1080,
"password":"$SS_PASSWD",
"timeout":600,
"method":"aes-256-cfb"
}
EOF
touch /etc/systemd/system/shadowsocks.service
cat > /etc/systemd/system/shadowsocks.service << EOF
[Unit]
Description=Shadowsocks
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/ssserver -c /etc/shadowsocks.json
[Install]
WantedBy=multi-user.target
EOF
systemctl enable shadowsocks
systemctl start shadowsocks
#!/bin/bash
read -s -p "webhooks port:" WEBHOOKS_PORT
read -s -p "webhooks secret" WEBHOOKS_SECRET
# set omzsh
echo -e \r | sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
sed -i "/plugins=(git)/ s/git/git zsh-syntax-highlighting/" ~/.zshrc
source ~/.zshrc
# set ssh keygen
ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ''
echo -e "\033[32m$(cat /root/.ssh/id_rsa.pub)\033[0m"
echo "Copy above is_rsa.pub to github SSH keys https://github.com/settings/keys"
read -p "press any ket to continue..."
# set htdoc
mkdir mutoe.com
cd mutoe.com
expect << EOF
spawn git clone git@github.com:mutoe/blog.git -b gh-pages
expect {
"Are you sure*" {send "yes\r"}
eof {exit}
}
EOF
# set nginx
sudo systemctl enable nginx
sudo nginx
sudo chmod -R 775 /etc/nginx/conf.d
sudo sed -i "/^user/c user mutoe;" /etc/nginx/nginx.conf
touch /etc/nginx/conf.d/blog.conf
cat > /etc/nginx/conf.d/blog.conf << EOF
server {
listen 80;
server_name blog.mutoe.com;
location / {
root /home/mutoe/mutoe.com/blog;
index index.html;
}
}
EOF
touch /etc/nginx/conf.d/www.conf
cat > /etc/nginx/conf.d/www.conf << EOF
server {
listen 80;
server_name mutoe.com www.mutoe.com;
access_log off;
rewrite ^/(.*) https://blog.mutoe.com$1 redirect;
}
EOF
sudo nginx -s reload
# certbot
sudo expect << EOF
spawn certbot --nginx
expect {
"Enter email address" {send "mutoe@foxmail.com\n";exp_continue}
"Please read the Terms of Service" {send "A\n";exp_continue}
"Would you be willing to share your email address" {send "N\n";exp_continue}
"Which names would you like to activate HTTPS for" {send "\n";exp_continue}
"You have an existing certificate that contains a portion of the domains" {send "E\n";exp_continue}
"You have an existing certificate that has exactly the same domains" {send "1\n";exp_continue}
"Please choose whether or not to redirect HTTP traffic to HTTPS" {send "2\n";exp_continue}
eof
}
EOF
# set webhooks
sudo yum global add pm2 @mutoe/webhooks
mkdir -p ~/mutoe.com/webhooks
cd ~/mutoe.com/webhooks
expect << EOF
spawn webhooks
expect {
"port" { send "9089\n"; exp_continue }
"secret" { send "1111\n"; exp_continue }
"bash" { send "\n" }
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.