aboutsummaryrefslogtreecommitdiff
path: root/docker/debian-dev/bootstrap/apt-source
diff options
context:
space:
mode:
Diffstat (limited to 'docker/debian-dev/bootstrap/apt-source')
-rw-r--r--docker/debian-dev/bootstrap/apt-source/11/add-deb-src.bash14
-rw-r--r--docker/debian-dev/bootstrap/apt-source/11/get-domain.bash5
-rw-r--r--docker/debian-dev/bootstrap/apt-source/11/replace-domain.bash7
-rw-r--r--docker/debian-dev/bootstrap/apt-source/11/replace-http.bash7
-rw-r--r--docker/debian-dev/bootstrap/apt-source/12/add-deb-src.bash22
-rw-r--r--docker/debian-dev/bootstrap/apt-source/12/get-domain.bash6
-rw-r--r--docker/debian-dev/bootstrap/apt-source/12/replace-domain.bash7
-rw-r--r--docker/debian-dev/bootstrap/apt-source/12/replace-http.bash7
-rw-r--r--docker/debian-dev/bootstrap/apt-source/china-source.txt1
-rw-r--r--docker/debian-dev/bootstrap/apt-source/install-apt-https.bash8
-rw-r--r--docker/debian-dev/bootstrap/apt-source/setup.bash34
11 files changed, 118 insertions, 0 deletions
diff --git a/docker/debian-dev/bootstrap/apt-source/11/add-deb-src.bash b/docker/debian-dev/bootstrap/apt-source/11/add-deb-src.bash
new file mode 100644
index 0000000..e134a00
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/11/add-deb-src.bash
@@ -0,0 +1,14 @@
+#! /usr/bin/env bash
+
+set -e
+
+dir=$(dirname "$0")
+domain=$("$dir/get-domain.bash")
+
+cat <<EOF >> /etc/apt/sources.list
+
+deb-src https://$domain/debian/ bullseye main
+deb-src https://$domain/debian-security/ bullseye-security main
+deb-src https://$domain/debian-updates/ bullseye-updates main
+
+EOF
diff --git a/docker/debian-dev/bootstrap/apt-source/11/get-domain.bash b/docker/debian-dev/bootstrap/apt-source/11/get-domain.bash
new file mode 100644
index 0000000..d44ea65
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/11/get-domain.bash
@@ -0,0 +1,5 @@
+#! /usr/bin/env bash
+
+set -e
+
+sed "s|.*https\?://\([-_.a-zA-Z0-9]\+\)/.*|\\1|;q" /etc/apt/sources.list
diff --git a/docker/debian-dev/bootstrap/apt-source/11/replace-domain.bash b/docker/debian-dev/bootstrap/apt-source/11/replace-domain.bash
new file mode 100644
index 0000000..86e88dc
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/11/replace-domain.bash
@@ -0,0 +1,7 @@
+#! /usr/bin/env bash
+
+set -e
+
+echo "Backup /etc/apt/sources.list to /etc/apt/sources.list.bak."
+echo "Replace source domain in /etc/apt/sources.list to $1."
+sed -i.bak "s|\(https\?://\)[-_.a-zA-Z0-9]\+/|\\1$1/|" /etc/apt/sources.list
diff --git a/docker/debian-dev/bootstrap/apt-source/11/replace-http.bash b/docker/debian-dev/bootstrap/apt-source/11/replace-http.bash
new file mode 100644
index 0000000..fae082a
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/11/replace-http.bash
@@ -0,0 +1,7 @@
+#! /usr/bin/env bash
+
+set -e
+
+echo "Backup /etc/apt/sources.list to /etc/apt/sources.list.bak."
+echo "Replace http to https in /etc/apt/sources.list."
+sed -i.bak 's/https\?/https/' /etc/apt/sources.list
diff --git a/docker/debian-dev/bootstrap/apt-source/12/add-deb-src.bash b/docker/debian-dev/bootstrap/apt-source/12/add-deb-src.bash
new file mode 100644
index 0000000..cf741d6
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/12/add-deb-src.bash
@@ -0,0 +1,22 @@
+#! /usr/bin/env bash
+
+set -e
+
+dir=$(dirname "$0")
+domain=$("$dir/get-domain.bash")
+
+cat <<EOF >> /etc/apt/sources.list.d/debian.sources
+
+Types: deb-src
+URIs: https://$domain/debian
+Suites: bookworm bookworm-updates
+Components: main
+Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
+
+Types: deb-src
+URIs: https://$domain/debian-security
+Suites: bookworm-security
+Components: main
+Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
+
+EOF \ No newline at end of file
diff --git a/docker/debian-dev/bootstrap/apt-source/12/get-domain.bash b/docker/debian-dev/bootstrap/apt-source/12/get-domain.bash
new file mode 100644
index 0000000..a24538c
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/12/get-domain.bash
@@ -0,0 +1,6 @@
+#! /usr/bin/env bash
+
+set -e
+
+grep -e 'URIs:' /etc/apt/sources.list.d/debian.sources | \
+ sed -E 's|URIs:\s*https?://([-_.a-zA-Z0-9]+)/.*|\1|;q'
diff --git a/docker/debian-dev/bootstrap/apt-source/12/replace-domain.bash b/docker/debian-dev/bootstrap/apt-source/12/replace-domain.bash
new file mode 100644
index 0000000..d55307c
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/12/replace-domain.bash
@@ -0,0 +1,7 @@
+#! /usr/bin/env bash
+
+set -e
+
+echo "Backup /etc/apt/sources.list.d/debian.sources to /etc/apt/sources.list.d/debian.sources.bak."
+echo "Replace source domain in /etc/apt/sources.list.d/debian.sources to $1."
+sed -i.bak -E "s|(URIs:\\s*https?://)[-_.a-zA-Z0-9]+(/.*)|\\1$1\\2|" /etc/apt/sources.list.d/debian.sources
diff --git a/docker/debian-dev/bootstrap/apt-source/12/replace-http.bash b/docker/debian-dev/bootstrap/apt-source/12/replace-http.bash
new file mode 100644
index 0000000..ed4391d
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/12/replace-http.bash
@@ -0,0 +1,7 @@
+#! /usr/bin/env bash
+
+set -e
+
+echo "Backup /etc/apt/sources.list to /etc/apt/sources.list.d/debian.sources.bak."
+echo "Replace http to https in /etc/apt/sources.list.d/debian.sources."
+sed -i.bak -E "s|(URIs:\\s*)https?(://[-_.a-zA-Z0-9]+/.*)|\\1https\\2|" /etc/apt/sources.list.d/debian.sources
diff --git a/docker/debian-dev/bootstrap/apt-source/china-source.txt b/docker/debian-dev/bootstrap/apt-source/china-source.txt
new file mode 100644
index 0000000..4312686
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/china-source.txt
@@ -0,0 +1 @@
+mirrors.tuna.tsinghua.edu.cn \ No newline at end of file
diff --git a/docker/debian-dev/bootstrap/apt-source/install-apt-https.bash b/docker/debian-dev/bootstrap/apt-source/install-apt-https.bash
new file mode 100644
index 0000000..70fb371
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/install-apt-https.bash
@@ -0,0 +1,8 @@
+#! /usr/bin/env bash
+
+set -e
+
+echo "Install apt https transport."
+apt-get update
+apt-get install -y apt-utils
+apt-get install -y apt-transport-https ca-certificates
diff --git a/docker/debian-dev/bootstrap/apt-source/setup.bash b/docker/debian-dev/bootstrap/apt-source/setup.bash
new file mode 100644
index 0000000..cdf68af
--- /dev/null
+++ b/docker/debian-dev/bootstrap/apt-source/setup.bash
@@ -0,0 +1,34 @@
+#! /usr/bin/env bash
+
+set -e
+
+dir=/bootstrap/apt-source
+
+echo "Getting debian version..."
+debian_version=$("$dir/../get-debian-version.bash")
+
+if [[ -z $debian_version ]]; then
+ echo "Debian version not found."
+ exit 1
+else
+ echo "Debian version: $debian_version"
+fi
+
+if [[ $debian_version -ge 12 ]]; then
+ setup_dir=$dir/12
+else
+ setup_dir=$dir/11
+fi
+
+echo "Setting up apt source..."
+
+if [[ -n $CRUPEST_DEBIAN_DEV_IN_CHINA ]]; then
+ echo "In China, using China source..."
+ "$setup_dir/replace-domain.bash" "$(cat "$dir/china-source.txt")"
+fi
+
+"$dir/install-apt-https.bash"
+"$setup_dir/replace-http.bash"
+"$setup_dir/add-deb-src.bash"
+
+echo "Setting up apt source done."