summarylogtreecommitdiffstats
path: root/moxa-uport16x0-install.sh
blob: 398d27d8b95f1d21ddfd3276b78dce895678d559 (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
_pkgname='moxa-uport16x0'
_modulenames=('mxusbserial' 'mxuport')
_origmodname=('mxuport')
_servicename='moxa-uport16x0-settings'
_modulenamesr=()
for (( _idx=${#_modulenames[@]}-1 ; _idx >= 0; _idx-- )); do
  _modulenamesr+=("${_modulenames[${_idx}]}")
done
unset _idx

pre_upgrade() {
  set -u
  systemctl disable "${_servicename}.service"
  if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then
    local _modulename
    for _modulename in "${_modulenamesr[@]}"; do
      modprobe -r "${_modulename}"
    done
  fi
  set +u
}

post_upgrade() {
  set -u
  if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then
    # depmod -a # now done by pacman hook
    modprobe -r "${_origmodname}" 2> /dev/null # blacklisted on boot
    local _modulename
    for _modulename in "${_modulenames[@]}"; do
      if ! lsmod | cut -d' ' -f1 | grep -q "^${_modulename}"'$'; then
        #echo 'Reboot or load now with:'
        #echo "  sudo modprobe '${_modulename}'"
        modprobe "${_modulename}"
      fi
    done
  else
    echo 'Once installed the new driver can be loaded with'
    echo "  sudo modprobe -r ${_origmodname}$(printf '; sudo modprobe %s' "${_modulenames[@]}")"
  fi
  systemctl daemon-reload
  systemctl enable "${_servicename}.service"
  set +u
}

post_install() {
  set -u
  post_upgrade
  # Doesn't do any good to start it. After install there's nothing in it.
  # systemctl start "${_servicename}.service"
  set +u
}

pre_remove() {
  set -u
  if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then
    local _modulename
    for _modulename in "${_modulenamesr[@]}"; do
      modprobe -r "${_modulename}"
    done
  fi
  systemctl disable "${_servicename}.service"
  if [ -d "/usr/src/${_pkgname}"-*/ ]; then
    # dkms remove runs before this so we could run these automatically but that might interrupt services
    echo 'Once removed the old driver can be loaded with'
    echo "  $(printf 'sudo modprobe -r %s; ' "${_modulenamesr[@]}")sudo modprobe ${_origmodname}"
  fi
  set +u
}

post_remove() {
  set -u
  systemctl daemon-reload
  if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then
    # depmod -a
    modprobe "${_origmodname}"
  fi
  set +u
}