summarylogtreecommitdiffstats
path: root/mesh-agent.install
blob: ed60fa7a31122c2737c49a31d13bc7e5fbf96ba4 (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
mesh-agent_reload_if_enabled() {
    systemctl is-enabled mesh-agent.service &> /dev/null
    if [ $? -eq 0 ]; then
        echo 'Service mesh-agent is enabled - reloading'
        systemctl daemon-reload
        systemctl restart mesh-agent.service
    else
        echo 'Service mesh-agent is not enabled -  do nothing...'
    fi
}

copy_var_from_msh() {
    FROM=$1
    TO=$2
    VARNAME=$3

    VAR=$(cat ${FROM} | tr -d '\r' | grep -E "${VARNAME}=.+" )
    if [ ! -z ${VAR} ]
    then
        echo "Copying \"${VAR}\" from ${FROM} to ${TO}"
        ESCAPED_REPLACE=$(printf '%s\n' "${VAR}" | sed -e 's/[\/&]/\\&/g')
        sed -Ei "s/${VARNAME}=.+/${ESCAPED_REPLACE}/" "${TO}"
    fi
}

## arg 1:  the new package version
#pre_install() {
	# do something here
#}

## arg 1:  the new package version
post_install() {
	mesh-agent_reload_if_enabled
	if [ -e /etc/meshagent.msh.pacsave ]
	then
	    copy_var_from_msh /etc/meshagent.msh.pacsave /etc/meshagent.msh MeshName
        copy_var_from_msh /etc/meshagent.msh.pacsave /etc/meshagent.msh MeshID
        copy_var_from_msh /etc/meshagent.msh.pacsave /etc/meshagent.msh ServerID
        copy_var_from_msh /etc/meshagent.msh.pacsave /etc/meshagent.msh MeshServer
	fi
	echo "mesh-agent.service not yet enabled. Remember to edit /etc/meshagent.sh and enable mesh-agent.service"
}

## arg 1:  the new package version
## arg 2:  the old package version
#pre_upgrade() {
	# do something here
#}

## arg 1:  the new package version
## arg 2:  the old package version
post_upgrade() {
	mesh-agent_reload_if_enabled

	# TODO: Handle changes to dist /etc/meshagent.msh causing   /etc/meshagent.msh.pacnew to be created.

    systemctl is-enabled mesh-agent.service &> /dev/null
    if [ ! $? -eq 0 ]; then
        echo "mesh-agent.service not yet enabled. Remember to edit /etc/meshagent.sh and enable mesh-agent.service"
    fi
}

## arg 1:  the old package version
pre_remove() {
	    echo 'Disabling mesh-agent service...'
        systemctl is-enabled mesh-agent.service &> /dev/null
        if [ $? -eq 0 ]; then
            systemctl stop mesh-agent.service &> /dev/null
            systemctl disable mesh-agent.service &> /dev/null
        fi
        systemctl daemon-reload
}

## arg 1:  the old package version
#post_remove() {
	# do something here
#}