Initial commit

This commit is contained in:
scripts 2025-09-06 08:53:35 +02:00
commit e379ecef0f
7 changed files with 345 additions and 0 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"editor.fontSize": 13,
"terminal.integrated.fontSize": 13,
"window.zoomLevel": 1.4,
}

33
LICENSE Normal file
View File

@ -0,0 +1,33 @@
Non-Commercial Use License [template.sh, install.sh]
Copyright (c) [2025] [Gilles Mouchet]
These scripts are provided free of charge with their source code. Anyone is authorized to:
- Use the scripts for personal, educational, or professional non-commercial purposes.
- Study, modify, and share the scripts free of charge, provided they retain this license.
It is strictly prohibited to:
- Sell these scripts or a modified version.
- Use them in commercial services or products.
- Distribute them in exchange for financial compensation, whether direct or indirect.
These scripts are provided "as is," without warranty of any kind.
-----------------------------------------------------------------------------------------
Licence dutilisation non commerciale [template.sh, install.sh]
Copyright (c) [2025] [Gilles Mouchet]
Ces scripts sont fournis gratuitement avec leurs codes source. Toute personne est autorisée à :
- Utiliser les scripts à des fins personnelles, éducatives ou professionnelles non commerciales.
- Étudier, modifier et partager les scripts gratuitement, à condition de conserver cette licence.
Il est strictement interdit de :
- Vendre ces scripts ou une version modifiée.
- Lutiliser dans des services ou produits commerciaux.
- Le distribuer en échange dune contrepartie financière, directe ou indirecte.
Ces scripts sont fourni "tel quel", sans garantie daucune sorte.

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# Project Name
TODO: Write a project description
## Requirements
TODO: Requirments
## Installation
TODO: Describe the installation process
## Usage
TODO: Write usage instructions
### Changelog
### [1.0.0] - 2025-09-06
#### Added
- New features and functionality.
#### Modified
- Changes to existing functionality (backwards compatible).
#### Fixed
- Bug fixes.
#### Removed
- Deprecated or removed features (breaking changes).
#### Project initialization
- initialization by [GMo](mailto:gilles.mouchet@gmail.com)

100
install.sh Executable file
View File

@ -0,0 +1,100 @@
#!/bin/bash
############################################################
# Decription: Install script
# Author: Gilles Mouchet (gilles.mouchet@gmail.com)
# Creation Date: 06-Sep-2025
# Version: 1.0
#
# Changelog:
# V1.0.0 - 06-Sep-2025 - GMo
# Added
# - Creation of script from scratch
#
############################################################
#-----------------------------------------------------------
# FUNCTIONS
#-----------------------------------------------------------
# Function installPacakege if needed
installPackage() {
packageName="$1"
echo "Installation of $packageName..."
case "$packageManager" in
apt)
sudo apt update && sudo apt install -y "$packageName"
;;
dnf)
sudo dnf install -y "$packageName"
;;
esac
if [ $? -eq 0 ]; then
echo "$packageName installed successfully"
else
echo "Error installing $packageName"
exit 1
fi
}
#-----------------------------------------------------------
# variables
fullScriptName=template.sh
shortScriptName=`echo $fullScriptName | sed -e 's|.*/||g' | cut -f1 -d.`
destPath=/usr/local/bin/
configFile=$shortScriptName.conf
configFilePath=/etc/$shortScriptName/
logRotateFile=$shortScriptName
logRotateFilePath=/etc/logrotate.d/$logRotateFile
# check if the effective user ID is 0 (root)
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root or with sudo."
exit 1
fi
# select packet manager if need to install package during install
packageManager=""
if command -v apt &> /dev/null; then
packageManager="apt"
elif command -v dnf &> /dev/null; then
packageManager="dnf"
else
echo "Erreur : No supported package managers (apt, dnf) were found."
exit 1
fi
echo "Package manager detected: $packageManager"
# check if logPath exist
if [ ! -d $configFilePath ]; then
mkdir $configFilePath &> /dev/null
rc=$?
if [ "$rc" != "0" ];then
echo "[ERROR] - An error occurred while creating $configFilePath ($rc)"
else echo "[SUCCESS] - The folder $configFilePath was created successfully."
fi
fi
# install package (example)
installPackage mutt &> /dev/null
# install script
cp $fullScriptName $destPath/. &> /dev/null
rc=$?
if [ "$rc" != "0" ];then
echo "[ERROR] - An error occurred while copying $fullScriptName to $destPath ($rc)"
else echo "[SUCCESS] - The script ${fullScriptName} to $destPath was copied successfully."
fi
# copy config file
cp $configFile $configFilePath &> /dev/null
rc=$?
if [ "$rc" != "0" ];then
echo "[ERROR] - An error occurred while copying $configFile to $configFilePath ($rc)"
else echo "[SUCCESS] - The script $configFile to $configFilepath was copied successfully."
fi
cp $logRotateFile.logrotate $logRotateFilePath &> /dev/null
rc=$?
if [ "$rc" != "0" ];then
echo "[ERROR] - An error occurred while copying $logRotateFile.logrotate to $logRotateFilePath ($rc)"
else echo "[SUCCESS] - The script $logRotateFile.logrotate to $logRotateFilePath was copied successfully."
fi
echo "Installation completed."

3
template.conf Normal file
View File

@ -0,0 +1,3 @@
# mail recipient
msgRecipient=exploit.gmotech@gmail.com

8
template.logrotate Normal file
View File

@ -0,0 +1,8 @@
/var/log/template/template.log {
daily
rotate 7
compress
missingok
notifempty
create 644 root root
}

175
template.sh Executable file
View File

@ -0,0 +1,175 @@
#!/bin/bash
############################################################
# Decription: Template script
# Author: Gilles Mouchet (gilles.mouchet@gmail.com)
# Creation Date: 06-Sep-2025
# Version: 1.0.0
#
# Changelog:
# V1.0.0 - 25-Sep-2025 - GMo
# Added
# - Creation of script from scratch
#
############################################################
#-----------------------------------------------------------------
# DON'T CHANGE ANYTHING FROM HERE
#-----------------------------------------------------------------
version="1.0.0"
mailSubject="[SUCCESS] - script result on `hostname`"
mailHeader="my_hdr From: GMO Check System <exploit.gmotech@gmail.com>"
mailBody=""
mailFooter="\n\nTemplate script $version by Exploit GMoTech"
tmpFile=/tmp/list.txt
#-----------------------------------------------------------
# FUNCTIONS
#-----------------------------------------------------------
function usage() {
cat << EOF
Usage: ./$(basename "$0") options
Template script
Options:
-p, --param - display parameters
-h, --help - display this help
-v, --version - display script version
EOF
}
#-----------------------------------------------------------
function sendMail() {
if [ -f "$tmpFile" ];then
echo -e "$mailBody $mailFooter" | mutt -e "$mailHeader" -s "${mailSubject}" $msgRecipient -a $tmpFile
else
echo -e "$mailBody $mailFooter" | mutt -e "$mailHeader" -s "${mailSubject}" $msgRecipient
fi
}
#-----------------------------------------------------------
# Function write log in file log
# parameter
# $1 define entry type (info, warning, error)
# $2 define text
# $3 define display on screen or not (nothing=no, 1=yes)
function log() {
if [ -z "$3" ]; then
displayScreen=0
else displayScreen=1
fi
case "$1" in
I)
logType="[info]"
;;
W)
logType="[warning]"
;;
E)
logType="[error]"
;;
esac
# on screen and logfile
#echo "$(date "+%Y-%m-%d")-$(date "+%H:%M:%S") - $logType - $2" | tee -a "$logFile"
#echo "[$(date "+%Y-%m-%d")-$(date "+%H:%M:%S")] - $logType - $2" >> "$logFile"
# true to display screen to
if [ "${displayScreen}" -eq 1 ];then
echo "[$(date "+%Y-%m-%d")-$(date "+%H:%M:%S")] - $logType - $2" | tee -a "$logFile"
else
echo "[$(date "+%Y-%m-%d")-$(date "+%H:%M:%S")] - $logType - $2" >> "$logFile"
fi
}
#-----------------------------------------------------------
# MAIN
#-----------------------------------------------------------
# check if the effective user ID is 0 (root)
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root or with sudo."
exit 1
fi
# config
progName=`echo $0 | sed -e 's|.*/||g' | cut -f1 -d.`
confDir=/etc/$progName
cfgFile=$confDir/$progName.conf
logPath=/var/log/$progName
logFile=$logPath/$progName.log
# check if conf file or passphrase file exist
if [ ! -f $cfgFile ]; then
echo "$progName not installed correctly. Please run install.sh script"
exit 1
fi
# read config file
. $cfgFile
log I "script start" 1
# check if logPath exist
if [ ! -d $logPath ]; then
mkdir $logPath
fi
# check param exist. Uncomment if your script need parameters
#if [ -z "$1" ]; then
# usage
# exit
#fi
while [[ "$#" -gt 0 ]]; do
case "$1" in
-p|--param)
cat << EOF
-------------------------------------------------------------------------------
Parameters
-------------------------------------------------------------------------------
Defined in script
-------------------------------------------------------------------------------
script name: $progName
config folder: $confDir
config file: $cfgFile
log path: $logPath
log file: $logFile
-------------------------------------------------------------------------------
Defined in $cfgFile
-------------------------------------------------------------------------------
message recipient: $msgRecipient
EOF
exit
;;
version|-v|--version)
cat << EOF
$(basename "$0") v$version (c) 1990 - $(date +%Y) by Gilles Mouchet
Non-Commercial Use License See LICENSE for details
EOF
exit
;;
# must be in the last block of the case because of *
*|help|-h|--help)
usage
exit
;;
esac
shift
done
# success message
log I "send a success message" 1
mailSubject="[SUCCESS] - script result on `hostname`"
mailBody=" This is a success test mail\nHave a good day"
sendMail
# warnig message
log W "send a warning message" 1
mailSubject="[WARNING] - script result on `hostname`"
mailBody=" This is a warning test mail\nHave a good day"
sendMail
# error message
log E "send an error message" 1
cat << EOF > $tmpFile
This file contain the description error
or log file
EOF
mailSubject="[ERROR] - script result on `hostname`"
mailBody=" This is a warning test mail\nHave a good day"
sendMail
rm -rf $tmpFile