Commit 084ae207 authored by Cédric BRINER's avatar Cédric BRINER Committed by Cédric BRINER
Browse files

wait 20s for ipv6 to come or remove, modify /etc/hosts

parent e74e3d9a
......@@ -235,12 +235,19 @@ eof
# wait ipv6
echo ""
pb "--"
pb "wait for stateless"
pb "Wait for stateless"
for ipv6_prefix in 2001 fd69; do
pb " - wait for ${ipv6_prefix}: "
has_waited="false"
echo -n " "
i=0
while ! ipadm | grep -w "addrconf" | awk '{ print $5}' | grep -v "^fe80" | grep -q "^${ipv6_prefix}" ; do
let i++
if [[ $i -gt 20 ]]; then
pr "Stateless ipv6 is not comming."
pb "Exit !"
exit 1
fi
sleep 0.1
echo -n "."
has_waited="true"
......@@ -256,26 +263,42 @@ eof
# get the ip from the
echo ""
pb "--"
pb "find the ip provided by stateless"
pb "Find the ip provided by stateless"
pb " - are we 10 or 129 ip ?"
is_129_or_10=$(ipadm | grep -w static | grep v4 | grep -v lo | awk '{ print $5}' | cut -d "." -f1)
ipv4=$(ipadm \
| grep -w static \
| grep v4 \
| grep -v lo \
| awk '{ print $5}' \
| cut -d "/" -f1)
is_129_or_10=${ipv4/%\.*/}
if [[ $is_129_or_10 = "10" ]]; then
pb " 10, then let's take a fd69 ipv6"
ipv6=$(ipadm | grep -w addrconf | grep v6 | grep -v " fe80:" | awk '{ print $5}' | grep "^fd69")
ipv6_n_prefix=$(ipadm \
| grep -w addrconf \
| grep v6 \
| grep -v " fe80:" \
| awk '{ print $5}' \
| grep "^fd69")
elif [[ $is_129_or_10 = "129" ]]; then
pb " 129, then let's take a 2001 ipv6"
ipv6=$(ipadm | grep -w addrconf | grep v6 | grep -v " fe80:" | awk '{ print $5}' | grep "^2001")
ipv6_n_prefix=$(ipadm \
| grep -w addrconf \
| grep v6 \
| grep -v " fe80:" \
| awk '{ print $5}' \
| grep "^2001")
else
pr " neither 10 or 129 ips"
pb "Exit !"
exit 1
fi
pg " - ipv6 founded : ${ipv6}"
pg " - ipv6 founded : ${ipv6_n_prefix}"
#
# disable-ndp
echo ""
pb "--"
pb "disable ndp for all"
pb "Disable ndp for all"
pb "--- start output of set_ndpd_no_all ---"
set_ndpd_no_all
pb "--- end output of set_ndpd_no_all ---"
......@@ -288,7 +311,14 @@ eof
pb " - wait for ${ipv6_prefix}: "
has_waited="false"
echo -n " "
i=0
while ipadm | grep -w "addrconf" | awk '{ print $5}' | grep -v "^fe80" | grep -q "^${ipv6_prefix}" ; do
let i++
if [[ $i -gt 20 ]]; then
pr "Stateless ipv6 is not removing."
pb "Exit !"
exit 1
fi
sleep 0.1
echo -n "."
has_waited="true"
......@@ -300,19 +330,38 @@ eof
pg "ok"
fi
done
#
# enable ipv6 static
echo ""
pb "--"
pb "Enable ipv6 static with ipv6(${ipv6})"
if ! ipadm create-addr -T static -a local="${ipv6}" net0 >& /dev/null; then
pb "Enable ipv6 static with ipv6(${ipv6_n_prefix})"
if ! ipadm create-addr -T static -a local="${ipv6_n_prefix}" net0 >& /dev/null; then
pr "Unable to create a static address"
pb "Exit !"
exit 1
fi
pg " IPv6 ENABLED !"
ipadm | grep -w static | grep -v lo | grep net | grep v6 | awk '{ print $5}' | sed "s|^| |"
#
# modify /etc/hosts
echo "------------------------------------------"
echo ""
pb "--"
pb "Add the new hostname in /etc/hosts"
official_hostname_n_aliases=$(grep -w ${ipv4} /etc/hosts | gsed -E "s|^\S+\s+||")
if [[ -z $official_hostname_n_aliases ]]; then
pr "Unable to find official hostname & aliases with:"
pr 'the cmd (grep -w ${ipv4} /etc/hosts | gsed -E "s|^\S+\s+||")'
pb "Exit !"
exit 1
fi
hosts_bkp=$($DATE "+/etc/hosts.bkp.ipv6-tools_off_to_static_%Y.%m.%d_%Hh%Mm%Ss")
ipv6=${ipv6_n_prefix/%\/*/}
mv /etc/hosts ${hosts_bkp}
grep -vw "${ipv6}" ${hosts_bkp} \
| gsed "/${ipv4}/i ${ipv6} ${official_hostname_n_aliases}" \
> /etc/hosts
pg "done"
}
function usage()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment