|
#!/usr/bin/env bash |
|
|
|
|
|
|
|
EMAIL=my-email@email.com |
|
PASSWORD=my-password |
|
|
|
# Update the package lists and install necessary packages |
|
apt update \ |
|
&& apt-get install --yes --no-install-recommends \ |
|
curl \ |
|
ca-certificates |
|
|
|
# Rename the default apt sources list to avoid conflicts with Beckhoff's apt repository |
|
mv /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list.d/debian.sources.bak |
|
|
|
# Create login credentials for Beckhoff's apt repository |
|
tee /etc/apt/auth.conf.d/bhf.conf > /dev/null <<EOF |
|
machine deb.beckhoff.com login ${EMAIL} password ${PASSWORD} |
|
machine deb-mirror.beckhoff.com login ${EMAIL} password ${PASSWORD} |
|
EOF |
|
|
|
# Get the apt sources for Beckhoff's apt repository (deb822 format) |
|
tee /etc/apt/sources.list.d/debian-beckhoff.sources > /dev/null <<'EOF' |
|
Types: deb |
|
URIs: https://deb-mirror.beckhoff.com/debian |
|
Suites: trixie |
|
Components: main |
|
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg |
|
|
|
Types: deb |
|
URIs: https://deb-mirror.beckhoff.com/debian-security |
|
Suites: trixie-security |
|
Components: main |
|
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg |
|
EOF |
|
|
|
tee /etc/apt/sources.list.d/bhf.sources > /dev/null <<'EOF' |
|
Types: deb |
|
URIs: https://deb.beckhoff.com/debian |
|
Suites: trixie-stable |
|
Components: main |
|
Signed-By: /usr/share/keyrings/bhf.asc |
|
EOF |
|
|
|
# Get the GPG key for Beckhoff's apt repository |
|
curl --fail --netrc-file "/etc/apt/auth.conf.d/bhf.conf" \ |
|
-o /usr/share/keyrings/bhf.asc \ |
|
https://deb.beckhoff.com/repo.pub |
|
|
|
apt install --yes tc31-xar-um |
|
|
|
# --- TwinCAT 3 configuration --- |
|
TC3_DIR=/etc/TwinCAT/3.1 |
|
|
|
# Static routes: ADS-over-MQTT via local mosquitto broker |
|
mkdir -p "${TC3_DIR}/Target" |
|
tee "${TC3_DIR}/Target/StaticRoutes.xml" > /dev/null <<'EOF' |
|
<?xml version="1.0" encoding="utf-8"?> |
|
<TcConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
xsi:noNamespaceSchemaLocation="http://www.beckhoff.com/schemas/2015/12/TcConfig"> |
|
<RemoteConnections> |
|
<Mqtt> |
|
<Address Port="1883">mosquitto</Address> |
|
<Topic>AdsOverMqtt</Topic> |
|
</Mqtt> |
|
</RemoteConnections> |
|
</TcConfig> |
|
EOF |
|
|
|
# Startup state: set TwinCAT to boot directly into RUN mode (0x05) |
|
mkdir -p "${TC3_DIR}/Target/RegFiles" |
|
tee "${TC3_DIR}/Target/RegFiles/SysStartupState.reg" > /dev/null <<'EOF' |
|
Windows Registry Editor Version 5.00 |
|
|
|
; SysStartupState defines the TwinCAT System Service Startup State |
|
; RUN = "SysStartupState"=dword:00000005 |
|
; CONFIG = "SysStartupState"=dword:0000000f |
|
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Beckhoff\TwinCAT3\System] |
|
"SysStartupState"=dword:00000005 |
|
EOF |
|
|