|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright (c) 2018 Jeong Han Lee |
| 4 | +# |
| 5 | +# The program is free software: you can redistribute |
| 6 | +# it and/or modify it under the terms of the GNU General Public License |
| 7 | +# as published by the Free Software Foundation, either version 2 of the |
| 8 | +# License, or any newer version. |
| 9 | +# |
| 10 | +# This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | +# more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License along with |
| 16 | +# this program. If not, see https://www.gnu.org/licenses/gpl-2.0.txt |
| 17 | +# |
| 18 | +# Author : Jeong Han Lee |
| 19 | +# email : jeonghan.lee@gmail.com |
| 20 | +# Date : Sunday, July 29 01:06:29 CEST 2018 |
| 21 | +# version : 0.0.1 |
| 22 | + |
| 23 | + |
| 24 | +declare -gr SC_SCRIPT="$(realpath "$0")" |
| 25 | +declare -gr SC_SCRIPTNAME=${0##*/} |
| 26 | +declare -gr SC_TOP="${SC_SCRIPT%/*}" |
| 27 | + |
| 28 | +declare -gr SUDO_CMD="sudo"; |
| 29 | + |
| 30 | +DKMS_SYSTEMD=dkms.service |
| 31 | +SD_UNIT_PATH_DEBIAN=/etc/systemd/system |
| 32 | +SD_UNIT_PATH_CENTOS=/usr/lib/systemd/system |
| 33 | + |
| 34 | + |
| 35 | +function find_dist |
| 36 | +{ |
| 37 | + |
| 38 | + local dist_id dist_cn dist_rs PRETTY_NAME |
| 39 | + |
| 40 | + if [[ -f /usr/bin/lsb_release ]] ; then |
| 41 | + dist_id=$(lsb_release -is) |
| 42 | + dist_cn=$(lsb_release -cs) |
| 43 | + dist_rs=$(lsb_release -rs) |
| 44 | + echo $dist_id ${dist_cn} ${dist_rs} |
| 45 | + else |
| 46 | + eval $(cat /etc/os-release | grep -E "^(PRETTY_NAME)=") |
| 47 | + echo ${PRETTY_NAME} |
| 48 | + fi |
| 49 | + |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +function setup_dkms_systemd |
| 55 | +{ |
| 56 | + printf ">>> Setup the systemd %s in %s\n" "${DKMS_SYSTEMD}" "${SD_UNIT_PATH}" |
| 57 | + |
| 58 | + ${SUDO_CMD} install -m 644 ${SC_TOP}/${DKMS_SYSTEMD} ${SD_UNIT_PATH}/ |
| 59 | + ${SUDO_CMD} systemctl daemon-reload; |
| 60 | + ${SUDO_CMD} systemctl enable ${DKMS_SYSTEMD}; |
| 61 | + ${SUDO_CMD} systemctl start ${DKMS_SYSTEMD}; |
| 62 | + printf "\n" |
| 63 | + |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +## Determine CentOS or Debian, because systemd path is different |
| 69 | + |
| 70 | +dist=$(find_dist) |
| 71 | + |
| 72 | +case "$dist" in |
| 73 | + *Debian*) |
| 74 | + SD_UNIT_PATH=${SD_UNIT_PATH_DEBIAN} |
| 75 | + ;; |
| 76 | + *CentOS*) |
| 77 | + SD_UNIT_PATH=${SD_UNIT_PATH_CENTOS} |
| 78 | + ;; |
| 79 | + *) |
| 80 | + printf "\n"; |
| 81 | + printf "Doesn't support the detected $dist\n"; |
| 82 | + printf "Please contact jeonghan.lee@gmail.com\n"; |
| 83 | + printf "\n"; |
| 84 | + exit; |
| 85 | + ;; |
| 86 | +esac |
| 87 | + |
| 88 | +${SUDO_CMD} -v |
| 89 | + |
| 90 | +# Setup Systemd for the DKMS autoinstall |
| 91 | +# dkms.sevice will be started before ethercat.service be started. |
| 92 | +setup_dkms_systemd |
| 93 | + |
0 commit comments