diff options
Diffstat (limited to 'moxa-uport16x0-install.sh')
-rw-r--r-- | moxa-uport16x0-install.sh | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/moxa-uport16x0-install.sh b/moxa-uport16x0-install.sh new file mode 100644 index 000000000000..1ec6f61afc27 --- /dev/null +++ b/moxa-uport16x0-install.sh @@ -0,0 +1,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 + rmmod "${_modulename}" + done + fi + set +u +} + +post_upgrade() { + set -u + if [ ! -d "/usr/src/${_pkgname}"-*/ ]; then + depmod -a + rmmod "${_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 rmmod ${_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 + rmmod "${_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 rmmod %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 +} |