summaryrefslogtreecommitdiffstats
path: root/get-thin-edge_io.sh
blob: 248874e9ba11631d48c241bf0bc0d5280dd85bbc (plain)
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
134
135
136
137
138
#!/bin/sh
set -e

TYPE=${2:-full}

usage() {
    cat <<EOF
USAGE:
    get-thin-edge_io [<VERSION>] [--minimal]

ARGUMENTS:
    <VERSION>     Install specific version of thin-edge.io - if not provided installs latest minor release

OPTIONS:
    --minimal   Install only basic set of components - tedge cli and tedge mappers

EOF
}

install_basic_components() {
    wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_${VERSION}_${ARCH}.deb" -P /tmp/tedge
    wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_mapper_${VERSION}_${ARCH}.deb" -P /tmp/tedge

    dpkg -i "/tmp/tedge/tedge_${VERSION}_${ARCH}.deb"
    dpkg -i "/tmp/tedge/tedge_mapper_${VERSION}_${ARCH}.deb"

}

install_tedge_agent() {
    wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_agent_${VERSION}_${ARCH}.deb" -P /tmp/tedge

    dpkg -i "/tmp/tedge/tedge_agent_${VERSION}_${ARCH}.deb"
}

install_tedge_plugins() {
    # Download and install apt plugin
    wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_apt_plugin_${VERSION}_${ARCH}.deb" -P /tmp/tedge
    dpkg -i "/tmp/tedge/tedge_apt_plugin_${VERSION}_${ARCH}.deb"

    # Download and install apama plugin
    wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_apama_plugin_${VERSION}_${ARCH}.deb" -P /tmp/tedge
    dpkg -i "/tmp/tedge/tedge_apama_plugin_${VERSION}_${ARCH}.deb"

    # Download and install configuration plugin
    wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/c8y_configuration_plugin_${VERSION}_${ARCH}.deb" -P /tmp/tedge
    dpkg -i "/tmp/tedge/c8y_configuration_plugin_${VERSION}_${ARCH}.deb"

    # Download and install c8y log plugin
    wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/c8y_log_plugin_${VERSION}_${ARCH}.deb" -P /tmp/tedge
    dpkg -i "/tmp/tedge/c8y_log_plugin_${VERSION}_${ARCH}.deb"

    # Download and install tedge_watchdog
    wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_watchdog_${VERSION}_${ARCH}.deb" -P /tmp/tedge
    dpkg -i "/tmp/tedge/tedge_watchdog_${VERSION}_${ARCH}.deb"
}

if [ $# -lt 3 ]; then
    while :; do
        case $1 in
        --minimal)
            TYPE="minimal"
            shift
            ;;
        *) break ;;
        esac
    done
else
    usage
    exit 0
fi

VERSION=$1
ARCH=$(dpkg --print-architecture)

echo "Thank you for trying thin-edge.io!"
echo

if [ -z "$VERSION" ]; then
    VERSION=0.7.4

    echo "Version argument has not been provided, installing latest: $VERSION"
    echo "To install a particular version use this script with the version as an argument."
    echo "For example: sudo ./get-thin-edge_io.sh $VERSION"
fi

if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ] || [ "$ARCH" = "armhf" ] || [ "$ARCH" = "amd64" ]; then
    # Some OSes may read architecture type as `aarch64`, `aarch64` and `arm64` are the same architectures types.
    if [ "$ARCH" = "aarch64" ]; then
        ARCH='arm64'
    fi

    # For arm64, only the versions above 0.3.0 are available.
    if [ "$ARCH" = "arm64" ] && ! dpkg --compare-versions "$VERSION" ge "0.3.0"; then
        echo "aarch64/arm64 compatible packages are only available for version 0.3.0 or above."
        exit 1
    fi

    echo "Installing for architecture $ARCH"
else
    echo "$ARCH is currently not supported. Currently supported are aarch64/arm64, armhf and amd64."
    exit 0
fi

if [ -d "/tmp/tedge" ]; then
    rm -R /tmp/tedge
fi

echo "Installing mosquitto as prerequirement for thin-edge.io"
apt install mosquitto -y

case $TYPE in
minimal) install_basic_components ;;
full)
    install_basic_components
    install_tedge_agent
    if apt -v >/dev/null 2>&1; then
        install_tedge_plugins
    fi
    ;;
*)
    echo "Unsupported argument type."
    exit 1
    ;;
esac

rm -R /tmp/tedge

# Test if tedge command is there and working
if tedge help >/dev/null;
then
    echo
    echo "thin-edge.io is now installed on your system!"
    echo ""
    echo "You can go to our documentation to find next steps: https://github.com/thin-edge/thin-edge.io/blob/main/docs/src/howto-guides/003_registration.md"
else
    echo "Something went wrong in the installation process please try the manual installation steps instead:"
    echo "https://github.com/thin-edge/thin-edge.io/blob/main/docs/src/howto-guides/002_installation.md"
fi