generated from ojullien/bash-manageservices
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ojullien <ojullien@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
147 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters