Commit 9a49a8aa by iv

Nicer script, keep logs but do not show them to end user, show connection state…

Nicer script, keep logs but do not show them to end user, show connection state when running script.
parent 3590cf18
......@@ -6,6 +6,7 @@ configdir="/home/chronos/user/.re6stconf"
configfile="${configdir}/re6stnet.conf"
# shill should not care about these interfaces
blacklist_option="re6stnet-tcp,re6stnet10,re6stnet9,re6stnet8,re6stnet7,re6stnet6,re6stnet5,re6stnet4,re6stnet3,re6stnet2,re6stnet1,tun0,tun1,tun2"
logfile="/var/log/grandenet"
# Require script to be run via sudo, but not as root
if [[ $EUID != 0 ]]; then
......@@ -35,7 +36,7 @@ function configure {
if [[ -f ${configdir} ]] ; then
echo "A file called ${configdir} has been found and removed."
rm "${configdir}"
elif [[ $(ls -A "${configdir}"/* 2> /dev/null) ]] ; then
elif [[ $(ls -A "${configdir}"/* 2> /dev/null ) ]] ; then
echo "Some files are into ${configdir}. Moving them to directory ${configdir}/old"
install -d ${configdir}/old && mv "${configdir}"/* "${configdir}/old" 2> /dev/null
fi
......@@ -81,11 +82,36 @@ function configure {
"
}
# function to clean up and exit
cleanup() {
echo "
#################### Cleaning up #################################
"
printf "\nCleaning up and exiting...\n"
if [ -r "${configdir}/ip6tables.save" ] ; then
echo "Removing changes in ip6tables rules"
ip6tables-restore < "${configdir}/ip6tables.save"
rm "${configdir}/ip6tables.save"
rm "${configdir}/current_ip6tables.conf"
fi
echo "Stop allowing IPv6 forwarding..."
}
echo "After answering a few questions, you will connect to the Grandenet network, based on re6st, a resilient overlay mesh network providing IPv6."
echo "Welcome on Grandenet network. It is a resilient overlay mesh network providing IPv6."
if [[ $(pgrep re6stnet) ]] ; then
read -p "re6stnet is already running. Stop it [y/N]? " stop
iproute=$(ip -6 r | grep default )
if [[ ${iproute} == "" ]] ; then
echo -e " \e[0;33mState: Starting...\e[0m
You will soon be part of grandenet network, please, be patient and give it some time to connect!"
else
echo -e " \e[0;32mState: Connected.\e[0m You are part of grandenet network.
Your default IPv6 route is:
${iproute}"
fi
read -p "Do you want to leave grandenet network [y/N]? " stop
if [ "$stop" == "y" -o "$stop" == "Y" ] ; then
cleanup
echo "Killing re6stnet process..."
killall re6stnet
# XXX: should only kill other grandenet processes...
......@@ -96,6 +122,9 @@ if [[ $(pgrep re6stnet) ]] ; then
fi
fi
echo -e " \e[0;31mState: Not connected.\e[0m
After answering a few questions, you will be able to connect."
# there may be a configuration already installed
usefound="n"
......@@ -137,7 +166,7 @@ if [ "$usefound" == "n" -o "$usefound" == "N" ]; then
fi
fi
# copy the config if needed
# copy the config if needed
if [ "${path}" == "${configdir}" -a -r "${path}/re6stnet.conf" -a -r "${path}/cert.crt" -a -r "${path}/cert.key" -a -r "${path}/ca.crt" ]; then
echo "Using existing configuration in '${configdir}'."
elif [ ! -d "$path" ] ; then
......@@ -159,28 +188,9 @@ fi
ip6tables-save > "${configdir}/ip6tables.save"
cp "${configdir}/ip6tables.save" "${configdir}/current_ip6tables.conf"
# function to clean up and exit
cleanup() {
echo "
#################### Cleaning up #################################
"
printf "\nCleaning up and exiting...\n"
if [ -r "${configdir}/ip6tables.save" ] ; then
echo "Removing changes in ip6tables rules"
ip6tables-restore < "${configdir}/ip6tables.save"
rm "${configdir}/ip6tables.save"
rm "${configdir}/current_ip6tables.conf"
fi
echo "Stop allowing IPv6 forwarding..."
sysctl net.ipv6.conf.all.forwarding=0 > /dev/null
exit 0
}
trap cleanup SIGHUP SIGINT SIGTERM
# setup shill network manager
if [[ $( pgrep -a shill | grep ${blacklist_option} ) ]] ; then
echo "shill was started with the right blacklist."
echo "shill was started with the right blacklist." >> ${logfile}
else
read -p "The network manager shill was not started with the right blacklisted devices list. Restart it [Y/n]? " confirm
if [ "$confirm" != "n" -a "$confirm" != "N" ] ; then
......@@ -223,20 +233,17 @@ else
ip6tables -A INPUT -p tcp --dport 50005 -j ACCEPT
fi
sysctl net.ipv6.conf.all.accept_ra=1
sysctl net.ipv6.conf.all.forwarding=1
sysctl net.ipv6.conf.all.accept_ra=1 >> "${logfile}" 2>&1
sysctl net.ipv6.conf.all.forwarding=1 >> "${logfile}" 2>&1
echo "re6st will start, it may take a few minutes before beeing usable"
# wait a bit, so the user can see it and the message is not lost among re6st log
for i in {0..2} ; do
sleep 1
done
echo ""
echo "
######################### re6st logs #############################
"
For debugging purpose, logs will be stored in ${logfile}.
To stop grandenet, run 'sudo ${0##*/}' command again."
# join re6st network
cd "${configdir}"
re6stnet @re6stnet.conf
\ No newline at end of file
nohup re6stnet @re6stnet.conf >> "${logfile}" 2>&1 &
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 sign in to comment