From: Andrew Sichevoi Date: Wed, 5 Sep 2012 18:19:59 +0000 (+0400) Subject: Added installation script for acpi-call module X-Git-Url: http://git.thekondor.net/?a=commitdiff_plain;h=0689a21d6d231553bedf487cbbec119c830a5884;p=scripts.git Added installation script for acpi-call module --- diff --git a/acpi-call-installer/install-acpi-call.sh b/acpi-call-installer/install-acpi-call.sh new file mode 100755 index 0000000..086b262 --- /dev/null +++ b/acpi-call-installer/install-acpi-call.sh @@ -0,0 +1,143 @@ +#!/bin/sh + +### +### This script is distributed in the terms of GNU GPL v3.0+ +### (c) Andrew Sichevoi, http://thekondor.net +### +### Name: install-acpi-call +### Description: simple installation script of ``acpi_call`` module. +### Notes: +### 1. The script is intended for Debian GNU/Linux +### 2. The script downloads the latest version of ``acpi_call`` from the home repository and +### installs the built module using DKMS. +### +### Arguments: +### none +### + +SOURCE_DIR=/usr/src +MODULE_VERSION=42 +MODULE_NAME=acpi_call + +DIST_DIR=${MODULE_NAME}-${MODULE_VERSION} +FULL_DIST_DIR_PATH=${SOURCE_DIR}/${DIST_DIR} + +REQUIRED_PACKAGES="dkms build-essential git" +SOURCE_REPOSITORY="https://github.com/peberlein/acpi_call" + +_error() +{ + echo "Error: $@" + exit 1 +} + +_check_permissions() +{ + if [ "root" != $(whoami) ]; then + _error "Must be run with root privileges" + fi +} + +__check_package_availability() +{ + /usr/bin/dpkg -s ${1} 2>/dev/null 1>&2 + return $? +} + +_check_essential_packages() +{ + missing_packages="" + + for package in ${REQUIRED_PACKAGES}; do + __check_package_availability ${package} || missing_packages="${missing_packages} ${package}" + done + + if [ ! -z "${missing_packages}" ]; then + extra_msg="Please note that some other packages must be requested during the installation" + _error "The following packages are not installed but required: ${missing_packages}\n${extra_msg}" + fi +} + +__check_directory_existence() +{ + test ! -d $1 + return $? +} + +_check_if_already_installed() +{ + __check_directory_existence ${FULL_DIST_DIR_PATH} + if [ ! 0 -eq $? ]; then + _error "The module is already installed. Directory '${FULL_DIST_DIR_PATH}' must be removed prior installation" + fi +} + +_download_sources() +{ + /usr/bin/git clone ${SOURCE_REPOSITORY} ${FULL_DIST_DIR_PATH} + if [ ! 0 -eq $? ]; then + _error "Sources could not be retrieved" + fi +} + +_create_dkms_config() +{ + ( + cat < ${FULL_DIST_DIR_PATH}/dkms.conf +} + +_register_dkms_module() +{ + dkms add -m ${MODULE_NAME} -v ${MODULE_VERSION} + if [ ! 0 -eq $? ]; then + _error "DKMS module cannot be registered" + fi +} + +_build_dkms_module() +{ + dkms build -m ${MODULE_NAME} -v ${MODULE_VERSION} + if [ ! 0 -eq $? ]; then + _error "DKMS module cannot be built" + fi +} + +_install_dkms_module() +{ + dkms install -m ${MODULE_NAME} -v ${MODULE_VERSION} + if [ ! 0 -eq $? ]; then + _error "DKMS module cannot be installed" + fi +} + + +_check_permissions +_check_if_already_installed +_check_essential_packages +_download_sources +_create_dkms_config +_register_dkms_module +_build_dkms_module +_install_dkms_module +