194 lines
6.1 KiB
Bash
Executable File
194 lines
6.1 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_BRANCH=""
|
|
case $OS_CODE in
|
|
bookworm) OS_BRANCH="debian" ;;
|
|
trixie) OS_BRANCH="debian" ;;
|
|
noble) OS_BRANCH="ubuntu" ;;
|
|
esac
|
|
if [ -z $OS_BRANCH ]; 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)
|
|
DEBIAN_URL=https://mirrors.cernet.edu.cn/debian
|
|
DEBIAN_SEC_URL=https://mirrors.cernet.edu.cn/debian-security
|
|
DOCKER_DEBIAN_URL=https://mirrors.cernet.edu.cn/docker-ce/linux/debian
|
|
PVE_URL=https://mirrors.cernet.edu.cn/proxmox/debian/pve
|
|
UBUNTU_URL=https://mirrors.cernet.edu.cn/ubuntu
|
|
DOCKER_UBUNTU_URL=https://mirrors.cernet.edu.cn/docker-ce/linux/ubuntu
|
|
;;
|
|
2)
|
|
DEBIAN_URL=https://mirrors.aliyun.com/debian
|
|
DEBIAN_SEC_URL=https://mirrors.aliyun.com/debian-security
|
|
DOCKER_DEBIAN_URL=https://mirrors.aliyun.com/docker-ce/linux/debian
|
|
PVE_URL=https://mirrors.cernet.edu.cn/proxmox/debian/pve
|
|
UBUNTU_URL=https://mirrors.aliyun.com/ubuntu
|
|
DOCKER_UBUNTU_URL=https://mirrors.aliyun.com/docker-ce/linux/ubuntu
|
|
;;
|
|
*)
|
|
DEBIAN_URL=https://deb.debian.org/debian
|
|
DEBIAN_SEC_URL=https://security.debian.org/debian-security
|
|
DOCKER_DEBIAN_URL=https://download.docker.com/linux/debian
|
|
PVE_URL=http://download.proxmox.com/debian/pve
|
|
UBUNTU_URL=https://archive.ubuntu.com/ubuntu
|
|
DOCKER_UBUNTU_URL=https://download.docker.com/linux/ubuntu
|
|
;;
|
|
esac
|
|
}
|
|
|
|
|
|
set_pkg_source(){
|
|
choose_sites
|
|
rm /etc/apt/sources.list || true
|
|
rm /etc/apt/sources.list.d/* || true
|
|
|
|
if [[ $OS_BRANCH == "debian" ]]; then
|
|
echo -e "Enabled: yes
|
|
Types: deb
|
|
URIs: $DEBIAN_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: $DEBIAN_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
|
|
|
|
elif [[ $OS_BRANCH == "ubuntu" ]]; then
|
|
echo -e "Enabled: yes
|
|
Types: deb
|
|
URIs: $UBUNTU_URL
|
|
Suites: $OS_CODE $OS_CODE-updates $OS_CODE-backports
|
|
Components: main restricted universe multiverse
|
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
Architectures: $OS_ARCH
|
|
|
|
Types: deb
|
|
URIs: $UBUNTU_URL
|
|
Suites: $OS_CODE-security
|
|
Components: main restricted universe multiverse
|
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
Architectures: $OS_ARCH
|
|
" | tee /etc/apt/sources.list.d/ubuntu.sources
|
|
fi
|
|
|
|
|
|
if ((DISTRO_PVE)); then
|
|
echo -e "Types: deb
|
|
URIs: $PVE_URL
|
|
Suites: $OS_CODE
|
|
Components: pve-no-subscription
|
|
Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg
|
|
" | tee /etc/apt/sources.list.d/pve-no-subscription.sources
|
|
else
|
|
|
|
if [[ $OS_BRANCH == "debian" ]]; then
|
|
echo -e "Types: deb
|
|
URIs: $DOCKER_DEBIAN_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_DEBIAN_URL/gpg $SET_PROXY | \
|
|
gpg --dearmor | tee /etc/apt/trusted.gpg.d/docker.gpg > /dev/null
|
|
|
|
#For docker-ctop
|
|
echo -e "Types: deb
|
|
URIs: https://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" $SET_PROXY | \
|
|
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" $SET_PROXY | \
|
|
gpg --dearmor | tee /etc/apt/trusted.gpg.d/crowdsec-archive-keyring.gpg > /dev/null
|
|
|
|
elif [[ $OS_BRANCH == "ubuntu" ]]; then
|
|
echo -e "Types: deb
|
|
URIs: $DOCKER_UBUNTU_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_UBUNTU_URL/gpg $SET_PROXY | \
|
|
gpg --dearmor | tee /etc/apt/trusted.gpg.d/docker.gpg > /dev/null
|
|
fi
|
|
fi
|
|
}
|
|
|
|
setup(){
|
|
apt update || true
|
|
apt-cache search '' | awk '{print $1}' | grep -Ex 'nala|ca-certificates|curl|gnupg|gpg|lsb-release|git|zsh' | xargs -r apt install --no-install-recommends -y
|
|
set_pkg_source
|
|
apt update
|
|
}
|
|
|
|
usage(){
|
|
echo "Usage: $0 [OPTIONS]";
|
|
echo "OPTIONS:";
|
|
echo " -f <PACKAGES> package list file (default: $PKG_BASE)";
|
|
echo " -s setup only";
|
|
echo " -m <CHOICE> apt mirror source";
|
|
echo " * official"
|
|
echo " 1 cernet (default)"
|
|
echo " 2 aliyun"
|
|
echo " -x <PROXY> Proxy [protocol://]host[:port]";
|
|
}
|
|
|
|
PKG_BASE="$AWD/packages-base"
|
|
DO_INSTALL=true;
|
|
MIRROR_SOURCE=1;
|
|
SET_PROXY=;
|
|
while getopts ":f:sm:x:" OPT; do
|
|
case $OPT in
|
|
f)
|
|
PKG_BASE=$OPTARG;
|
|
;;
|
|
s)
|
|
DO_INSTALL=false;
|
|
;;
|
|
m)
|
|
MIRROR_SOURCE=$OPTARG;
|
|
;;
|
|
x)
|
|
SET_PROXY="-x $OPTARG";
|
|
;;
|
|
?)
|
|
echo "Invalid Option: -$OPTARG";
|
|
usage;
|
|
exit 1;;
|
|
esac;
|
|
done;
|
|
|
|
setup
|
|
if $DO_INSTALL; then
|
|
$AWD/install.sh $PKG_BASE
|
|
$AWD/configure.sh
|
|
fi |