init-debian/init.sh
2026-01-10 08:20:06 +08:00

144 lines
4.2 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" ;;
Trixie) OS_VERSION="13" ;;
esac
if [ -z $OS_VERSION ]; then
echo "Unsupported Debian Code: $OS_CODE" && exit 1
fi
DISTRO_PVE=$((command -v pvesh &>/dev/null && echo 1) || echo 0)
SCRIPT=$(readlink -f "$0")
AWD=$(dirname "$SCRIPT")
choose_sites(){
case $MIRROR_SOURCE in
1)
MIRROR_URL=https://mirrors.cernet.edu.cn/debian/
SEC_URL=https://mirrors.cernet.edu.cn/debian-security
DOCKER_URL=https://mirrors.cernet.edu.cn/docker-ce/linux/debian
DOCKER_PGP=https://mirrors.cernet.edu.cn/docker-ce/linux/debian/gpg
PVE_URL=https://mirrors.cernet.edu.cn/proxmox/debian/pve
;;
*)
MIRROR_URL=https://deb.debian.org/debian/
SEC_URL=https://security.debian.org/debian-security
DOCKER_URL=https://download.docker.com/linux/debian
DOCKER_PGP=https://download.docker.com/linux/debian/gpg
PVE_URL=http://download.proxmox.com/debian/pve
;;
esac
}
set_pkg_source(){
choose_sites
rm /etc/apt/sources.list || true
rm /etc/apt/sources.list.d/* || true
echo -e "Enabled: yes
Types: deb
URIs: $MIRROR_URL
Suites: $OS_CODE $OS_CODE-updates $OS_CODE-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Architectures: $OS_ARCH
Types: deb
URIs: $SEC_URL
Suites: $OS_CODE-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Architectures: $OS_ARCH
" | tee /etc/apt/sources.list.d/debian.sources
if ((DISTRO_PVE)); then
echo -e "Types: deb
URIs: $PVE_URL
Suites: $OS_CODE
Components: pve-no-subscription
Signed-By: /etc/apt/trusted.gpg.d/proxmox-release-$OS_CODE.gpg
" | tee /etc/apt/sources.list.d/pve-no-subscription.sources
else
echo -e "Types: deb
URIs: $DOCKER_URL
Suites: $OS_CODE
Components: stable
Signed-By: /etc/apt/trusted.gpg.d/docker.gpg
Architectures: $OS_ARCH
" | tee /etc/apt/sources.list.d/docker.sources
curl -fsSL $DOCKER_PGP | \
gpg --dearmor | tee /etc/apt/trusted.gpg.d/docker.gpg > /dev/null
#For docker-ctop
echo -e "Types: deb
URIs: http://packages.azlux.fr/debian
Suites: $OS_CODE
Components: main
Signed-By: /etc/apt/trusted.gpg.d/azlux-archive-keyring.gpg
Architectures: $OS_ARCH
" | tee /etc/apt/sources.list.d/azlux.sources
curl -fsSL "https://azlux.fr/repo.gpg.key" | \
gpg --dearmor | tee /etc/apt/trusted.gpg.d/azlux-archive-keyring.gpg > /dev/null
echo -e "Types: deb
URIs: https://packagecloud.io/crowdsec/crowdsec/any/
Suites: any
Components: main
Signed-By: /etc/apt/trusted.gpg.d/crowdsec-archive-keyring.gpg
Architectures: $OS_ARCH
" | tee /etc/apt/sources.list.d/crowdsec.sources
curl -fsSL "https://packagecloud.io/crowdsec/crowdsec/gpgkey" | \
gpg --dearmor | tee /etc/apt/trusted.gpg.d/crowdsec-archive-keyring.gpg > /dev/null
fi
}
config(){
apt update
apt list nala ca-certificates curl gnupg gpg lsb-release git zsh | awk -F'/' '/\// {print $1}' | xargs -r apt install --no-install-recommends -y
set_pkg_source
apt update
$AWD/configure.sh
}
usage(){
echo "Usage: $0 [OPTIONS]";
echo "OPTIONS:";
echo " -f <PACKAGES> package list file (default: $PKG_BASE)";
echo " -c config only";
echo " -m <CHOICE> apt mirror source";
echo " * official"
echo " 1 cernet (default)"
}
PKG_BASE="$AWD/packages-base"
DO_INSTALL=true;
MIRROR_SOURCE=1;
while getopts ":f:cm:" OPT; do
case $OPT in
f)
PKG_BASE=$OPTARG;
;;
c)
DO_INSTALL=false;
;;
m)
MIRROR_SOURCE=$OPTARG;
;;
?)
echo "Invalid Option: -$OPTARG";
usage;
exit 1;;
esac;
done;
config
if $DO_INSTALL; then
$AWD/install.sh $PKG_BASE
fi