Last active
June 15, 2019 14:31
-
-
Save IMelker/0f1d6c2541a3584378d8a329eb23c3c4 to your computer and use it in GitHub Desktop.
Centos7 VirtualBox Guest Additions installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ------------------------------------------------------------ | |
# Centos7 VirtualBox Guest Additions installation | |
# Update kernel headers and install requirements for it | |
# | |
# USAGE sudo prepare.sh | |
# | |
# sudo requires for installation, export KERNEL_DIR and reboot | |
# ------------------------------------------------------------ | |
## Requie run as sudo ## | |
if [[ $UID != 0 ]]; then | |
echo "Please run this script with sudo:" | |
echo "sudo $0 $*" | |
exit 1 | |
fi | |
## CentOS/RHEL 7/6/5 ## | |
yum update -y kernel* | |
## Install following packages ## | |
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm | |
yum install -y gcc kernel-devel kernel-headers dkms make bzip2 perl | |
## Add KERN_DIR environment variable ## | |
export KERN_DIR=/usr/src/kernels/$(uname -r) | |
## Mount VirtualBoxGuestAdditions ## | |
mkdir /media/VirtualBoxGuestAdditions | |
mount -r /dev/cdrom /media/VirtualBoxGuestAdditions | |
## Run installation ## | |
cd /media/VirtualBoxGuestAdditions | |
./VBoxLinuxAdditions.run | |
## Reboot after install ## | |
while true; do | |
read -p "Do you wish to reboot now(it's necessary)?" yn | |
case $yn in | |
[Yy]* ) reboot; break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment