[工具] Shell 批量设置官方软件源(openSUSE Leap 15.2 版)

#!/bin/bash
#作者:朱明宇
#名称:批量设置官方软件源(openSUSE 版)
#作用:批量设置官方软件源(openSUSE 版)

#使用方法:
#1. 服务器清单 $add_repo_servers_list.txt 每一个服务器名占用一行,并和此脚本放在同一目录下
#2. 在此脚本的分割线内写入相应的内容
#3. 给此脚本增加执行权限
#4. 执行此脚本

#注意:此脚本执行前必须要先保证能无秘钥远程这些远程服务器

#######################我是分割线:两条分割线里的内容需要使用者自己配置########################

add_repo_servers_list.txt #存放要设置官方软件源的文件

#######################我是分割线:两条分割线里的内容需要使用者自己配置########################

cat add_repo_servers_list.txt
read -p "will add opensuse_leap_15.2 repo please input y " a
echo $a
if [ "$a" != "y" ];then
echo "you don't agree so exit now"
exit
fi

for i in `awk '{print $1}' add_repo_servers_list.txt`
do
ssh $i '
sudo -u root su - root -c "zypper mr -da"
sudo -u root su - root -c "zypper ar -fcg http://download.opensuse.org/distribution/leap/15.2/repo/oss/ OpenSUSE_Leap_152_x64_update-oss"
sudo -u root su - root -c "zypper ar -fcg http://download.opensuse.org/distribution/leap/15.2/repo/non-oss/ OpenSUSE_Leap_152_x64_update-non-oss"
sudo -u root su - root -c "zypper ar -fcg http://download.opensuse.org/update/leap/15.2/oss/ OpenSUSE_Leap_152_x64_oss"
sudo -u root su - root -c "zypper ar -fcg http://download.opensuse.org/update/leap/15.2/non-oss/ OpenSUSE_Leap_152_x64_non-oss"
sudo -u root su - root -c "zypper ref"
done