48 lines
1.9 KiB
Bash
48 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Configure Chinese mirrors (Aliyun) for apt, pip, and npm
|
|
# Can be called independently or during container initialization
|
|
|
|
set -e
|
|
|
|
echo "Configuring Chinese mirrors (Aliyun) for apt, pip, and npm..."
|
|
|
|
# Replace Ubuntu sources with Aliyun mirror
|
|
if [[ -f /etc/apt/sources.list.d/ubuntu.sources ]]; then
|
|
sudo sed -i 's|http://archive.ubuntu.com/ubuntu/|https://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list.d/ubuntu.sources
|
|
sudo sed -i 's|http://security.ubuntu.com/ubuntu/|https://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list.d/ubuntu.sources
|
|
echo "Updated Ubuntu apt sources to use Aliyun mirrors"
|
|
fi
|
|
|
|
# Configure npm registry to use Chinese mirror (npmmirror.com is the recommended mirror)
|
|
if command -v npm &> /dev/null; then
|
|
npm config set registry https://registry.npmmirror.com/
|
|
echo "Configured npm registry to use Chinese mirror (registry.npmmirror.com)"
|
|
fi
|
|
# Also set system-wide npm config for all users
|
|
sudo mkdir -p /etc/npm
|
|
echo "registry=https://registry.npmmirror.com/" | sudo tee /etc/npm/npmrc > /dev/null
|
|
# Set for root user as well (for when npm is installed later)
|
|
sudo mkdir -p /root/.npm
|
|
echo "registry=https://registry.npmmirror.com/" | sudo tee /root/.npmrc > /dev/null
|
|
echo "Configured npm registry to use Chinese mirror (registry.npmmirror.com)"
|
|
|
|
# Configure pip to use Aliyun mirror
|
|
sudo mkdir -p /etc/pip
|
|
echo "[global]
|
|
index-url = https://mirrors.aliyun.com/pypi/simple/
|
|
|
|
[install]
|
|
trusted-host = mirrors.aliyun.com" | sudo tee /etc/pip/pip.conf > /dev/null
|
|
echo "Configured pip to use Aliyun mirror"
|
|
|
|
# Update apt package cache after changing mirrors
|
|
echo "Updating apt package cache from new mirrors..."
|
|
if sudo apt update; then
|
|
echo "Apt package cache updated successfully from Aliyun mirrors"
|
|
else
|
|
echo "Warning: apt update failed, but mirrors are configured"
|
|
fi
|
|
|
|
echo "Chinese mirrors (Aliyun) configuration completed"
|