其实还有很多不足的地方,bug还是比较多的
#!/bin/bash #author joe #description this shell is to create the yum repofile Path="/etc/yum.repos.d/" Name=".repo" declare -i Enabled declare -i Gpgcheck file_exit(){ if [ $1 == "quit" ];then exit 5 fi } check_name() { file_exit $1 local filename=$1 if [ -e $Path$filename$Name ];then read -p "do you want to add some thing in this repofile?(y/n):" answer if [ $answer == "y" ];then return 4 else read -p "the $filename is exist" filename return 3 fi else touch $Path$filename$Name fi } check_file_thing() { local filename=$1 read -p "1.insert the repo id:" Id file_exit $Id while : do read -p "2.insert the repo baseurl:" Baseurl curl -m1 $Baseurl &>/dev/null if [ $? -eq 0 ];then break else echo "the error baseurl you insert,please do again!" continue fi done read -p "3.insert the enabled of the repo(enabled=0):" Enabled read -p "4.insert the gpgcheck of the repo(gpgcheck=0):" Gpgcheck echo "[$Id]" >> $Path$filename$Name echo "baseurl=$Baseurl" >> $Path$filename$Name echo "enabled=$Enabled" >> $Path$filename$Name echo "gpgcheck=$Gpgcheck" >> $Path$filename$Name } read -p "insert the file name:" filename check_name $filename while [ $? -eq 3 ] do read -p "insert the file name:" filename check_name $filename done check_file_thing $filename while : do yum repolist if [ $? -eq 0 ];then echo "the repo file fixed finished " break else echo "you file repofile have something wrong!" sleep 1 vim + $Path$filename$Name fi done