init-debian/init.sh
2024-01-30 05:29:30 +08:00

147 lines
5.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
OS_ARCH=$(dpkg --print-architecture) || (echo "Not Debian Based Distro" && exit 1)
OS_CODE=$(source /etc/os-release && echo "$VERSION_CODENAME")
OS_VERSION=""
case $OS_CODE in
bullseye) OS_VERSION="11" ;;
bookworm) OS_VERSION="12" ;;
esac
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
choose_sites(){
case $MIRROR_SOURCE in
1)
MIRROR_URL=https://mirrors.ustc.edu.cn/debian/
SEC_URL=https://mirrors.ustc.edu.cn/debian-security
DOCKER_URL=https://mirrors.ustc.edu.cn/docker-ce/linux/debian
;;
2)
MIRROR_URL=https://mirrors.xjtu.edu.cn/debian/
SEC_URL=https://mirrors.xjtu.edu.cn/debian-security
DOCKER_URL=https://mirrors.xjtu.edu.cn/docker-ce/linux/debian
;;
3)
MIRROR_URL=https://mirrors.nju.edu.cn/debian/
SEC_URL=https://mirrors.nju.edu.cn/debian-security
DOCKER_URL=https://mirrors.nju.edu.cn/docker-ce/linux/debian
;;
4)
MIRROR_URL=https://mirrors.tuna.tsinghua.edu.cn/debian/
SEC_URL=https://mirrors.tuna.tsinghua.edu.cn/debian-security
DOCKER_URL=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian
;;
*)
MIRROR_URL=https://deb.debian.org/debian/
SEC_URL=https://security.debian.org/debian-security
DOCKER_URL=https://download.docker.com/linux/debian
;;
esac
}
configure(){
choose_sites
sed -i -r "s/.*set tabsize.*/set tabsize 4/g" /etc/nanorc
sed -i -r "s/.*set tabstospaces.*/set tabstospaces/g" /etc/nanorc
sed -i -r "/.*HashKnownHosts.*/d" /etc/ssh/ssh_config
sed -i -r "/.*HostKeyAlgorithms.*/d" /etc/ssh/ssh_config
sed -i -r "/.*PubkeyAcceptedKeyTypes.*/d" /etc/ssh/ssh_config
echo " HashKnownHosts no" >> /etc/ssh/ssh_config
echo " HostKeyAlgorithms ssh-ed25519,ssh-rsa,rsa-sha2-256" >> /etc/ssh/ssh_config
echo " PubkeyAcceptedKeyTypes ssh-ed25519,ssh-rsa,rsa-sha2-256" >> /etc/ssh/ssh_config
echo -e "deb $MIRROR_URL $OS_CODE main contrib non-free non-free-firmware
deb $MIRROR_URL $OS_CODE-updates main contrib non-free non-free-firmware
deb $MIRROR_URL $OS_CODE-backports main contrib non-free non-free-firmware
deb $SEC_URL $OS_CODE-security main contrib non-free non-free-firmware
" | tee /etc/apt/sources.list
command="nala"
apt update
apt install $command || command="apt"
$command install ca-certificates curl gnupg lsb-release zsh
if [[ $OS_VERSION=="12" ]]; then
OS_VERSION="Testing"
fi
echo "deb http://download.opensuse.org/repositories/shells:/zsh-users:/zsh-completions/Debian_$OS_VERSION/ /" | \
tee /etc/apt/sources.list.d/shells:zsh-users:zsh-completions.list
curl -fsSL "https://download.opensuse.org/repositories/shells:zsh-users:zsh-completions/Debian_$OS_VERSION/Release.key" | \
gpg --dearmor | tee /etc/apt/trusted.gpg.d/shells_zsh-users_zsh-completions.gpg > /dev/null
echo "deb [arch=$OS_ARCH] $DOCKER_URL $OS_CODE stable" | \
tee /etc/apt/sources.list.d/docker.list
curl -fsSL "https://download.docker.com/linux/debian/gpg" | \
gpg --dearmor | tee /etc/apt/trusted.gpg.d/docker.gpg > /dev/null
echo "deb https://packagecloud.io/ookla/speedtest-cli/debian/ $OS_CODE main" | \
tee /etc/apt/sources.list.d/ookla_speedtest-cli.list
curl -fsSL "https://packagecloud.io/ookla/speedtest-cli/gpgkey" | \
gpg --dearmor | tee /etc/apt/trusted.gpg.d/ookla_speedtest-cli-archive-keyring.gpg > /dev/null
echo "deb [arch=$OS_ARCH] http://packages.azlux.fr/debian $OS_CODE main" | \
tee /etc/apt/sources.list.d/azlux.list
curl -fsSL "https://azlux.fr/repo.gpg.key" | \
gpg --dearmor | tee /etc/apt/trusted.gpg.d/azlux-archive-keyring.gpg > /dev/null
usermod -s /usr/bin/zsh $(whoami)
cp "$SCRIPTPATH/.zshrc" $HOME
cp "$SCRIPTPATH/.screenrc" $HOME
cp $SCRIPTPATH/*.py $HOME
}
install_pkg(){
command="nala"
command -v $command &>/dev/null || command="apt"
$command update
test -r "$PKG_BASE"
xargs -a <(awk '! /^ *(#|$)/' "$PKG_BASE") -r $command install
}
usage(){
echo "Usage: $0 [OPTIONS]";
echo "OPTIONS:";
echo " -f <PACKAGES> package list file (default: $PKG_BASE)";
echo " -i install only";
echo " -m <CHOICE> apt mirror source";
echo " 1 ustc (default)"
echo " 2 xjtu"
echo " 3 nju"
echo " 4 tsinghua"
}
PKG_BASE="$SCRIPTPATH/packages-base"
INSTALL_ONLY=0;
MIRROR_SOURCE=1;
while getopts ":f:im:" OPT; do
case $OPT in
f)
PKG_BASE=$OPTARG;
;;
i)
INSTALL_ONLY=1;
;;
m)
MIRROR_SOURCE=$OPTARG;
;;
?)
echo "Invalid Option: -$OPTARG";
usage;
exit 1;;
esac;
done;
if [ $INSTALL_ONLY -eq 0 ]; then
configure;
fi;
install_pkg;