32 lines
946 B
Bash
Executable File
32 lines
946 B
Bash
Executable File
#!/bin/bash
|
|
# Ver: 1.2 by Endial Fang (endial@126.com)
|
|
#
|
|
# 此脚本用于根据传入的参数选择对应的 apt 源配置文件并复制到指定目录
|
|
# shell 执行参数,分别为 -e(命令执行错误则退出脚本) -u(变量未定义则报错) -x(打印实际待执行的命令行)
|
|
set -eu
|
|
|
|
# 检查是否有足够的权限
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Error: This script must be run as root."
|
|
exit 1
|
|
fi
|
|
|
|
# 获取用户传入的参数,若未传入则使用默认值 "default"
|
|
source_name=${1:-default}
|
|
|
|
# 定义源文件路径
|
|
source_file="/etc/apt/sources/${source_name}.sources"
|
|
|
|
# 检查源文件是否存在
|
|
if [ ! -f "$source_file" ]; then
|
|
echo "Error: Source file $source_file does not exist."
|
|
exit 1
|
|
fi
|
|
|
|
# 定义目标文件路径
|
|
target_file="/etc/apt/sources.list.d/debian.sources"
|
|
|
|
# 复制源文件到目标文件
|
|
cp "$source_file" "$target_file"
|
|
echo "Successfully selected apt source: $source_name"
|