init-debian/init.sh
2024-01-25 16:44:01 +08:00

113 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
OS_ARCH=$(dpkg --print-architecture)
OS_CODE=$(. /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")
echo $SCRIPTPATH
configure(){
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" >> /etc/ssh/ssh_config
echo " PubkeyAcceptedKeyTypes ssh-ed25519,ssh-rsa" >> /etc/ssh/ssh_config
mirror_site=mirrors.tuna.tsinghua.edu.cn
#mirror_site=mirrors.ustc.edu.cn
sec_site=$mirror_site
docker_source=https://$mirror_site/docker-ce/linux/debian
if [ $ORIGINAL_SOURCE -eq 1 ]; then
mirror_site="deb.debian.org"
sec_site="security.debian.org"
docker_source=https://download.docker.com/linux/debian
fi;
echo -e "deb https://$mirror_site/debian/ $OS_CODE main contrib non-free non-free-firmware
deb https://$mirror_site/debian/ $OS_CODE-updates main contrib non-free non-free-firmware
deb https://$mirror_site/debian/ $OS_CODE-backports main contrib non-free non-free-firmware
deb https://$sec_site/debian-security $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_source $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
cp "$SCRIPTPATH/.zshrc" $HOME
usermod -s /usr/bin/zsh $(whoami)
}
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 " -o original apt source";
}
PKG_BASE="$SCRIPTPATH/packages-base"
INSTALL_ONLY=0;
ORIGINAL_SOURCE=0;
while getopts ":f:io" OPT; do
case $OPT in
f)
PKG_BASE=$OPTARG;
;;
i)
INSTALL_ONLY=1;
;;
o)
ORIGINAL_SOURCE=1;
;;
?)
echo "Invalid Option: -$OPTARG";
usage;
exit 1;;
esac;
done;
if [ $INSTALL_ONLY -eq 0 ]; then
configure;
fi;
install_pkg;