Commit 9a49a8aa authored by iv's avatar iv

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

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" ...@@ -6,6 +6,7 @@ configdir="/home/chronos/user/.re6stconf"
configfile="${configdir}/re6stnet.conf" configfile="${configdir}/re6stnet.conf"
# shill should not care about these interfaces # shill should not care about these interfaces
blacklist_option="re6stnet-tcp,re6stnet10,re6stnet9,re6stnet8,re6stnet7,re6stnet6,re6stnet5,re6stnet4,re6stnet3,re6stnet2,re6stnet1,tun0,tun1,tun2" 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 # Require script to be run via sudo, but not as root
if [[ $EUID != 0 ]]; then if [[ $EUID != 0 ]]; then
...@@ -35,7 +36,7 @@ function configure { ...@@ -35,7 +36,7 @@ function configure {
if [[ -f ${configdir} ]] ; then if [[ -f ${configdir} ]] ; then
echo "A file called ${configdir} has been found and removed." echo "A file called ${configdir} has been found and removed."
rm "${configdir}" 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" echo "Some files are into ${configdir}. Moving them to directory ${configdir}/old"
install -d ${configdir}/old && mv "${configdir}"/* "${configdir}/old" 2> /dev/null install -d ${configdir}/old && mv "${configdir}"/* "${configdir}/old" 2> /dev/null
fi fi
...@@ -81,11 +82,36 @@ function configure { ...@@ -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 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 if [ "$stop" == "y" -o "$stop" == "Y" ] ; then
cleanup
echo "Killing re6stnet process..." echo "Killing re6stnet process..."
killall re6stnet killall re6stnet
# XXX: should only kill other grandenet processes... # XXX: should only kill other grandenet processes...
...@@ -96,6 +122,9 @@ if [[ $(pgrep re6stnet) ]] ; then ...@@ -96,6 +122,9 @@ if [[ $(pgrep re6stnet) ]] ; then
fi fi
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 # there may be a configuration already installed
usefound="n" usefound="n"
...@@ -137,7 +166,7 @@ if [ "$usefound" == "n" -o "$usefound" == "N" ]; then ...@@ -137,7 +166,7 @@ if [ "$usefound" == "n" -o "$usefound" == "N" ]; then
fi fi
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 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}'." echo "Using existing configuration in '${configdir}'."
elif [ ! -d "$path" ] ; then elif [ ! -d "$path" ] ; then
...@@ -159,28 +188,9 @@ fi ...@@ -159,28 +188,9 @@ fi
ip6tables-save > "${configdir}/ip6tables.save" ip6tables-save > "${configdir}/ip6tables.save"
cp "${configdir}/ip6tables.save" "${configdir}/current_ip6tables.conf" 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 # setup shill network manager
if [[ $( pgrep -a shill | grep ${blacklist_option} ) ]] ; then 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 else
read -p "The network manager shill was not started with the right blacklisted devices list. Restart it [Y/n]? " confirm 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 if [ "$confirm" != "n" -a "$confirm" != "N" ] ; then
...@@ -223,20 +233,17 @@ else ...@@ -223,20 +233,17 @@ else
ip6tables -A INPUT -p tcp --dport 50005 -j ACCEPT ip6tables -A INPUT -p tcp --dport 50005 -j ACCEPT
fi fi
sysctl net.ipv6.conf.all.accept_ra=1 sysctl net.ipv6.conf.all.accept_ra=1 >> "${logfile}" 2>&1
sysctl net.ipv6.conf.all.forwarding=1 sysctl net.ipv6.conf.all.forwarding=1 >> "${logfile}" 2>&1
echo "re6st will start, it may take a few minutes before beeing usable" 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 " echo "
######################### re6st logs #############################
" For debugging purpose, logs will be stored in ${logfile}.
To stop grandenet, run 'sudo ${0##*/}' command again."
# join re6st network # join re6st network
cd "${configdir}" cd "${configdir}"
re6stnet @re6stnet.conf nohup re6stnet @re6stnet.conf >> "${logfile}" 2>&1 &
\ No newline at end of file
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