Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support deb822 format in Ubuntu 24.04 #25

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 60 additions & 7 deletions src/mirrors/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ check() {
[ "$NAME" = "Ubuntu" ]
}

_ubuntu_set_config_file() {
config_file="/etc/apt/sources.list.d/ubuntu.sources"
if ! [ -f $config_file ]; then # rule for ubuntu before 24.04
config_file="/etc/apt/sources.list"
fi
}

install() {
config_file="/etc/apt/sources.list"
_ubuntu_set_config_file
source_os_release
codename=${VERSION_CODENAME}
set_sudo
Expand All @@ -26,7 +33,48 @@ install() {
confirm "Use source code?" && \
src_prefix=""

$sudo sh -e -c "cat <<EOF > ${config_file}
# 如果 config_file == /etc/apt/sources.list.d/ubuntu.sources
if [ "$config_file" = "/etc/apt/sources.list.d/ubuntu.sources" ]; then
$sudo sh -e -c "cat <<EOF > ${config_file}
# ${gen_tag}
Types: deb
URIs: ${http}://${domain}/ubuntu/
Suites: ${codename} ${codename}-updates ${codename}-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

${src_prefix}Types: deb-src
${src_prefix}URIs: ${http}://${domain}/ubuntu/
${src_prefix}Suites: ${codename} ${codename}-updates ${codename}-backports
${src_prefix}Components: main universe restricted multiverse
${src_prefix}Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: ${secure_url}
Suites: ${codename}-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

${src_prefix}Types: deb-src
${src_prefix}URIs: ${secure_url}
${src_prefix}Suites: ${codename}-security
${src_prefix}Components: main universe restricted multiverse
${src_prefix}Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

${propoesd_prefix}Types: deb
${propoesd_prefix}URIs: ${http}://${domain}/ubuntu/
${propoesd_prefix}Suites: ${codename}-proposed
${propoesd_prefix}Components: main universe restricted multiverse
${propoesd_prefix}Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

${propoesd_prefix}Types: deb-src
${propoesd_prefix}URIs: ${http}://${domain}/ubuntu/
${propoesd_prefix}Suites: ${codename}-proposed
${propoesd_prefix}Components: main universe restricted multiverse
${propoesd_prefix}Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF"
else
$sudo sh -e -c "cat <<EOF > ${config_file}
# ${gen_tag}
deb ${http}://${domain}/ubuntu/ ${codename} main restricted universe multiverse
${src_prefix}deb-src ${http}://${domain}/ubuntu/ ${codename} main restricted universe multiverse
Expand All @@ -40,10 +88,13 @@ ${src_prefix}deb-src ${secure_url} ${codename}-security main restricted universe

${propoesd_prefix}deb ${http}://${domain}/ubuntu/ ${codename}-proposed main restricted universe multiverse
${propoesd_prefix}deb-src ${http}://${domain}/ubuntu/ ${codename}-proposed main restricted universe multiverse
EOF" || {
EOF"
fi

if [ $? -ne 0 ]; then
print_error "Write ${config_file} failed"
return 1
}
fi

confirm_y "Do you want to apt update?" && {
$sudo apt update || {
Expand All @@ -56,7 +107,7 @@ EOF" || {
}

uninstall() {
config_file="/etc/apt/sources.list"
_ubuntu_set_config_file
set_sudo
$sudo mv ${config_file}.bak ${config_file} || {
print_error "Failed to recover ${config_file}"
Expand All @@ -65,14 +116,16 @@ uninstall() {
}

is_deployed() {
config_file="/etc/apt/sources.list"
_ubuntu_set_config_file
result=0
$sudo grep -q "${gen_tag}" ${config_file} || result=$?
return $result
}

can_recover() {
bak_file="/etc/apt/sources.list.bak"
_ubuntu_set_config_file
bak_file="$config_file.bak"

result=0
test -f $bak_file || result=$?
return $result
Expand Down