Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cybiohub committed Dec 14, 2021
1 parent fa687ea commit af63b53
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
| ![alt text][logo] | Integration & Securite Systeme |
| ------------- |:-------------:|

# Login Alert
This script is used to update Linux systems (Ubuntu and Debian). It is a script to launch the apt-get by generating execution logs. It allows better control for technicians who do not know Linux.
# Majserver
This script is used to update Linux systems (Ubuntu and Debian) with the apt-get command. A basic script, but which allows you to,

- Speed up the update by forcing the use of IPv4 only.
- Generate an execution log for logging.
- Allows better control for technicians unfamiliar with Linux.
- Prevents the execution of some tasks if a restart of the system is necessary.

---
[logo]: ./md/logo.png "Cybionet"
179 changes: 179 additions & 0 deletions bin/majserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#! /bin/bash
#set -x
# * **************************************************************************
# * Creation: (c) 2004-2021 Cybionet - Ugly Codes Division
# *
# * File: majserver.sh
# * Version: 0.1.12b
# *
# * Comment: Tool to configure update system.
# *
# * Date: December 16, 2017
# * Modification: November 25, 2021
# *
# * **************************************************************************
# * chmod 500 majserver.sh
# ****************************************************************************


#############################################################################################
# ## CONSTANTS

# ## Location of the log file.
readonly APTLOG='/var/log/maj-update.log'

# ## Force use of IPv4. To disable this option empty the variable.
readonly FORCEIPV4='-o Acquire::ForceIPv4=true'


#############################################################################################
# ## VARIABLES

# ## Retrieval of date and year
aptDate=$(date +%Y-%m-%d)
appYear=$(date +%Y)

# ## Application informations.
appHeader="(c) 2004-${appYear} Cybionet - Ugly Codes Division"
readonly appVersion='0.1.12b'


#############################################################################################
# ## VERIFICATION

# ## Check if the script are running under root user.
if [ "${EUID}" -ne '0' ] ; then
echo -e "\n\e[34m${appHeader}\e[0m\n"
echo -e "\n\n\n\e[33mCAUTION: This script must be run as root.\e[0m"
exit 0
else
echo -e "\n\e[34m${appHeader}\e[0m\n"
fi


#############################################################################################
# ## FUNCTIONS

# ## Show warning to remember to take snapshot.
function reminderCheck() {
echo -n -e "\e[38;5;208mWARNING:\e[0m Have you taken the snapshot of the virtual machine before updating it? [y|N] "
read ANSWER
if [ "${ANSWER}" != 'y' ]; then
echo 'Have a nice day!'
exit 0
fi
}

# ## Launch update.
function aptUpdate() {
apt-get update "${FORCEIPV4}"
echo "${aptDate} - UpDate Repository" >> "${APTLOG}"
}

# ## Launch upgrade.
function aptUpgrade() {
reminderCheck
apt-get upgrade "${FORCEIPV4}"
echo "${aptDate} - UpGrade System" >> "${APTLOG}"
}

# ## Launch dist-upgrade.
function aptDistUpgrade() {
reminderCheck
apt-get dist-upgrade "${FORCEIPV4}"
echo "${aptDate} - Distribution UpGrade" >> "${APTLOG}"
}

# ## Launch autoremove.
function autoRemove() {
if [ -f '/var/run/reboot-required' ]; then
echo -e "\e[38;5;208mWARNING: Reboot the system before removing old package.\e[0m"
exit 0
fi

echo -n -e "\n\e[38;5;208mWARNING:\e[0m Are you sure you want to do this? [y|N] "
read ANSWER
if [ "${ANSWER}" != 'y' ]; then
echo 'Have a nice day!'
exit 0
fi

apt-get autoremove
echo "${aptDate} - Autoremove Packages" >> "${APTLOG}"
}

# ## Launch autoclean.
function autoClean() {
if [ -f '/var/run/reboot-required' ]; then
echo -e "\e[38;5;208mWARNING: Reboot the system before cleaning archive packages.\e[0m"
exit 0
fi

apt-get autoclean
echo "${aptDate} - Autoclean Archive Packages" >> "${APTLOG}"
}

# ## Check if intervention is necessairy.
function aptCheck() {
apt-get check
}

# ## Show the content of the log.
function showlog() {
cat "${APTLOG}"
}

# ## Show the version of this app (hidden option).
function version() {
echo -e "Version: ${appVersion}\n"
}

# ## Check if the system requires a reboot.
# ## Result: 0 (Ok), 1 (Reboot).
function rebootNeeded() {
if [ -f '/var/run/reboot-required' ]; then
echo -e "\e[38;5;208mWARNING: A system restart is required.\e[0m"
fi
}


#############################################################################################
# ## MENU

case "${1}" in
update)
aptUpdate
;;
upgrade)
aptUpdate
aptUpgrade
rebootNeeded
;;
distupgrade|dist-upgrade)
aptDistUpgrade
rebootNeeded
;;
autoremove)
autoRemove
;;
autoclean)
autoClean
;;
check)
aptCheck
;;
showlog)
showlog
;;
version)
version
;;
*)
echo 'Options: update | upgrade | dist-upgrade | autoremove | autoclean | check | showlog'
;;
esac

# ## Exit.
exit 0

# ## END
Binary file added md/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit af63b53

Please sign in to comment.