Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
Signed-off-by: ojullien <ojullien@users.noreply.github.com>
  • Loading branch information
ojullien committed Jul 29, 2019
1 parent 6b344ba commit b74dfc4
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 96 deletions.
46 changes: 46 additions & 0 deletions scripts/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## -----------------------------------------------------------------------------
## Linux Scripts.
## Configuration file.
##
## @package ojullien\bash-updatesystem\scripts
## @license MIT <https://github.com/ojullien/bash-updatesystem/blob/master/LICENSE>
## -----------------------------------------------------------------------------

## -----------------------------------------------------------------------------
## Defines current date
## -----------------------------------------------------------------------------
readonly m_DATE="$(date +"%Y%m%d")_$(date +"%H%M")"

## -----------------------------------------------------------------------------
## Defines main directories
## -----------------------------------------------------------------------------

# DESTINATION
readonly m_INSTALL_DESTINATION_DIR="/opt/oju/bash"
readonly m_DIR_APP="${m_INSTALL_DESTINATION_DIR}/app" # Directory holds apps
readonly m_DIR_BIN="${m_INSTALL_DESTINATION_DIR}/bin" # Directory holds app entry point
readonly m_DIR_SYS="${m_INSTALL_DESTINATION_DIR}/sys" # Directory holds system files

# SOURCE
readonly m_INSTALL_APP_NAME="updatesystem"
readonly m_INSTALL_SOURCE_APP_DIR="$(realpath "${m_DIR_REALPATH}/../src/app/${m_INSTALL_APP_NAME}")"
readonly m_INSTALL_SOURCE_BIN_FILE="$(realpath "${m_DIR_REALPATH}/../src/bin/${m_INSTALL_APP_NAME}.sh")"

## -----------------------------------------------------------------------------
## Defines main files
## Log file cannot be in /var/log 'cause few apps clean this directory
## -----------------------------------------------------------------------------
readonly m_LOGDIR="$(realpath "${m_DIR_REALPATH}/../src/log")"
readonly m_LOGFILE="${m_LOGDIR}/${m_DATE}_$(basename "$0").log"

## -----------------------------------------------------------------------------
## Defines colors
## -----------------------------------------------------------------------------
readonly COLORRED="$(tput -Txterm setaf 1)"
readonly COLORGREEN="$(tput -Txterm setaf 2)"
readonly COLORRESET="$(tput -Txterm sgr0)"

## -----------------------------------------------------------------------------
## Defines options
## -----------------------------------------------------------------------------
declare -i m_INSTALL_OPTION_REMOVE=0
70 changes: 70 additions & 0 deletions scripts/includes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## -----------------------------------------------------------------------------
## Linux Scripts.
## Usefull functions.
##
## @package ojullien\bash-updatesystem\scripts
## @license MIT <https://github.com/ojullien/bash-updatesystem/blob/master/LICENSE>
## -----------------------------------------------------------------------------

Install::trace() {
String::separateLine
String::notice "Main configuration"
FileSystem::checkDir "\tSource directory:\t\t${m_DIR_REALPATH}" "${m_DIR_REALPATH}"
FileSystem::checkDir "\tSystem directory:\t\t${m_DIR_SYS}" "${m_DIR_SYS}"
FileSystem::checkDir "\tDestination app directory:\t${m_DIR_APP}" "${m_DIR_APP}"
FileSystem::checkDir "\tDestination bin directory:\t${m_DIR_BIN}" "${m_DIR_BIN}"
FileSystem::checkFile "\tLog file is:\t\t\t${m_LOGFILE}" "${m_LOGFILE}"
return 0
}

Install::run() {

String::separateLine

if ((m_INSTALL_OPTION_REMOVE)); then
FileSystem::removeDirectory "${m_DIR_APP}/${m_INSTALL_APP_NAME}"
iReturn=$?
((0!=iReturn)) && return ${iReturn}
fi

FileSystem::removeDirectory "${m_DIR_BIN}/${m_INSTALL_APP_NAME}.sh"
iReturn=$?
((0!=iReturn)) && return ${iReturn}

FileSystem::copyFile "${m_INSTALL_SOURCE_APP_DIR}" "${m_DIR_APP}"
iReturn=$?
((0!=iReturn)) && return ${iReturn}
Console::waitUser

FileSystem::copyFile "${m_INSTALL_SOURCE_BIN_FILE}" "${m_DIR_BIN}"
iReturn=$?
((0!=iReturn)) && return ${iReturn}
Console::waitUser

String::notice -n "Change owner:"
chown -R root:root "${m_DIR_APP}/${m_INSTALL_APP_NAME}" "${m_DIR_BIN}/${m_INSTALL_APP_NAME}.sh"
iReturn=$?
String::checkReturnValueForTruthiness ${iReturn}
((0!=iReturn)) && return ${iReturn}
Console::waitUser

String::notice -n "Change directory access rights:"
find "${m_DIR_APP}" -type d -name "${m_INSTALL_APP_NAME}" -exec chmod u=rwx,g=rx,o=rx {} \;
iReturn=$?
String::checkReturnValueForTruthiness ${iReturn}
((0!=iReturn)) && return ${iReturn}

String::notice -n "Change files access rights:"
find "${m_DIR_APP}/${m_INSTALL_APP_NAME}" -type f -exec chmod u=rw,g=r,o=r {} \;
iReturn=$?
String::checkReturnValueForTruthiness ${iReturn}
((0!=iReturn)) && return ${iReturn}

String::notice -n "Change sh files access rights:"
chmod +x "${m_DIR_BIN}/${m_INSTALL_APP_NAME}.sh"
iReturn=$?
String::checkReturnValueForTruthiness ${iReturn}
((0!=iReturn)) && return ${iReturn}

return ${iReturn}
}
127 changes: 31 additions & 96 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Linux Scripts.
## Install the bash-updatesystem project into the /opt/oju/bash directory.
##
## @package ojullien\bash\scripts
## @package ojullien\bash-updatesystem\scripts
## @license MIT <https://github.com/ojullien/bash-updatesystem/blob/master/LICENSE>
## -----------------------------------------------------------------------------
#set -o errexit
Expand All @@ -14,54 +14,10 @@ set -o pipefail
## Current project directory, eg: /opt/Shell/scripts/
## -----------------------------------------------------------------------------
readonly m_DIR_REALPATH="$(realpath "$(dirname "$0")")"

## -----------------------------------------------------------------------------
## Defines current date
## -----------------------------------------------------------------------------
readonly m_DATE="$(date +"%Y%m%d")_$(date +"%H%M")"

## -----------------------------------------------------------------------------
## Defines main directories
## -----------------------------------------------------------------------------

# DESTINATION
readonly m_INSTALL_DESTINATION_DIR="/opt/oju/bash"
readonly m_DIR_APP="${m_INSTALL_DESTINATION_DIR}/app" # Directory holds apps
readonly m_DIR_BIN="${m_INSTALL_DESTINATION_DIR}/bin" # Directory holds app entry point
readonly m_DIR_SYS="${m_INSTALL_DESTINATION_DIR}/sys" # Directory holds system files

# SOURCE
readonly m_INSTALL_APP_NAME="updatesystem"
readonly m_INSTALL_SOURCE_APP_DIR="$(realpath "${m_DIR_REALPATH}/../src/app/${m_INSTALL_APP_NAME}")"
readonly m_INSTALL_SOURCE_BIN_FILE="$(realpath "${m_DIR_REALPATH}/../src/bin/${m_INSTALL_APP_NAME}.sh")"

## -----------------------------------------------------------------------------
## Defines main files
## Log file cannot be in /var/log 'cause few apps clean this directory
## -----------------------------------------------------------------------------
readonly m_LOGDIR="$(realpath "${m_DIR_REALPATH}/../src/log")"
readonly m_LOGFILE="${m_LOGDIR}/${m_DATE}_$(basename "$0").log"

## -----------------------------------------------------------------------------
## Defines colors
## -----------------------------------------------------------------------------
readonly COLORRED="$(tput -Txterm setaf 1)"
readonly COLORGREEN="$(tput -Txterm setaf 2)"
readonly COLORRESET="$(tput -Txterm sgr0)"

## -----------------------------------------------------------------------------
## Functions
## -----------------------------------------------------------------------------
Constant::trace() {
String::separateLine
String::notice "Main configuration"
FileSystem::checkDir "\tSource directory:\t\t${m_DIR_REALPATH}" "${m_DIR_REALPATH}"
FileSystem::checkDir "\tSystem directory:\t\t${m_DIR_SYS}" "${m_DIR_SYS}"
FileSystem::checkDir "\tDestination app directory:\t${m_DIR_APP}" "${m_DIR_APP}"
FileSystem::checkDir "\tDestination bin directory:\t${m_DIR_BIN}" "${m_DIR_BIN}"
FileSystem::checkFile "\tLog file is:\t\t\t${m_LOGFILE}" "${m_LOGFILE}"
return 0
}
# shellcheck source=/dev/null
. "${m_DIR_REALPATH}/config.sh"
# shellcheck source=/dev/null
. "${m_DIR_REALPATH}/includes.sh"

## -----------------------------------------------------------------------------
## Includes sources & configuration
Expand Down Expand Up @@ -90,12 +46,6 @@ if [[ ! -d "${m_DIR_SYS}" ]]; then
exit 1
fi

## -----------------------------------------------------------------------------
## Trace
## -----------------------------------------------------------------------------
Constant::trace
Console::waitUser

## -----------------------------------------------------------------------------
## Start
## -----------------------------------------------------------------------------
Expand All @@ -104,49 +54,34 @@ String::notice "Today is: $(date -R)"
String::notice "The PID for $(basename "$0") process is: $$"
Console::waitUser

FileSystem::removeDirectory "${m_DIR_APP}/${m_INSTALL_APP_NAME}"
iReturn=$?
((0!=iReturn)) && exit ${iReturn}

FileSystem::removeDirectory "${m_DIR_BIN}/${m_INSTALL_APP_NAME}.sh"
iReturn=$?
((0!=iReturn)) && exit ${iReturn}

FileSystem::copyFile "${m_INSTALL_SOURCE_APP_DIR}" "${m_DIR_APP}"
iReturn=$?
((0!=iReturn)) && exit ${iReturn}
Console::waitUser

FileSystem::copyFile "${m_INSTALL_SOURCE_BIN_FILE}" "${m_DIR_BIN}"
iReturn=$?
((0!=iReturn)) && exit ${iReturn}
Console::waitUser

String::notice -n "Change owner:"
chown -R root:root "${m_DIR_APP}/${m_INSTALL_APP_NAME}" "${m_DIR_BIN}/${m_INSTALL_APP_NAME}.sh"
iReturn=$?
String::checkReturnValueForTruthiness ${iReturn}
((0!=iReturn)) && exit ${iReturn}
## -----------------------------------------------------------------------------
## Parse the app options and arguments
## -----------------------------------------------------------------------------
declare -i iReturn=1

while (( "$#" )); do
case "$1" in
-t|--trace)
shift
String::separateLine
Install::trace
;;
-r|--remove)
shift
m_INSTALL_OPTION_REMOVE=1
;;
*) # unknown option
shift
String::separateLine
Option::showHelp
exit 0
;;
esac
done

Install::run ${m_INSTALL_OPTION_REMOVE}
Console::waitUser

String::notice -n "Change directory access rights:"
find "${m_DIR_APP}" -type d -name "${m_INSTALL_APP_NAME}" -exec chmod u=rwx,g=rx,o=rx {} \;
iReturn=$?
String::checkReturnValueForTruthiness ${iReturn}
((0!=iReturn)) && exit ${iReturn}

String::notice -n "Change files access rights:"
find "${m_DIR_APP}/${m_INSTALL_APP_NAME}" -type f -exec chmod u=rw,g=r,o=r {} \;
iReturn=$?
String::checkReturnValueForTruthiness ${iReturn}
((0!=iReturn)) && exit ${iReturn}

String::notice -n "Change sh files access rights:"
chmod +x "${m_DIR_BIN}/${m_INSTALL_APP_NAME}.sh"
iReturn=$?
String::checkReturnValueForTruthiness ${iReturn}
((0!=iReturn)) && return ${iReturn}

## -----------------------------------------------------------------------------
## END
## -----------------------------------------------------------------------------
Expand Down

0 comments on commit b74dfc4

Please sign in to comment.