Make vfio.sh POSIX compliant.

This commit is contained in:
the_4n0nym0u53 2022-01-03 00:39:35 +01:00
parent 0adf0d13b9
commit c9275dea37
No known key found for this signature in database
GPG key ID: 35EE09F5481049BB

View file

@ -1,28 +1,26 @@
#!/bin/sh #!/bin/sh
if (( $(id -u) != 0 )); then if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root. Quitting..." echo "This script must be run as root. Quitting..."
exit 1 exit 1
fi fi
if [ "$1" = "on" ]; then if [ "$1" = "on" ]; then
if grep "#MODULES=()" /etc/mkinitcpio.conf &> /dev/null; then if grep "#MODULES=()" /etc/mkinitcpio.conf > /dev/null; then
echo "VFIO is already enabled. Quitting..." echo "VFIO is already enabled. Quitting..."
exit 1 exit 1
fi fi
echo "Enabling VFIO..." echo "Enabling VFIO..."
sed -i 's/MODULES=()/#MODULES=()/g' /etc/mkinitcpio.conf sed -i 's/MODULES=()/#MODULES=()/g' /etc/mkinitcpio.conf
sed -i 's/#MODULES=(vfio/MODULES=(vfio/g' /etc/mkinitcpio.conf sed -i 's/#MODULES=(vfio/MODULES=(vfio/g' /etc/mkinitcpio.conf
elif [ "$1" = "off" ]; then elif [ "$1" = "off" ]; then
if grep "#MODULES=(vfio" /etc/mkinitcpio.conf &> /dev/null; then if grep "#MODULES=(vfio" /etc/mkinitcpio.conf > /dev/null; then
echo "VFIO is already disabled. Quitting..." echo "VFIO is already disabled. Quitting..."
exit 1 exit 1
fi fi
echo "Disabling VFIO..." echo "Disabling VFIO..."
sed -i 's/#MODULES=()/MODULES=()/g' /etc/mkinitcpio.conf sed -i 's/#MODULES=()/MODULES=()/g' /etc/mkinitcpio.conf
sed -i 's/MODULES=(vfio/#MODULES=(vfio/g' /etc/mkinitcpio.conf sed -i 's/MODULES=(vfio/#MODULES=(vfio/g' /etc/mkinitcpio.conf
else else
@ -31,8 +29,8 @@ else
fi fi
sleep 0.5 sleep 0.5
echo "Rebuilding initramfs..."
echo "Regenerating initramfs..."
mkinitcpio -P mkinitcpio -P
echo "Done!" echo "Done!"