Skip to content

Instantly share code, notes, and snippets.

@ZeekoZhu
Last active December 7, 2018 09:19
Show Gist options
  • Save ZeekoZhu/af1a3a259a1a0d65e6f89960418084b8 to your computer and use it in GitHub Desktop.
Save ZeekoZhu/af1a3a259a1a0d65e6f89960418084b8 to your computer and use it in GitHub Desktop.
Arch Linux Initialization
#!/bin/bash
USERNAME='zeeko'
HOSTNAME='hostodo'
SS_PORTNO='2333'
SS_METHOD='aes-256-gcm'
SS_PASSWD='password'
# Repo
cat >> /etc/pacman.conf << EOF
[archlinuxcn]
Server = https://cdn.repo.archlinuxcn.org/\$arch
EOF
# Kernel and packages; I prefer lts kernel
pacman -Syyu --noconfirm linux-lts sudo mosh git vim fish wget yarn \
htop docker docker-compose nodejs npm shadowsocks-libev simple-obfs screenfetch \
archlinuxcn-keyring screen
pacman -Rs linux --noconfirm
grub-mkconfig -o /boot/grub/grub.cfg
# hostname
echo $HOSTNAME > /etc/hostname
# Locale: timezone and language
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo LANG=en_US.UTF-8 > /etc/locale.conf
sed -i 's/#en_US.UTF-8\ UTF-8/en_US.UTF-8\ UTF-8/g' /etc/locale.gen
sed -i 's/#zh_CN.UTF-8\ UTF-8/zh_CN.UTF-8\ UTF-8/g' /etc/locale.gen
locale-gen
# Optmize tcp
cat > /etc/sysctl.d/tcp_fastopen.conf << EOF
# tcp_fastopen
net.ipv4.tcp_fastopen = 3
EOF
cat > /etc/modules-load.d/tcp_bbr.conf << EOF
tcp_bbr
EOF
cat > /etc/modules-load.d/modules.conf << EOF
# tcp_bbr
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
EOF
modprobe tcp_bbr
sysctl --system
# check
sysctl net.ipv4.tcp_available_congestion_control
sysctl net.ipv4.tcp_congestion_control
# User
useradd -mG wheel,docker $USERNAME -s /usr/bin/fish
echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel
# sed -i 's/PermitRootLogin\ yes/PermitRootLogin\ no/g' /etc/ssh/sshd_config
systemd_service() {
systemctl start $1
systemctl enable $1
}
# Docker
systemd_service docker.service
# shadowsocks-libev-server
mkdir /etc/shadowsocks
cat > /etc/shadowsocks/config.json << EOF
{
"server": "0.0.0.0",
"server_port": ${SS_PORTNO},
"method": "${SS_METHOD}",
"password": "${SS_PASSWD}",
"plugin": "obfs-server",
"plugin_opts": "obfs=tls"
}
EOF
systemd_service shadowsocks-libev-server@config.service
# Root fish shell config
chsh -s /usr/bin/fish
mkdir -p /root/.config/fish
cat > /root/.config/fish/config.fish << EOF
function fish_greeting
echo "You are now ROOT user!"
echo "With great power, comes great responsibility."
end
alias l="ls -Alh"
alias qwq="uname -snrm; uptime"
EOF
# Config for user
# Install fisherman
curl -Lo /home/$USERNAME/.config/fish/functions/fisher.fish --create-dirs https://git.io/fisher
# greeting and alias
cat > /home/$USERNAME/.config/fish/config.fish << EOF
function fish_greeting
uname -snrm; uptime
end
set -gx PATH \$PATH \$HOME/.local/bin
alias l="ls -Alh"
alias qwq="uname -snrm; uptime"
# zeeko.fish
alias stls="sudo systemctl start"
alias stlr="sudo systemctl restart"
alias stlR="sudo systemctl daemon-reload"
alias stlp="sudo systemctl stop"
alias stl="sudo systemctl status"
EOF
# Config dirs
mkdir -p /home/$USERNAME/.local/bin
user_dir() {
mkdir -p $1
chown -R $USERNAME:$USERNAME $1
}
user_dir /home/$USERNAME/.local
user_dir /home/$USERNAME/.config
screenfetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment