Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
Create the local YUM source configuration file
Yum, which stands for “Yellow Dog Updater, Modified”, is a software package manager that exists specifically to resolve package dependencies. This section describes how to set up the local YUM source, which can be used to manage local packages after centos is installed on a VM.
The procedure for setting up a local YUM source is as follows
- Specify the mount point of the CD-ROM by specifying parameters
- Create a mount point if it does not exist
- Back up other configuration files in /etc/yum.repos.d/
- Finally, a message is displayed indicating that the creation succeeds
#! /bin/bash
#Build local YUM
#Mount the CD to /mount_dir(automatically created)
#D /*.repo to the./bak/ directory
#Set up the environment
#Yum is ok, correct and error messages are redirected to /dev/null(no redundant information is output)
#mount /dev/sr0 /mount_dir || mkdir /mount_dir && mount /dev/sr0 /mount_dir
#Mount the CD-ROM to /mount_dirMount_device =$1 mount_dir=$1 read -p "Please enter the system device and mount path you want to mount: " mount_device mount_dir mount ${mount_device} ${mount_dir} > /dev/null 2>&1 || mkdir -p ${mount_dir} && mount ${mount_device} ${mount_dir} > /dev/null 2>&1
#The service side
#1. Create a warehouse
#yum_source=$3${yum_source} mkdir -p ${yum_source} > /dev/null 2>&1 echo ${yum_source}#2. Copy the RPM package to the repository
find ${mount_dir} -name "*.rpm" | xargs -I {} cp {} ${yum_source} > /dev/null 2>&1
#3. Update the warehouse configuration file
#rpm -q createrepo > /dev/null 2>&1 || createrepo_name=$(ls ${yum_source} | grep "createrepo") && rpm -i ${createrepo_name} && rpm -q createrepo > /dev/null 2>&1
#createrepo ${yum_source}
createrepo ${yum_source}
echo ${yum_source}
#The client
#The configuration file
#1. Back up the source configuration file to a directoryBak_dir =$4 read -p "Please enter the directory where you want to back up the source configuration file: " ${bak_dir} echo ${bak_dir} mv /etc/yum.repos.d/*.repo ${bak_dir} > /dev/null 2>&1 || mkdir -p ${bak_dir} > /dev/null 2>&1 && cp /etc/yum.repos.d/*.repo ${bak_dir} > /dev/null 2>&1
#Creating a Configuration File
touch /etc/yum.repos.d/new_yum.repo
cat << end > /etc/yum.repos.d/new_yum.repo
[new_yum]
name=new_yum
baseurl=file:///yum_source
enabled=1
gpgcheck=0
end
echo "yum is ok!"
Copy the code