[r27]: / trunk / install.sh  Maximize  Restore  History

Download this file

134 lines (121 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 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
 61
 62
 63
 64
 65
 66
 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash

SUDO=""
# default versions
CDS_VERSION=4.0.0.0
EDGE_VERSION=4.0.0.0
# Overload versions, when they are passed as command line arguments
[ ! -z $1 ] && CDS_VERSION=$1
[ ! -z $2 ] && EDGE_VERSION=$2

URL="https://store.codesys.com/ftp_download/3S/LinuxSL/2302000005/${CDS_VERSION}/CODESYS%20Control%20for%20Linux%20SL%20${CDS_VERSION}.package"
EDGE_URL="https://store.codesys.com/ftp_download/3S/EdgeGatewayLinux/000120/${EDGE_VERSION}/CODESYS%20Edge%20Gateway%20for%20Linux%20${EDGE_VERSION}.package"


# check if this linux system is debian based
if ! which dpkg >/dev/zero; then 
	echo "This install script only runs on debian based distributions"
	exit 1
fi

# check if we are running as root, or we have sudoers access to dpkg
if [ "$USER" != "root" ]; then
	if ! which sudo >/dev/zero; then
		echo "You are not running as root, and don't have sudo installed."
		exit 1
	fi
	echo "You are running as non-root user. We try to get sudo access to dpkg."
	if ! sudo dpkg --version >/dev/zero; then
		echo "You have no access to dpkg. Please rerun the script as root"
		exit 1
	fi
	SUDO="sudo"
fi

# check necessary tools
if ! which wget >/dev/zero; then
	echo "We need the tool 'wget' to download the CODESYS package."
	echo "You may try:"
	echo "  apt-get install wget"
	exit 1;
fi

if ! which unzip >/dev/zero; then
	echo "We need the tool 'unzip' to unpack the CODESYS package."
	echo "You may try:"
	echo "  apt-get install unzip"
	exit 1;
fi

# check if /lib64 is available
if ! -d /lib64; then
	echo "Seems that you are not running on a traditional multi arch system."
	echo "As a workaround, you can link /lib to /lib64."
	echo "ln -s /lib /lib64"
fi

# check availability of ipv4, and try to install xinetd forwarding if not
ipv4=$(ip -4 addr list scope global)
ipv6=$(ip -6 addr list scope global)

if [ -z "${ipv4}" -a ! -z "${ipv6}" ]; then
	echo "You are running on an ipv6 only host. CODESYS doesn't support this, yet."
	echo "So we try to install an ipv6 forwarding, using xinetd."
	# check if xinetd is installed
	if [ ! -d /etc/xinetd.d ]; then
		echo "We need the tool 'xinetd' to tunnel between ipv4 and ipv6"
		echo "You may try:"
		echo "  apt-get install xinetd"
		exit 1;
	fi
	address=$(ip -6 addr list scope global dev eth0 | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)
	cat << EOF > /etc/xinetd.d/codesys-ipv6
service codesys-tcp
{
    flags           = IPv6
    disable         = no
    type            = UNLISTED
    socket_type     = stream
    protocol        = tcp
    user            = nobody
    wait            = no
    redirect        = 127.0.0.1 11740
    port            = 11740
    bind            = ${address}
}
service codesys-gw
{
    flags           = IPv6
    disable         = no
    type            = UNLISTED
    socket_type     = stream
    protocol        = tcp
    user            = nobody
    wait            = no
    redirect        = 127.0.0.1 1217
    port            = 1217
    bind            = ${address}
}
service codesys-edge
{
    flags           = IPv6
    disable         = no
    type            = UNLISTED
    socket_type     = stream
    protocol        = tcp
    user            = nobody
    wait            = no
    redirect        = 127.0.0.1 11743
    port            = 11743
    bind            = ${address}
}
EOF
	systemctl reload xinetd
fi

# start installation
if [ -z "${TRY_RUN}" ]; then
	# download and install the edge package
	[ ! -f /tmp/edge.package ] && wget --output-document=/tmp/edge.package ${EDGE_URL}
    (
	    unzip -p /tmp/edge.package '*.deb' > /tmp/edge.deb && \
        ${SUDO} dpkg -i /tmp/edge.deb
    )
	# download and install the control package
	[ ! -f /tmp/codesys.package ] && wget --output-document=/tmp/codesys.package ${URL}
	(
	    unzip -p /tmp/codesys.package '*codemeter*.deb' > /tmp/codemeter.deb && \
	    ${SUDO} dpkg -i /tmp/codemeter.deb
	    unzip -p /tmp/codesys.package '*codesyscontrol*.deb' > /tmp/codesys.deb && \
	    ${SUDO} dpkg -i /tmp/codesys.deb
	)
fi