summarylogtreecommitdiffstats
path: root/eea.install
blob: 196b04be702f61c3709257849aff6729d7849ff8 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
pre_install() {
  # Script to be run before package is installed / upgraded
  SYSTEMD_CAT="$(which systemd-cat 2>/dev/null || true)"
  print_error() {
    errorstr="ESET Endpoint Antivirus error: $1"
    if [ -n "$SYSTEMD_CAT" ]; then
      printf "%s" "$errorstr" | $SYSTEMD_CAT -t "eea" -p err
    else
      echo "$errorstr" 1>&2
    fi
  }

  # Check for previous product
  if [ -d "/opt/eset/esets/" ] || [ -f "/opt/eset/efs/etc/pkgid" ] || [ -f "/etc/opt/eset/esets/info/pkgid" ] || [ -f "/etc/opt/eset/esets/esets.cfg" ]; then
    print_error 'Previous ESET Security product must be uninstalled first, package won'\''t be installed.'
    exit 1
  fi
}

pre_upgrade() {
  # Script to be run before package is installed / upgraded
  SYSTEMD_CAT="$(which systemd-cat 2>/dev/null || true)"
  print_error() {
    errorstr="ESET Endpoint Antivirus error: $1"
    if [ -n "$SYSTEMD_CAT" ]; then
      printf "%s" "$errorstr" | $SYSTEMD_CAT -t "eea" -p err
    else
      echo "$errorstr" 1>&2
    fi
  }

  # Check for previous product
  if [ -d "/opt/eset/esets/" ] || [ -f "/opt/eset/efs/etc/pkgid" ] || [ -f "/etc/opt/eset/esets/info/pkgid" ] || [ -f "/etc/opt/eset/esets/esets.cfg" ]; then
    print_error 'Previous ESET Security product must be uninstalled first, package won'\''t be installed.'
    exit 1
  fi

  #################################### Upgrade ####################################
  # stop and unregister old product
  '/opt/eset/eea/lib/install_scripts/unregister_service.sh'
  # export configuration from old product to xml
  # this path must be into old product
  if [ -f '/var/opt/eset/eea/confd/settings.json' ]; then
    confd_ug='eset-eea-confd:eset-eea-daemons'
    sudo -u ${confd_ug%:*} -- '/opt/eset/eea/lib/cfg-upgrade' --export-xml '/var/opt/eset/eea/confd/exported.xml'
  fi

  # remove potential upgrade package already prepared in product, as we are upgrading first
  # because /var/opt/eset is left intact during upgrade, prepared upgrade
  # package can be present there, which would cause "pcu update when product starts" during this
  # upgrade
  rm -f '/var/opt/eset/eea/updated/app/eea.bin'
}

post_install() {
  # Script to be run after package is installed
  # import config engine configuration from old product
  import_configuration() {
    # import only if we have exported xml from old product
    if [ -f '/var/opt/eset/eea/confd/exported.xml' ]; then
      # we don't want to leave old settings.json, all information is
      # in exported xml
      rm -f '/var/opt/eset/eea/confd/settings.json'
      confd_ug='eset-eea-confd:eset-eea-daemons'
    sudo -u ${confd_ug%:*} -- '/opt/eset/eea/lib/cfg-upgrade' --import-xml '/var/opt/eset/eea/confd/exported.xml'
    rm -f '/var/opt/eset/eea/confd/exported.xml'
    fi
  }

  # check if users have been already created
  if ! grep eset-eea-daemons /etc/group >/dev/null; then
    # create users and groups
    for g in eset-eea-daemons; do
      groupadd -r $g
    done

    for ug in eset-eea-scand:eset-eea-daemons eset-eea-licensed:eset-eea-daemons eset-eea-confd:eset-eea-daemons eset-eea-logd:eset-eea-daemons eset-eea-updated:eset-eea-daemons; do
      useradd -d '/opt/eset/eea' -M -N -r -s /sbin/nologin -g "${ug#*:}" "${ug%:*}"
    done
  fi
}

post_upgrade() {
  # Script to be run after package is installed
  # import config engine configuration from old product
  import_configuration() {
    # import only if we have exported xml from old product
    if [ -f '/var/opt/eset/eea/confd/exported.xml' ]; then
      # we don't want to leave old settings.json, all information is
    # in exported xml
      rm -f '/var/opt/eset/eea/confd/settings.json'
      confd_ug='eset-eea-confd:eset-eea-daemons'
    sudo -u ${confd_ug%:*} -- '/opt/eset/eea/lib/cfg-upgrade' --import-xml '/var/opt/eset/eea/confd/exported.xml'
    rm -f '/var/opt/eset/eea/confd/exported.xml'
    fi
  }
  # check if users have been already created
  if ! grep eset-eea-daemons /etc/group >/dev/null; then
    # create users and groups
  for g in eset-eea-daemons; do
    groupadd -r $g
  done

    for ug in eset-eea-scand:eset-eea-daemons eset-eea-licensed:eset-eea-daemons eset-eea-confd:eset-eea-daemons eset-eea-logd:eset-eea-daemons eset-eea-updated:eset-eea-daemons; do
      useradd -d '/opt/eset/eea' -M -N -r -s /sbin/nologin -g "${ug#*:}" "${ug%:*}"
  done
  fi
  #################################### Upgrade ####################################
  # change directory permissions
  chgrp -R 'eset-eea-daemons' '/var/opt/eset/eea'
  chmod -R 775 '/var/opt/eset/eea'
  
  logd_ug='eset-eea-logd:eset-eea-daemons'
  chown -R ${logd_ug%:*} '/var/log/eset/eea'
  chmod -R 700 '/var/log/eset/eea'
  mkdir -p '/var/opt/eset/eea/cache/data/Logs'
  mkdir -p '/var/opt/eset/eea/cache/data/Diagnostics'
  
  chgrp -R 'eset-eea-daemons' '/var/opt/eset/eea/cache' '/var/opt/eset/eea/cache/data' '/var/opt/eset/eea/modules_notice' '/var/opt/eset/eea/dumps'
  for dir in /var/opt/eset/eea/cache /var/opt/eset/eea/cache/data; do
    chmod -R 770 "$dir"
    chmod 1770 "$dir"
  done
  chmod 1770 '/var/opt/eset/eea/cache/data/Logs'
  
  scand_ug='eset-eea-scand:eset-eea-daemons'
  chown -R ${scand_ug%:*} /var/opt/eset/eea/cache
  
  # extract modules from tar
  tar -xf /var/opt/eset/eea/lib/modules_eea.tar -C /var/opt/eset/eea/lib
  # compile modules
  /opt/eset/eea/bin/upd --compile-nups
  # set correct user to compiled modules
  updated_ug='eset-eea-updated:eset-eea-daemons'
  chown -R ${updated_ug} /var/opt/eset/eea/lib

  import_configuration

  # register and start service
  '/opt/eset/eea/lib/install_scripts/register_service.sh'

  # add current eula info into CE path AcceptedEulas
  # esmc may have already modified this by policy, in that case it is locked, so
  # ignore error here and leave esmc to manage this setting
  '/opt/eset/eea/lib/cfg' --eula-tag "EULA-BUS-STANDARD" --eula-version "2020.1" > /dev/null || true
}

pre_remove() {
  # Script to be run before package is uninstalled
  SYSTEMD_CAT="$(which systemd-cat 2>/dev/null || true)"
  print_error() {
    errorstr="ESET Endpoint Antivirus error: $1"
    if [ -n "$SYSTEMD_CAT" ]; then
      printf "%s" "$errorstr" | $SYSTEMD_CAT -t "eea" -p err
    else
      echo "$errorstr" 1>&2
    fi
  }

  # dissociate product
  if ! /opt/eset/eea/sbin/lic -d >/dev/null 2>/dev/null; then
    print_error 'License was not dissociated. Please use ESET License Administrator to dissociate license manually.'
  fi
  # stop product, unregister from systemd/init.d
  /opt/eset/eea/lib/install_scripts/unregister_service.sh

  # clean notice dir
  rm -rf /var/opt/eset/eea/modules_notice/*

  # remove devctld file with udev rules
  rm /etc/udev/rules.d/00-eset.eea.rules 2>/dev/null || true
  
  ### NOTE: All directories created by ApplicationBase::CreateAppDir() must be explicitly deleted bellow.
  
  # remove licensed folder
  rm -rf /var/opt/eset/eea/licensed

  # remove confd folder
  rm -rf /var/opt/eset/eea/confd
}

post_remove() {
  # Script to be run after package is uninstalled
  # remove users and groups
  for ug in eset-eea-scand:eset-eea-daemons eset-eea-licensed:eset-eea-daemons eset-eea-confd:eset-eea-daemons eset-eea-logd:eset-eea-daemons eset-eea-updated:eset-eea-daemons; do
    usr=${ug%:*}
    userdel $usr 2>/dev/null || true
  done
  
  for g in eset-eea-daemons; do
    groupdel $g 2>/dev/null || true
  done
  
  # clean files generated on runtime
  # there may be other our product(s) installed
  rm -rf /var/log/eset/eea
  rmdir /var/log/eset 2>/dev/null || true
  
  rm -rf /var/run/eset/eea
  rmdir /var/run/eset 2>/dev/null || true
  
  rm -rf /var/opt/eset/eea
  rmdir /var/opt/eset 2>/dev/null || true
}