all parametters are now correctly checked
This commit is contained in:
parent
df09b3093b
commit
9948fa24a0
1 changed files with 46 additions and 1 deletions
47
set-tap.sh
47
set-tap.sh
|
@ -8,6 +8,8 @@ Usage="
|
||||||
set-tap.sh [PARAMETTER] [OPTION]
|
set-tap.sh [PARAMETTER] [OPTION]
|
||||||
|
|
||||||
set up a bridge and a tap interface. Use either doas or sudo to get the root access. Please make sure that you account have access to theses commands.
|
set up a bridge and a tap interface. Use either doas or sudo to get the root access. Please make sure that you account have access to theses commands.
|
||||||
|
This script will use either doas or sudo to access the root user and do some temporary modifications. You will be able to see some with 'ip a' command
|
||||||
|
Please do your best to not make any mistakes in the options, or else you can be obliged to reboot your computer.
|
||||||
|
|
||||||
PARAMETTER available
|
PARAMETTER available
|
||||||
-h, --help Print this help message and quit
|
-h, --help Print this help message and quit
|
||||||
|
@ -17,7 +19,7 @@ PARAMETTER available
|
||||||
OPTION available
|
OPTION available
|
||||||
--bridge-id=<bridge-id> Set the name for the new bridge interface, usually it is br0, br1, etc
|
--bridge-id=<bridge-id> Set the name for the new bridge interface, usually it is br0, br1, etc
|
||||||
--tap-id=<tap-id> Set the tap id. Usually it is tap0, tap1, tap2, etc
|
--tap-id=<tap-id> Set the tap id. Usually it is tap0, tap1, tap2, etc
|
||||||
--addr=<address> Set an external address on the bridge. The external address have to be on the same network as one of the host network interface. e.g. if eth0, wlan0, etc is on 192.168.0.2/24, you should put the address on the network 192.168.0.0/24
|
--addr=<address> Set an external address on the bridge. The external address have to be on the same network as one of the host network interface. e.g. if eth0, wlan0, etc is on 192.168.0.2/24, you should put the address on the network 192.168.0.0/24. Please not that the CIDR notation have to be use.
|
||||||
--replace=<interface> In case you want to replace the main connexion of your computer so that only the vm will be able to reach the external network, replace interface by the interface you want to replace, and make sure that the --addr is set to one of the ip on the interace. Please not that it will be possible for your host to lost all connection to the external internet with this parametter.
|
--replace=<interface> In case you want to replace the main connexion of your computer so that only the vm will be able to reach the external network, replace interface by the interface you want to replace, and make sure that the --addr is set to one of the ip on the interace. Please not that it will be possible for your host to lost all connection to the external internet with this parametter.
|
||||||
"
|
"
|
||||||
Version="1.0"
|
Version="1.0"
|
||||||
|
@ -38,7 +40,50 @@ for i in $@; do
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
# detect the options
|
||||||
|
for i in $@; do
|
||||||
|
case "${i%=*}" in
|
||||||
|
"--bridge-id")
|
||||||
|
bridge="${i#*=}"
|
||||||
|
echo "${bridge}"
|
||||||
|
;;
|
||||||
|
"--tap-id")
|
||||||
|
tap="${i#*=}"
|
||||||
|
echo "${tap}"
|
||||||
|
;;
|
||||||
|
"--addr")
|
||||||
|
address="${i#*=}"
|
||||||
|
echo "${address}"
|
||||||
|
;;
|
||||||
|
"--replace")
|
||||||
|
echo "--replace not yet supported, program stopped." >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "parametter ${i%=*} not recognised" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${bridge}" == "" ] || [ "${tap}" == "" ]
|
||||||
|
echo "Error, --bridge-id and --tap-id have to be both specified to make the tap address" >&2
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# check if sudo is installed
|
||||||
|
if which doas &> /dev/null
|
||||||
|
then
|
||||||
|
echo "doas is installed"
|
||||||
|
rooter=$(which doas)
|
||||||
|
elif which sudo &> /dev/null
|
||||||
|
then
|
||||||
|
echo "sudo is installed"
|
||||||
|
rooter=$(which sudo)
|
||||||
|
else
|
||||||
|
echo "no command to give access to root is given. Abandon" >&2
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue