Closed dashohoxha closed 6 years ago
based on above comment and testing plan
These are the changes that I plan on making in test.sh
first I set DEVICE=ltsp-test-if
then this these changes
case $1 in
start )
echo "creating virtual interface.."
modprobe dummy
ip link add ${DEVICE} type dummy
ip link set ${DEVICE} up
ip addr add ${NETWORK}.100/24 brd + dev ${DEVICE}
sed -i settings.sh -e "/^LAN_IF/ c LAN_IF=\"${DEVICE}\""
echo "destroying already present ltsp-server.."
vagrant destroy -f
(cd dhcp/ && vagrant destroy -f)
if [ ${STANDALONE,,} != "yes" ] ; then
echo "starting dhcp server.."
(cd dhcp/ && vagrant up)
fi
echo "starting ltsp-server and ltsp-client"
vagrant up && ./client.sh
;;
stop )
echo "destroying virtual interface.."
ip addr del ${NETWORK}.100/24 brd + dev ${DEVICE}
ip link delete ${DEVICE} type dummy
sed -i settings.sh -e '/^LAN_IF/ c LAN_IF="" '
rmmod dummy
echo "destroying ltsp-client"
VBoxManage controlvm ltsp-client poweroff 2>/dev/null
VBoxManage unregistervm ltsp-client --delete 2>/dev/null
echo "halt and destroying ltsp-server and dhcp-server"
vagrant halt
vagrant destroy -f
(cd dhcp/ vagrant halt && vagrant destroy -f)
;;
* )
echo "error: invalid arguments provided"
help
;;
esac
vagrant destroy -f
-f flag is used so that it does not prompt yes or no
(cd dhcp/ && vagrant destroy -f)
brackets are used so that the directory is not changed
You can also keep DEVICE=ltsptest01
.
You can set the option -x
on #/bin/bash -x
and then eliminate all those echo
lines.
(cd dhcp/ && vagrant destroy -f) brackets are used so that the directory is not changed\
You can also do:
cd dhcp/
vagrant destroy -f
cd -
sure we can do that. I thought of using (cd dhcp/ && vagrant destroy -f)
because it is a one liner
cd dhcp/ vagrant destroy -f cd -
we can do this as well. It looks cleaner. will push the changes after one final test.
Testing suggests we should remove this root check block
if [[ $UID != 0 ]]; then
echo "error: use sudo or run script as root user"
exit 1
fi
Since root is not a regular user in ubuntu. Meaning I can not log in from root. So it does not make sense to create vagrant boxes with root user. If we do it with root user they will then we wont be able to control them with normal user. this video showes the problem - https://youtu.be/GSpfOm4OfRo 2:06
will be using sudo whever required and vagrant box related commands will be executed with normal user.
This happened because you're running vagrant up
with root hence the permission issues. You can run vagrant command with non-root user, with su <non-root user> -c command
You can also check linked-clones
option to speed up vagrant testing.
https://www.vagrantup.com/docs/virtualbox/configuration.html#linked-clones
You can run vagrant command with non-root user, with
su <non-root user> -c command
If we do this way then we would have to add su <non-root user> -c command
to 14 lines. Also extra line to get non-root user
from machine.
However if we do it with sudo
we will have to add sudo
to just 7 lines. Using sudo
is less number of characters. Making code more efficient. It is also familiar which increases readability of our code.
So it makes sense to use sudo
:)
The function of
test.sh
is not just to create and destroy a virtual interface. It should also start and stop the ltsp-server, the dhcp-server and the ltsp-client.