slapos-re6st-setup 3.8 KB
Newer Older
1
#!/bin/bash -e 
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

SLAPOS_CFG_PATH=/etc/opt/slapos/slapos.cfg

if [ -z "$COMPUTERNAME" ]; then
  if [ -z "$1" ]; then
    echo " [ERROR] Use re6st-setup.sh COMPUTERNAME or Please export COMPUTERNAME= variable, and rerun the script, it is mandatory for re6st setup script"
    exit 1
  fi
  export COMPUTERNAME=$1
fi


function re6st_conf_repos
{
    if [ ! -f /usr/bin/re6st-conf ]; then
      if [ -f /usr/bin/zypper ]; then
        zypper addrepo http://git.erp5.org/dist/rpm/ git.erp5.org
        zypper update
        zypper install re6stnet
      else
        if [ -f /usr/bin/apt-get ]; then
23 24 25
          if [ ! -f /etc/apt/sources.list.d/git.erp5.org.list ]; then 
            gpg --keyserver subkeys.pgp.net --recv-keys 1A716324
            gpg --export 1A716324 | apt-key add -
26

27 28
            echo "deb http://git.erp5.org/dist/deb ./" > /etc/apt/sources.list.d/git.erp5.org.list
          fi
29
          apt-get update
30
          apt-get install -y re6stnet
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        else
          echo "[ERROR] Unable to install re6st package, no apt-get or zypper found"
          exit 1
        fi
      fi
    fi
}


function re6st_conf_generation
{
    if [ ! -f /etc/re6stnet/re6stnet.conf ]; then
      re6st_conf_repos
      # Generate re6st configuration
      REGISTRY="http://re6stnet.nexedi.com"
      re6st-conf -d /etc/re6stnet --registry $REGISTRY -r title $COMPUTERNAME --anonymous
      echo "File /etc/re6stnet/re6stnet.conf generated"
      echo "You now need to reboot your server manually for the changes to take\
effect"
    fi
}

function remove_VPN_conf
{
    # Remove VPN configuration
    if [ -e /etc/openvpn/vifib.conf ]; then
        mv /etc/openvpn/vifib.conf /etc/openvpn/vifib.conf.disabled`date`
        echo "Removed vifib OpenVPN configuration files"
    fi

61 62 63 64 65 66
    # Remove VPN configuration
    if [ -e /etc/openvpn/vifib.backup.conf ]; then
        mv /etc/openvpn/vifib.backup.conf /etc/openvpn/vifib.backup.conf.disabled`date`
        echo "Removed vifib OpenVPN configuration files"
    fi

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    if [ -e /etc/opt/slapos/openvpn-needed ]; then
        rm /etc/opt/slapos/openvpn-needed
        echo "Removed /etc/opt/slapos/openvpn-needed"
    fi
    echo "###################################################################################################"
    echo "WARNING: RESTART OpenVPN can cut your access out, if you are connected via tapVPN IPv6 address!!!!!"
    echo "###################################################################################################"
}

function modify_interfaces_in_SlapOS_conf
{
    # Modify slapos.cfg to use lo
    cp $SLAPOS_CFG_PATH $SLAPOS_CFG_PATH.old
    echo "Copied old slapos.cfg to $SLAPOS_CFG_PATH.old"

    sed 's/\(interface_name =\).*/\1 lo/g' $SLAPOS_CFG_PATH.old > $SLAPOS_CFG_PATH.tmp
    sed 's/.*ipv6_interface =.*//g' $SLAPOS_CFG_PATH.tmp > $SLAPOS_CFG_PATH
    rm $SLAPOS_CFG_PATH.tmp
}

#XXX Vivien: fugly logic, feel free to modify it if you can do better
#            or if install/upgrade procedure was simplified
if [ ! -e /etc/re6stnet/re6stnet.conf ]; then
    if [ -e $SLAPOS_CFG_PATH ]; then
        # In case of an upgrade test for native ipv6 inside slapos.cfg
        # Only migrates if tapVPN is used.
        if grep -qe "ipv6_interface = tapVPN" $SLAPOS_CFG_PATH && ! grep -qe "#ipv6_interface" $SLAPOS_CFG_PATH; then
            # If using vifib VPN
            remove_VPN_conf

            modify_interfaces_in_SlapOS_conf

            re6st_conf_generation
        else
            # Manual configuration by user before upgrade
            echo "You seem to have no separate interface for ipv6, please proceed \
with the configuration of re6st and SlapOS Node by yourself."
        fi
    else
        # New node
        re6st_conf_generation
    fi
else
  echo "WARNING: /etc/re6stnet/re6stnet.conf is present on your system, skip to run. Please check your existing configuration."
fi