Making run Files from Local Sources

Keywords: Operation & Maintenance yum Docker Linux network

1. Use yum to download the necessary packages in a directory:

yum install --downloaddir ./ --downloadonly nvidia-detect

2. Making script files:

The script file needs unix format (only 0A line breaks, no 0D carriage return) and cannot be in window format.The last must be the end of 0A."Must be"######## End install.sh"before the end of 0A to identify the beginning of the tar.gz file."If the tar cannot be unpacked, it is generally not positioned accurately at the end and may be one line apart.

#!/bin/bash  

# Processing command: tar-zcvf. /local_euler_repo.tar.gz. /local_euler_repo
# Post-processing command: cat install.sh local_euler_repo.tar.gz > ai_env_install_euleros2.0sp5_gui_x86_64.run

#Unpack the tar.gz file
echo "$(date '+%Y-%m-%d %H:%M:%S') Extract files to temporary directory"
# Used to locate the starting location of the tar.gz file
lineCount=$(grep -a -n -E "^###### End install.sh" $0|awk -F: '{print $1 + 1}')
tail -n +$lineCount $0 > /tmp/local_euler_repo.tar.gz
tar zxvf /tmp/local_euler_repo.tar.gz -C /tmp

# Create Local Library
echo "$(date '+%Y-%m-%d %H:%M:%S') Create local software repo"
cat > /etc/yum.repos.d/EulerOS-Local.repo <<EOF
[Local-EulerOS-AI]
name=Local EulerOS-2.0SP5 AI - \$basearch
baseurl=file:///tmp/local_euler_repo
enabled=1
gpgcheck=0
priority=1
EOF

# install
echo "$(date '+%Y-%m-%d %H:%M:%S') Installation related tools"
yum clean all
yum makecache
yum update -y
yum erase -y systemtap-runtime
yum install -y make gcc kernel-devel

rm -fr /etc/yum.repos.d/EulerOS-Local.repo
rm -fr /tmp/local_euler_repo×
exit 0
# Used to locate the starting location of the tar.gz file
###### End install.sh

3. Generate compression packages:

tar -zcvf ./local_euler_repo.tar.gz ./local_euler_repo

4. Generate run files:

cat install.sh local_euler_repo.tar.gz > ai_env_install_euleros2.0sp5_gui_x86_64.run

5. Complete script:

#!/bin/bash  

# file_name: install.sh
# Processing command: tar-zcvf. /local_euler_repo.tar.gz. /local_euler_repo
# Post-processing command: cat install.sh local_euler_repo.tar.gz > ai_env_install_euleros2.0sp5_gui_x86_64.run

 echo "$(date '+%Y-%m-%d %H:%M:%S') AI environment install....."
# Must be run with root user
if [ "$(whoami)" != "root" ]; then
    echo "Please use root to execute!!!"
	exit 0
fi

#repo exists to determine whether a restart is required
repos_file_is_exist=$(ls /etc/yum.repos.d/EulerOS-Local.repo 2>/dev/null|wc -l)
#Unpack the tar.gz file
echo "$(date '+%Y-%m-%d %H:%M:%S') Extract files to temporary directory"
lineCount=$(grep -a -n -E "^###### End install.sh" $0|awk -F: '{print $1 + 1}')
tail -n +$lineCount $0 > /tmp/local_euler_repo.tar.gz
tar zxvf /tmp/local_euler_repo.tar.gz -C /tmp

# Create Local Library
echo "$(date '+%Y-%m-%d %H:%M:%S') Create local software repo"
cat > /etc/yum.repos.d/EulerOS-Local.repo <<EOF
[Local-EulerOS-AI]
name=Local EulerOS-2.0SP5 AI - \$basearch
baseurl=file:///tmp/local_euler_repo
enabled=1
gpgcheck=0
priority=1
EOF

# install
echo "$(date '+%Y-%m-%d %H:%M:%S') Installation related tools"
yum clean all
yum makecache
yum update -y
yum erase -y systemtap-runtime
yum install -y make gcc kernel-devel

# Disable nouveau
if [ "$(ls /boot/initramfs-*nouveau.img 2>/dev/bull|wc -l)" == "0" ]; then
    echo "$(date '+%Y-%m-%d %H:%M:%S') Disable nouveau"
    sed -i '/GRUB_CMDLINE/ s/auto/auto rd.driver.blacklist=nouveau nouveau.modeset=0/g' /etc/default/grub
	grub2-mkconfig -o /boot/grub2/grub.cfg #Build Configuration
	echo -e "blacklist nouveau\noptions nouveau modeset=0" >> /etc/modprobe.d/blacklist.conf
	mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
	dracut /boot/initramfs-$(uname -r).img $(uname -r)   #Update the configuration and restart
else
    echo "$(date '+%Y-%m-%d %H:%M:%S') Nouveau is disabled"
fi

# reboot system now
if [ $repos_file_is_exist == "0" ]; then
    echo "$(date '+%Y-%m-%d %H:%M:%S') Reboot system"
    echo "The system restarts 10 seconds later !!!"
    echo "*****After the restarts, please run the file again !!!"
	sleep 10
	# Enter character mode
    systemctl disable gdm.service
    reboot
fi 

#Confirm disable after power on
if [ "$(lsmod | grep nouveau | grep -v grep | wc -l)" == "0" ]; then
    echo "Nouveau is disabled"
else
    echo "Nouveau disable failed, please check manually. Yes to continue, otherwise exit the installation:[N]"
	read your_input
	sleep 1
	if [ $your_input != "yes" -a $your_input != "Yes" -a $your_input != "Y"  -a $your_input != "y"]; then
        rm -fr /etc/yum.repos.d/EulerOS-Local.repo
        rm -fr /tmp/local_euler_repo×
		echo exit 0
	fi
fi

# Install docker
echo "$(date '+%Y-%m-%d %H:%M:%S') Install docker"
chattr -i /etc/gshadow
chattr -i /etc/shadow
chattr -i /etc/group
chattr -i /etc/passwd
groupadd docker
chattr -i /etc/gshadow
chattr -i /etc/shadow
chattr -i /etc/group
chattr -i /etc/passwd
yum install -y docker-ce
yum install -y nvidia-docker2
systemctl enable docker

# Set up a network
sed -i "s/net.ipv4.ip_forward=0/net.ipv4.ip_forward=1/g" /etc/sysctl.conf
systemctl restart network
sed -i 's/^MACs/#MACs/g' /etc/ssh/sshd_config
systemctl restart sshd

# Install graphics card driver
yum install -y nvidia-detect
echo "$(date '+%Y-%m-%d %H:%M:%S') Install nvidia driver"
echo "Select the type of Graphics:"
echo "    1. NVIDIA RTX 2080 Ti"
echo "    2. NVIDIA Tesla P4"
echo "    3. Installer driver by IEF"
echo "    4. other"
echo "    q. quit"
echo "Please your choice[1|2|3|q]:"
read your_input
sleep 1
if [ "$your_input" == "1" ]; then
	echo "$(date '+%Y-%m-%d %H:%M:%S') Install RTX 2080 Ti Driver...."
	chmod a+x /tmp/local_euler_repo/nvidia_drivers/NVIDIA-Linux-x86_64-440.44.run
	sh /tmp/local_euler_repo/nvidia_drivers/NVIDIA-Linux-x86_64-440.44.run --no-opengl-files --no-install-compat32-libs
fi

if [ "$your_input" == "2" ]; then
	echo "$(date '+%Y-%m-%d %H:%M:%S') Install Tesla P4 Driver...."
	chmod a+x /tmp/local_euler_repo/nvidia_drivers/NVIDIA-Linux-x86_64-410.129-diagnostic.run
	sh /tmp/local_euler_repo/nvidia_drivers/NVIDIA-Linux-x86_64-410.129-diagnostic.run --no-opengl-files --no-install-compat32-libs
fi

if [ "$your_input" == "3" ]; then
	echo "Please install the graphics driver manually!!!"
fi

if [ "$your_input" == "4" ]; then
	echo "Please install the graphics driver manually!!!"
fi

if [ "$your_input" == "q" ]; then
	echo "Don't install the graphics driver!"
fi

# Open Graphics Mode
systemctl enable gdm.service


# Clear
echo "$(date '+%Y-%m-%d %H:%M:%S') Clean temporary files"
rm -fr /etc/yum.repos.d/EulerOS-Local.repo
rm -fr /tmp/local_euler_repo×
# restart
echo "Install AI environment successfully, system will restart!!!"
echo "The system restarts 10 seconds later !!!"
sleep 10
reboot

exit 0
###### End install.sh

Posted by sangamon on Mon, 06 Jan 2020 18:09:06 -0800