Compare commits
13 Commits
6945e8e25b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b8dbe3eea | |||
| a1bcddb6e4 | |||
| 50617d8e0c | |||
| bd89f16c70 | |||
| 6d4068de38 | |||
| c666b5feb9 | |||
| 0248e202b0 | |||
| 86ebfd59dd | |||
| 680bd6f46c | |||
| 038a6bf49f | |||
| 11adbf51be | |||
| 4bc19b4a4f | |||
| 3efe0aad2d |
172
install/docker.sh
Normal file
172
install/docker.sh
Normal file
@@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ──────────────────────────────
|
||||
# Config & helpers
|
||||
# ──────────────────────────────
|
||||
LOGFILE="${LOGFILE:-/var/log/docker-install.log}"
|
||||
: > "$LOGFILE" || { echo "Cannot write $LOGFILE (need root?)"; exit 1; }
|
||||
|
||||
if [[ ${EUID:-$(id -u)} -ne 0 ]]; then SUDO="sudo"; else SUDO=""; fi
|
||||
TARGET_USER="${SUDO_USER:-$USER}"
|
||||
|
||||
GREEN=$(tput setaf 2 || true); CYAN=$(tput setaf 6 || true); RESET=$(tput sgr0 || true)
|
||||
BOLD=$(tput bold || true); NORM=$(tput sgr0 || true)
|
||||
|
||||
log() { echo -e "${CYAN}$*${RESET}" | tee -a "$LOGFILE"; }
|
||||
ok() { echo -e "${GREEN}$*${RESET}" | tee -a "$LOGFILE"; }
|
||||
run() { eval "$@" >>"$LOGFILE" 2>&1; }
|
||||
|
||||
ascii="
|
||||
${CYAN}
|
||||
=++++
|
||||
*####
|
||||
-====
|
||||
.****:-****.=***+
|
||||
:####-=####.*#### :
|
||||
.====.:==== -==== -##=
|
||||
+***=.****:-****.=***+ ****= ####*
|
||||
####*:####-=####.*#### ####+ *####*###*=
|
||||
====-.====.:==== -==== ====: -########*.
|
||||
-+++++++++++++++++++++++++++++++**#####==-:
|
||||
=#####################################:
|
||||
:###################################*.
|
||||
*#################################=
|
||||
.*##############################+.
|
||||
+##########################*-
|
||||
.=*####################+-.
|
||||
.-=+**######**+=-:.
|
||||
${RESET}"
|
||||
|
||||
clear
|
||||
echo -e "$ascii"
|
||||
|
||||
# ──────────────────────────────
|
||||
# Arguments
|
||||
# ──────────────────────────────
|
||||
ACTION="install" # install | uninstall
|
||||
PURGE_REPO="no" # yes | no
|
||||
|
||||
for arg in "${@:-}"; do
|
||||
case "$arg" in
|
||||
--uninstall|-u) ACTION="uninstall" ;;
|
||||
--purge-repo) PURGE_REPO="yes" ;;
|
||||
--help|-h)
|
||||
cat <<USAGE
|
||||
Usage:
|
||||
$0 # installs Docker (default)
|
||||
$0 --uninstall # uninstalls Docker (keeps /opt/docker)
|
||||
$0 -u --purge-repo # uninstalls Docker + removes APT repo and GPG key
|
||||
Logs: ${LOGFILE}
|
||||
USAGE
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# ──────────────────────────────
|
||||
# OS Detection
|
||||
# ──────────────────────────────
|
||||
if [[ -r /etc/os-release ]]; then . /etc/os-release; else
|
||||
echo "Cannot detect distribution (missing /etc/os-release)." >&2; exit 1; fi
|
||||
|
||||
case "${ID:-}" in
|
||||
ubuntu) BASE_URL="https://download.docker.com/linux/ubuntu" ;;
|
||||
debian) BASE_URL="https://download.docker.com/linux/debian" ;;
|
||||
*) echo "Unsupported distribution: ${ID:-unknown}. (Ubuntu/Debian only)"; exit 1 ;;
|
||||
esac
|
||||
|
||||
CODENAME="${VERSION_CODENAME:-}"
|
||||
if [[ -z "$CODENAME" ]] && command -v lsb_release >/dev/null 2>&1; then CODENAME="$(lsb_release -cs)"; fi
|
||||
if [[ -z "$CODENAME" ]]; then echo "Unable to determine codename (VERSION_CODENAME)." >&2; exit 1; fi
|
||||
|
||||
ARCH="$(dpkg --print-architecture)"
|
||||
PRETTY="${PRETTY_NAME:-$ID}"
|
||||
LISTFILE="/etc/apt/sources.list.d/docker.list"
|
||||
KEYFILE="/etc/apt/keyrings/docker.asc"
|
||||
REPO_LINE="deb [arch=${ARCH} signed-by=${KEYFILE}] ${BASE_URL} ${CODENAME} stable"
|
||||
|
||||
echo -e "Mode: ${CYAN}${BOLD}${ACTION^^}${RESET} | ${BOLD}${PRETTY}${RESET} (${BOLD}${CODENAME}${RESET}), arch=${CYAN}${ARCH}${RESET}"
|
||||
echo -e "Detailed logs: ${CYAN}${LOGFILE}${RESET}\n"
|
||||
|
||||
# ──────────────────────────────
|
||||
# INSTALL Functions
|
||||
# ──────────────────────────────
|
||||
install_docker() {
|
||||
echo -e "${CYAN}1) Installing prerequisites (ca-certificates, curl, gnupg, acl)${RESET}"
|
||||
run "$SUDO apt-get update -y"
|
||||
run "$SUDO apt-get install -y ca-certificates curl gnupg acl"
|
||||
|
||||
echo -e "${CYAN}2) Preparing Docker keyring${RESET}"
|
||||
run "$SUDO install -m 0755 -d /etc/apt/keyrings"
|
||||
if [[ ! -f "$KEYFILE" ]]; then
|
||||
run "$SUDO curl -fsSL ${BASE_URL}/gpg -o ${KEYFILE}"
|
||||
run "$SUDO chmod a+r ${KEYFILE}"
|
||||
fi
|
||||
|
||||
echo -e "${CYAN}3) Adding Docker APT repository (stable)${RESET}"
|
||||
echo "$REPO_LINE" | $SUDO tee "$LISTFILE" >/dev/null
|
||||
run "$SUDO apt-get update -y"
|
||||
|
||||
echo -e "${CYAN}4) Installing Docker Engine + Buildx + Compose${RESET}"
|
||||
run "$SUDO apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
||||
|
||||
echo -e "${CYAN}5) Enabling Docker service${RESET}"
|
||||
run "$SUDO systemctl enable --now docker"
|
||||
|
||||
echo -e "${CYAN}6) Managing docker group and adding user${RESET}"
|
||||
if ! getent group docker >/dev/null 2>&1; then run "$SUDO groupadd docker"; fi
|
||||
if ! id -nG "$TARGET_USER" | grep -qw docker; then run "$SUDO usermod -aG docker '$TARGET_USER'"; fi
|
||||
|
||||
echo -e "${CYAN}7) Creating and setting permissions for /opt/docker${RESET}"
|
||||
run "$SUDO mkdir -p /opt/docker"
|
||||
run "$SUDO chown root:docker /opt/docker"
|
||||
run "$SUDO chmod 2770 /opt/docker"
|
||||
run "$SUDO setfacl -R -m g:docker:rwx /opt/docker"
|
||||
run "$SUDO setfacl -R -d -m g:docker:rwx /opt/docker"
|
||||
|
||||
echo -e "${CYAN}8) Verifying installation (hello-world)${RESET}"
|
||||
run "$SUDO docker run --rm hello-world"
|
||||
|
||||
echo ""; ok "✅ Docker installation and verification completed."
|
||||
echo -e "Log out and log back in (${BOLD}logout/login${NORM}) to use Docker without sudo."
|
||||
}
|
||||
|
||||
# ──────────────────────────────
|
||||
# UNINSTALL Functions
|
||||
# ──────────────────────────────
|
||||
uninstall_docker() {
|
||||
echo -e "${CYAN}1) Stopping Docker service (if running)${RESET}"
|
||||
if $SUDO systemctl is-active --quiet docker; then run "$SUDO systemctl stop docker"; fi
|
||||
run "$SUDO systemctl disable docker || true"
|
||||
|
||||
echo -e "${CYAN}2) Removing Docker packages${RESET}"
|
||||
PKGS="docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras docker-scan-plugin docker.io"
|
||||
run "$SUDO DEBIAN_FRONTEND=noninteractive apt-get purge -y $PKGS || true"
|
||||
echo -e "${CYAN}3) Cleaning up dependencies${RESET}"
|
||||
run "$SUDO apt-get autoremove -y --purge || true"
|
||||
|
||||
if [[ "$PURGE_REPO" == "yes" ]]; then
|
||||
echo -e "${CYAN}4) Removing Docker APT repo and GPG key${RESET}"
|
||||
run "$SUDO rm -f '$LISTFILE' || true"
|
||||
run "$SUDO rm -f '$KEYFILE' || true"
|
||||
run "$SUDO apt-get update -y || true"
|
||||
STEP_NEXT=5
|
||||
else
|
||||
STEP_NEXT=4
|
||||
fi
|
||||
|
||||
echo -e "${CYAN}${STEP_NEXT}) Keeping local data and /opt/docker (no deletion)${RESET}"
|
||||
echo -e "${CYAN} → /opt/docker, /var/lib/docker, and /var/lib/containerd are NOT touched.${RESET}"
|
||||
|
||||
echo ""; ok "🧹 Docker uninstallation complete (packages removed, data kept)."
|
||||
echo -e "You can manually delete ${BOLD}/var/lib/docker${NORM} and ${BOLD}/var/lib/containerd${NORM} if you want a full cleanup."
|
||||
}
|
||||
|
||||
# ──────────────────────────────
|
||||
# Main
|
||||
# ──────────────────────────────
|
||||
case "$ACTION" in
|
||||
install) install_docker ;;
|
||||
uninstall) uninstall_docker ;;
|
||||
esac
|
||||
31
install/packages.sh
Normal file
31
install/packages.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define color codes
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
RESET='\033[0m' # No Color
|
||||
|
||||
# Packages list
|
||||
packages=(
|
||||
"exa" # Better than ls
|
||||
"bat" # Better than cat
|
||||
"btop" # Betther than top
|
||||
"ncdu" # Better than du -h
|
||||
"duf" # Better than df -h
|
||||
"neofetch" # Because it's cool
|
||||
"git" # Because git
|
||||
)
|
||||
|
||||
# Packages installation
|
||||
clear
|
||||
echo "Mise à jour de la liste des paquets..."
|
||||
echo " "
|
||||
sudo apt update >/dev/null 2>&1
|
||||
echo "Installation des paquets :"
|
||||
for package in "${packages[@]}"; do
|
||||
if sudo NEEDRESTART_MODE=a apt install "$package" -y >/dev/null 2>&1; then
|
||||
echo -e " - Installation de $package : ${GREEN}ok${RESET}"
|
||||
else
|
||||
echo -e " - Installation de $package : ${RED}échoué${RESET}"
|
||||
fi
|
||||
done
|
||||
35
monitoring/cpu.sh
Normal file
35
monitoring/cpu.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
|
||||
# URL ntfy
|
||||
NTFY_URL="my_url"
|
||||
# Chemin vers le fichier journal
|
||||
LOG_FILE="/var/log/cpu.log"
|
||||
# Seuil de charge CPU en pourcentage
|
||||
SEUIL_CPU=70
|
||||
|
||||
# Obtenir le nom du serveur à partir du hostname
|
||||
SERVER_NAME=$(hostname)
|
||||
|
||||
# Fonction pour obtenir la charge CPU actuelle
|
||||
get_cpu_load() {
|
||||
# Utilisation de la commande 'top' pour obtenir la charge CPU
|
||||
cpu_load=$(top -bn1 | awk '/%Cpu/ {print $2}' | cut -d "." -f 1)
|
||||
echo "$cpu_load"
|
||||
}
|
||||
|
||||
# Vérifier la charge CPU et envoyer une notification si nécessaire
|
||||
check_cpu_load() {
|
||||
cpu_usage=$(get_cpu_load)
|
||||
|
||||
if [ "$cpu_usage" -gt "$SEUIL_CPU" ]; then
|
||||
#top_processes=$(get_top_processes)
|
||||
date >> $LOG_FILE
|
||||
ps aux --sort=-%cpu | head -n 6 >> $LOG_FILE
|
||||
message="La charge CPU du serveur ${SERVER_NAME} est de ${cpu_usage}% (seuil: ${SEUIL_CPU}%) voir logs dans /var/log/cpu.log"
|
||||
title="!!!CPU(${SERVER_NAME})!!!"
|
||||
curl -d "$message" ntfy.sh/$NTFY_URL?title=$title
|
||||
fi
|
||||
}
|
||||
|
||||
# Appeler la fonction pour vérifier la charge CPU
|
||||
check_cpu_load
|
||||
40
monitoring/update.sh
Normal file
40
monitoring/update.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Utilisation ##
|
||||
# cat /var/log/update.log pour voir les logs
|
||||
# sudo bash update.sh afin de l'utiliser directement
|
||||
|
||||
# Colors
|
||||
green='\033[0;32m'
|
||||
orange='\033[0;33m'
|
||||
red='\033[0;31m'
|
||||
reset='\033[0m'
|
||||
|
||||
# Update and log
|
||||
echo "Mise à jour des paquets..."
|
||||
apt update > /dev/null 2>&1
|
||||
echo "Dernière MAJ : $(date +'%d/%m %H:%M')" > /var/log/update.log
|
||||
update=$(apt --just-print upgrade 2>/dev/null | grep 'Inst' | wc -l)
|
||||
message="$update mises à jour peuvent être appliquées immédiatement"
|
||||
if [ "$update" -ne 0 ]; then
|
||||
if [ "$update" -lt 2 ]; then
|
||||
echo -e "${green}$update mise à jour peut être appliquée immédiatement${reset}" | tee -a /var/log/update.log
|
||||
elif [ "$update" -lt 10 ]; then
|
||||
echo -e "${green}$message${reset}" | tee -a /var/log/update.log
|
||||
elif [ "$update" -lt 20 ]; then
|
||||
echo -e "${orange}$message${reset}" | tee -a /var/log/update.log
|
||||
elif [ "$update" -ge 20 ]; then
|
||||
echo -e "${red}$message${reset}" | tee -a /var/log/update.log
|
||||
fi
|
||||
else
|
||||
echo -e "${green}Tous les paquets sont à jour${reset}" | tee -a /var/log/update.log
|
||||
fi
|
||||
|
||||
security=$(apt --just-print upgrade 2>/dev/null | grep 'Inst' | grep -i security | wc -l)
|
||||
if [ "$security" -ne 0 ]; then
|
||||
echo -e "${red}$security de ces mises à jour sont des mises à jour de sécurité${reset}" | tee -a /var/log/update.log
|
||||
fi
|
||||
|
||||
if [ -f /var/run/reboot-required ]; then
|
||||
echo -e "${orange}Un redémarrage est requis pour finaliser les mises à jour${reset}" | tee -a /var/log/update.log
|
||||
fi
|
||||
45
update.sh
45
update.sh
@@ -1,45 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## Utilisation ##
|
||||
# cat /var/log/update.log pour voir les logs
|
||||
# sudo bash update.sh afin de l'utiliser directement
|
||||
|
||||
# Colors
|
||||
green='\033[0;32m'
|
||||
orange='\033[0;33m'
|
||||
red='\033[0;31m'
|
||||
reset='\033[0m'
|
||||
|
||||
# Update and log
|
||||
echo "Mise à jour des paquets..."
|
||||
apt update > /dev/null 2>&1
|
||||
update=$(apt --just-print upgrade 2>/dev/null | grep 'Inst' | wc -l)
|
||||
if [ "$update" -ne 0 ]; then
|
||||
if [ "$update" -lt 2 ]; then
|
||||
echo -e "${green}$update mise à jour peut être appliquée immédiatement${reset}" > /var/log/update.log
|
||||
echo -e "${green}$update mise à jour peut être appliquée immédiatement${reset}"
|
||||
elif [ "$update" -lt 10 ]; then
|
||||
echo -e "${green}$update mises à jour peuvent être appliquées immédiatement${reset}" > /var/log/update.log
|
||||
echo -e "${green}$update mises à jour peuvent être appliquées immédiatement${reset}"
|
||||
elif [ "$update" -lt 20 ]; then
|
||||
echo -e "${orange}$update mises à jour peuvent être appliquées immédiatement${reset}" > /var/log/update.log
|
||||
echo -e "${orange}$update mises à jour peuvent être appliquées immédiatement${reset}"
|
||||
elif [ "$update" -ge 20 ]; then
|
||||
echo -e "${red}$update mises à jour peuvent être appliquées immédiatement${reset}" > /var/log/update.log
|
||||
echo -e "${red}$update mises à jour peuvent être appliquées immédiatement${reset}"
|
||||
fi
|
||||
else
|
||||
echo -e "${green}Tous les paquets sont à jour${reset}" > /var/log/update.log
|
||||
echo -e "${green}Tous les paquets sont à jour${reset}"
|
||||
fi
|
||||
|
||||
security=$(apt --just-print upgrade 2>/dev/null | grep 'Inst' | grep -i security | wc -l)
|
||||
if [ "$security" -ne 0 ]; then
|
||||
echo -e "${red}$security de ces mises à jour sont des mises à jour de sécurité${reset}" >> /var/log/update.log
|
||||
echo -e "${red}$security de ces mises à jour sont des mises à jour de sécurité${reset}"
|
||||
fi
|
||||
|
||||
if [ -f /var/run/reboot-required ]; then
|
||||
echo -e "${orange}Un redémarrage est requis pour finaliser les mises à jour${reset}" >> /var/log/update.log
|
||||
echo -e "${orange}Un redémarrage est requis pour finaliser les mises à jour${reset}"
|
||||
fi
|
||||
Reference in New Issue
Block a user