grdn-cfg 2.12 KB
#!/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 "
*filter
: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
COMMIT
" > "${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."