diff --git a/init.sh b/init.sh index 833d0b2..080578a 100755 --- a/init.sh +++ b/init.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash set -e -OS_ARCH=$(dpkg --print-architecture) -OS_CODE=$(. /etc/os-release && echo "$VERSION_CODENAME") +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" ;; @@ -13,6 +13,35 @@ SCRIPT=$(readlink -f "$0") SCRIPTPATH=$(dirname "$SCRIPT") echo $SCRIPTPATH +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(){ sed -i -r "s/.*set tabsize.*/set tabsize 4/g" /etc/nanorc sed -i -r "s/.*set tabstospaces.*/set tabstospaces/g" /etc/nanorc @@ -24,20 +53,11 @@ configure(){ 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 - mirror_site=mirrors.nju.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 + 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" @@ -55,7 +75,7 @@ deb https://$sec_site/debian-security $OS_CODE-security main contrib non-free no 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" | \ + 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 @@ -83,16 +103,20 @@ install_pkg(){ usage(){ echo "Usage: $0 [OPTIONS]"; - echo "Options:"; + echo "OPTIONS:"; echo " -f package list file (default: $PKG_BASE)"; echo " -i install only"; - echo " -o original apt source"; + echo " -m apt mirror source"; + echo " 1 ustc (default)" + echo " 2 xjtu" + echo " 3 nju" + echo " 4 tsinghua" } PKG_BASE="$SCRIPTPATH/packages-base" INSTALL_ONLY=0; -ORIGINAL_SOURCE=0; -while getopts ":f:io" OPT; do +MIRROR_SOURCE=1; +while getopts ":f:im:" OPT; do case $OPT in f) PKG_BASE=$OPTARG; @@ -100,8 +124,8 @@ while getopts ":f:io" OPT; do i) INSTALL_ONLY=1; ;; - o) - ORIGINAL_SOURCE=1; + m) + MIRROR_SOURCE=$OPTARG; ;; ?) echo "Invalid Option: -$OPTARG";