Commit 102f5c7b authored by iv's avatar iv

re6st: merge the grdn-cfg and grdn-run in a single script grandenet.

parent a6678438
...@@ -4,10 +4,72 @@ ...@@ -4,10 +4,72 @@
mountpoint="/media/removable" mountpoint="/media/removable"
configdir="/home/chronos/user/.re6stconf" configdir="/home/chronos/user/.re6stconf"
configfile="${configdir}/re6stnet.conf" configfile="${configdir}/re6stnet.conf"
# shill should not care about these devices # 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"
echo "After having run this script, you will connect to the Grandenet network, based on re6st, a resilient overlay mesh network providing IPv6."
function configure {
configoptions=()
echo "You are going to generate all the files needed to be able to join the Grandenet network, based on re6st: a resilient overlay mesh network providing IPv6 over IPv4."
read -p "token (you can get one on http://www.grandenet.cn): " token
if [ "${token}" == "" ] ; then
echo "No token given. Exiting."
exit 1
fi
read -p "registry [http://re6stnet.grandenet.cn]: " registry
if [ "${registry}" == "" ] ; then
registry="http://re6stnet.grandenet.cn"
fi
read -p "set re6st route as default [Y/n]? " default
if [ "${default}" != "n" -a "${default}" != "N" ] ; then
configoptions+=('default')
fi
re6st-conf --registry "${registry}" --token "${token}" --dir "${configdir}"
printf '%s\n' "${configoptions[@]}" >> "${configfile}"
echo "
:FORWARD ACCEPT [0:0]
:OUTPUT DROP [0:0]
-A INPUT -p udp -m udp --dport 6696 -j ACCEPT
-A INPUT -p udp -m udp --dport 326 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 9684 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 50005 -j ACCEPT
-A OUTPUT -p udp -m udp --dport 6696 -j ACCEPT
-A OUTPUT -p udp -m udp --dport 326 -j ACCEPT
" > "${configdir}/ip6tables.conf"
read -p "save configuration on an external device [Y/n]? " save
if [ "$save" != "n" -a "$save" != "N" ] ; then
save=1
if [[ $(ls -d "${mountpoint}"/*) ]]; then
echo "Detected external partitions:"
for mnt in "${mountpoint}"/* ; do
echo " * $mnt"
done
else
echo "no external device partition mounted on ${mountpoint}"
fi
read -e -p "Where the configuration directory should be saved (use tabulation for autocompletion): " place
place+="/re6stconf"
echo "configuration will be saved in $place"
install -d "${place}"
for file in "${configdir}"/* ; do
install "${file}" "${place}"
done
else
echo "Configuration will be placed in ${configfile}, please do a manual backup later or you could lose your access to this network."
fi
}
echo "After answering a few questions, you will connect to the Grandenet network, based on re6st, 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 read -p "re6stnet is already running. Stop it [y/N] ?" stop
if [ "$stop" == "y" -o "$stop" == "Y" ] ; then if [ "$stop" == "y" -o "$stop" == "Y" ] ; then
...@@ -19,51 +81,67 @@ if [[ $(pgrep re6stnet) ]] ; then ...@@ -19,51 +81,67 @@ if [[ $(pgrep re6stnet) ]] ; then
fi fi
fi fi
# get configuration # there may be a configuration already installed
usefound="n"
path=""
if [ -r "${configfile}" -a -r "${configdir}/cert.crt" -a -r "${configdir}/cert.key" -a -r "${configdir}/ca.crt" ]; then if [ -r "${configfile}" -a -r "${configdir}/cert.crt" -a -r "${configdir}/cert.key" -a -r "${configdir}/ca.crt" ]; then
echo "configuration was found in ${configdir}" read -p "Configuration was found in '${configdir}'. Use it: [Y/n]? (answering n will delete the previous config) " usefound
else if [ "$usefound" != "n" -a "$usefound" != "N" ]; then
echo "no configuration was found in ${configdir}, looking for it elsewhere..." path=${configdir}
path="" else
if [[ $(find "${mountpoint}" -type d | grep re6stconf) ]] ; then rm -R "${configdir}"
tempath=$(find "${mountpoint}" -type d | grep -m 1 re6stconf)
read -p "Use configuration directory found at: ${tempath} [Y/n]? " confirm
if [ "${confirm}" == "y" -o "${confirm}" == "Y" -o "${confirm}" == "" ] ; then
path=$tempath
fi fi
fi
# try to find a saved configuration
if [ ! -r "${configfile}" ] ; then
echo "Looking for configuration directory on external devices..."
if [[ $(find "${mountpoint}" -type d | grep re6stconf) ]] ; then
path=$(find "${mountpoint}" -type d | grep -m 1 re6stconf)
read -p "Use configuration directory found at: ${path} [Y/n]? " usefound
else else
echo "no configuration directory was found" echo "No configuration directory was found."
fi fi
fi
install -d "${configdir}"
# don't use possibly found configuration(s)
if [ "$usefound" == "n" -o "$usefound" == "N" ]; then
read -p "Manually give the path (p) or generate new (n) configuration [p/N]? " action
if [ "${action}" == "P" -o "${action}" == "p" ] ; then
read -e -p "Please give a path to the directory containing the re6stnet configuration if you already generated one: " path
if [ "$path" == "" ] ; then if [ "$path" == "" ] ; then
read -e -p "please give a path to the directory containing the re6stnet configuration if you already generated one: " path echo "No configuration path given. Exiting."
if [ "$path" == "" ] ; then
echo "No configuration given, you can generate one using grdn-cfg command. Exiting."
exit 1 exit 1
fi fi
else
configure || ( echo "Problem occured while generating new configuration. Exiting." && exit 1 )
path=${configdir}
fi fi
if [ ! -d "$path" ] ; then fi
echo "Invalid path ${path}, you can generate a valid configuration using grdn-cfg command. Exiting."
# copy the config if needed got by previous steps
if [ ${path}=${configdir} ]; then
echo "Using configuration in place."
elif [ ! -d "$path" ] ; then
echo "Invalid path '${path}'. Exiting."
exit 1 exit 1
fi elif [ -r "${path}/re6stnet.conf" -a -r "${path}/cert.crt" -a -r "${path}/cert.key" -a -r "${path}/ca.crt" ]; then
if [ -r "${path}/re6stnet.conf" -a -r "${path}/cert.crt" -a -r "${path}/cert.key" -a -r "${path}/ca.crt" ]; then echo "Copying config to '${configdir}'."
install -d "${configdir}"
for file in "${path}"/* ; do for file in "${path}"/* ; do
install -m 600 "${file}" "${configdir}" install -m 600 "${file}" "${configdir}"
done done
else else
echo "Missing some configuration files in ${path}, you can generate a valid configuration using grdn-cfg command. Exiting." echo "Missing some configuration files in '${path}'. Exiting."
exit 1 exit 1
fi
fi fi
# setup # saving current firewall configuration
# saving firewall configuration
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"
# clean before exiting # function to clean up and exit
cleanup() { cleanup() {
printf "\nCleaning up and exiting...\n" printf "\nCleaning up and exiting...\n"
if [ -r "${configdir}/ip6tables.save" ] ; then if [ -r "${configdir}/ip6tables.save" ] ; then
......
#!/bin/bash
# interactively generate configuration for re6st on NayuOS
mountpoint="/media/removable"
configdir="/home/chronos/user/.re6stconf"
configfile="${configdir}/re6stnet.conf"
options=()
install -d "${configdir}"
echo "After having run this script, you will be able to join the Grandenet network, based on re6st, a resilient overlay mesh network providing IPv6."
read -p "token (you can get one on http://www.grandenet.cn): " token
read -p "registry [http://re6stnet.grandenet.cn]: " registry
if [ "${registry}" == "" ] ; then
registry="http://re6stnet.grandenet.cn"
fi
read -p "set re6st route as default [Y/n]? " default
if [ "${default}" == "y" -o "${default}" == "Y" -o "${default}" == "" ] ; then
options+=('default')
fi
read -p "save configuration on an external device [Y/n]? " save
if [ "$save" == "y" -o "$save" == "Y" -o "$save" == "" ] ; then
save=1
if [[ $(ls -d "${mountpoint}"/*) ]]; then
echo "Detected external partitions:"
for mnt in /media/removable/* ; do
echo " * $mnt"
done
else
echo "no external device partition mounted on /media/removable"
fi
read -e -p "Where the configuration directory should be saved (use tabulation for autocompletion): " place
place+="/re6stconf"
echo "configuration will be saved in $place"
else
save=0
echo "Configuration will be placed in ${configfile}, please do manually backup later or you could lose your access."
fi
re6st-conf --registry "${registry}" --token "${token}" --dir "${configdir}"
printf '%s\n' "${options[@]}" >> "${configfile}"
echo "
:FORWARD ACCEPT [0:0]
:OUTPUT DROP [0:0]
-A INPUT -p udp -m udp --dport 6696 -j ACCEPT
-A INPUT -p udp -m udp --dport 326 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 9684 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 50005 -j ACCEPT
-A OUTPUT -p udp -m udp --dport 6696 -j ACCEPT
-A OUTPUT -p udp -m udp --dport 326 -j ACCEPT
" > "${configdir}/ip6tables.conf"
if [ $save -a $place ] ; then
sudo install -d "${place}"
for file in "${configdir}"/* ; do
install "${file}" "${place}"
done
fi
echo "Use grdn-run command to run re6st."
...@@ -42,6 +42,6 @@ python_compile() { ...@@ -42,6 +42,6 @@ python_compile() {
} }
python_install() { python_install() {
dobin "${FILESDIR}"/grdn-cfg "${FILESDIR}"/grdn-run dobin "${FILESDIR}"/grandenet
distutils-r1_python_install distutils-r1_python_install
} }
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