diff --git a/config/ftp-server.yaml b/config/ftp-server.yaml new file mode 100644 index 0000000..c1cf707 --- /dev/null +++ b/config/ftp-server.yaml @@ -0,0 +1,6 @@ +ftp: + listen_port: 21 + anonymous_enable: no + local_enable: yes + write_enable: no + local_root: /home/gilles diff --git a/config/grub-theme.yaml b/config/grub-theme.yaml new file mode 100644 index 0000000..b0da054 --- /dev/null +++ b/config/grub-theme.yaml @@ -0,0 +1,9 @@ +grub: + theme_archive: debian-1080p.zip + default_mode: saved + save_default: true + timeout: 5 + timeout_style: menu + disable_os_prober: false + gfxmode: auto + cmdline_linux_default: quiet splash diff --git a/core/bootstrap.sh b/core/bootstrap.sh index bbc2566..8873d2b 100644 --- a/core/bootstrap.sh +++ b/core/bootstrap.sh @@ -20,6 +20,8 @@ source "$BOOTSTRAP_ROOT/core/runtime.sh" source "$BOOTSTRAP_ROOT/core/registry.sh" # shellcheck source=core/dispatcher.sh source "$BOOTSTRAP_ROOT/core/dispatcher.sh" +# shellcheck source=core/test_runner.sh +source "$BOOTSTRAP_ROOT/core/test_runner.sh" # shellcheck source=menus/main.sh source "$BOOTSTRAP_ROOT/menus/main.sh" diff --git a/core/dispatcher.sh b/core/dispatcher.sh index 39dfccf..8865cc4 100644 --- a/core/dispatcher.sh +++ b/core/dispatcher.sh @@ -40,6 +40,17 @@ dispatcher_prompt_and_run_module() { local nfs_mount_now="" local nfs_server_mode="" local samba_mode="" + local grub_default_mode="" + local grub_save_default="" + local grub_timeout="" + local grub_timeout_style="" + local grub_os_prober="" + local grub_gfxmode="" + local grub_cmdline="" + local grub_extra_cmdline="" + local grub_keep_extra="" + local grub_selection="" + local grub_index=1 case "$module_id" in system/user-sudo) @@ -120,12 +131,18 @@ dispatcher_prompt_and_run_module() { fi ;; network/nfs-server) - nfs_server_mode="$(prompt_select_from_list "Mode de synchronisation NFS serveur" "add-only" "strict")" + nfs_server_mode="$(prompt_select_described_from_list \ + "Mode de synchronisation NFS serveur" \ + "add-only|Ajoute seulement les exports absents sans retirer les autres." \ + "strict|Remplace la zone geree pour refléter exactement le YAML du repo.")" ui_info "Synchronisation des exports NFS depuis le fichier YAML du repo" dispatcher_run_module "$module_id" "$nfs_server_mode" ;; network/samba-share) - samba_mode="$(prompt_select_from_list "Mode de synchronisation Samba" "add-only" "strict")" + samba_mode="$(prompt_select_described_from_list \ + "Mode de synchronisation Samba" \ + "add-only|Ajoute seulement les partages absents sans ecraser le reste." \ + "strict|Regénère la zone geree pour correspondre exactement au YAML du repo.")" ui_info "Synchronisation des partages Samba depuis le fichier YAML du repo" dispatcher_run_module "$module_id" "$samba_mode" ;; @@ -140,8 +157,51 @@ dispatcher_prompt_and_run_module() { ui_warn "Aucune archive de theme GRUB disponible" return 1 fi - archive_name="$(prompt_select_from_list "Selectionner une archive de theme" "${grub_archives[@]}")" - dispatcher_run_module "$module_id" "$archive_name" + ui_section "Themes GRUB disponibles" + grub_index=1 + for archive_name in "${grub_archives[@]}"; do + printf ' %d. %s (%s)\n' "$grub_index" "$(module_grub_theme_archive_label "$archive_name")" "$archive_name" + grub_index=$((grub_index + 1)) + done + grub_selection="$(prompt_select_number "Selectionner une archive de theme" 1 "${#grub_archives[@]}")" + archive_name="${grub_archives[$((grub_selection - 1))]}" + grub_default_mode="$(prompt_select_described_from_list \ + "Mode de demarrage par defaut" \ + "dernier choix|Redemarre sur le dernier systeme choisi au menu GRUB." \ + "toujours Debian|Demarre toujours sur la premiere entree GRUB, en general Debian.")" + if [[ "$grub_default_mode" == "dernier choix" ]]; then + grub_default_mode="saved" + elif [[ "$grub_default_mode" == "toujours Debian" ]]; then + grub_default_mode="0" + fi + grub_save_default="$(prompt_confirm_default "Memoriser le dernier OS choisi au boot" "yes")" + grub_timeout="$(prompt_read_default "Temps d'attente du menu GRUB" "5")" + grub_timeout_style="$(prompt_select_described_from_list \ + "Style du menu GRUB" \ + "menu visible|Affiche toujours le menu GRUB pendant le delai choisi." \ + "menu cache|Cache le menu au demarrage sauf cas particulier.")" + if [[ "$grub_timeout_style" == "menu visible" ]]; then + grub_timeout_style="menu" + elif [[ "$grub_timeout_style" == "menu cache" ]]; then + grub_timeout_style="hidden" + fi + grub_os_prober="$(prompt_confirm_default "Activer la detection Windows et autres OS" "yes")" + if [[ "$grub_os_prober" == "yes" ]]; then + grub_os_prober="false" + else + grub_os_prober="true" + fi + grub_gfxmode="$(prompt_read_default "Resolution GRUB (auto, 1920x1080, 2560x1440...)" "auto")" + grub_cmdline="$(prompt_read_default "Parametres noyau Linux par defaut" "quiet splash")" + grub_extra_cmdline="$(module_grub_theme_extra_cmdline_options "$grub_cmdline")" + if [[ -n "$grub_extra_cmdline" ]]; then + ui_info "Options noyau detectees sur la machine mais absentes de la config saisie : $grub_extra_cmdline" + grub_keep_extra="$(prompt_confirm_default "Conserver ces options supplementaires" "yes")" + if [[ "$grub_keep_extra" == "yes" ]]; then + grub_cmdline="$(module_grub_theme_merge_cmdline_options "$grub_cmdline" "$grub_extra_cmdline")" + fi + fi + dispatcher_run_module "$module_id" "$archive_name" "$grub_default_mode" "$grub_save_default" "$grub_timeout" "$grub_timeout_style" "$grub_os_prober" "$grub_gfxmode" "$grub_cmdline" ;; containers/docker-engine) target_user="$(prompt_read_default "Utilisateur a ajouter au groupe docker" "${POSTINSTALL_DOCKER_TARGET_USER:-gilles}")" diff --git a/core/registry.sh b/core/registry.sh index 033e7ce..93006df 100644 --- a/core/registry.sh +++ b/core/registry.sh @@ -40,3 +40,15 @@ registry_module_path() { local module_id="$1" printf '%s\n' "${REGISTRY_MODULE_PATHS[$module_id]:-}" } + +registry_module_test_path() { + local module_id="$1" + local module_path="" + + module_path="${REGISTRY_MODULE_PATHS[$module_id]:-}" + if [[ -z "$module_path" ]]; then + return 1 + fi + + printf '%s\n' "${module_path%/module.sh}/tests.sh" +} diff --git a/core/test_runner.sh b/core/test_runner.sh new file mode 100644 index 0000000..4e562aa --- /dev/null +++ b/core/test_runner.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +test_runner_smoke() { + ui_section "Smoke test" + bash "$RUNTIME_PROJECT_ROOT/tests/smoke.sh" +} + +test_runner_module() { + local module_id="$1" + local test_path="" + + test_path="$(registry_module_test_path "$module_id")" + if [[ -z "$test_path" || ! -f "$test_path" ]]; then + ui_warn "Aucun test disponible pour $module_id" + return 1 + fi + + ui_section "Test du module $module_id" + bash "$test_path" +} + +test_runner_all_modules() { + local module_id="" + local failures=0 + + while IFS= read -r module_id; do + [[ -n "$module_id" ]] || continue + if ! test_runner_module "$module_id"; then + failures=$((failures + 1)) + fi + done < <(registry_list) + + if [[ "$failures" -eq 0 ]]; then + ui_success "Tous les tests modules se sont termines sans echec" + else + ui_warn "$failures test(s) module(s) ont retourne un echec" + fi +} diff --git a/docs/lan-validation.md b/docs/lan-validation.md index eebf193..8bd80ec 100644 --- a/docs/lan-validation.md +++ b/docs/lan-validation.md @@ -52,6 +52,14 @@ cat /etc/samba/smb.conf.d/postinstall-home.conf systemctl status wsdd2 ``` +### FTP + +```bash +systemctl status vsftpd +grep -E 'listen_port|anonymous_enable|local_enable|write_enable|local_root' /etc/vsftpd.conf +ss -ltnp | grep ':21' +``` + ### NFS client ```bash @@ -107,6 +115,13 @@ Verifier si la machine Debian apparait dans : Si le poste n'apparait pas mais que `\\ip\public` fonctionne, verifier `wsdd2` sur Debian. +### FTP + +Depuis un client FTP ou l'explorateur si autorise : + +- tester `ftp://` +- verifier si l'authentification locale fonctionne selon `config/ftp-server.yaml` + ## Resultat attendu - le poste Debian repond au ping sur son IP @@ -114,4 +129,5 @@ Si le poste n'apparait pas mais que `\\ip\public` fonctionne, verifier `wsdd2` s - SSH accepte les connexions selon la politique definie dans `config/ssh-server.yaml` - le partage Samba `public` est accessible depuis Linux et Windows 11 - le poste apparait idealement dans l'explorateur reseau Windows via Samba et `wsdd2` +- le serveur FTP repond selon la politique definie dans `config/ftp-server.yaml` - les exports NFS et montages NFS sont conformes aux fichiers YAML du repo diff --git a/lib/prompts.sh b/lib/prompts.sh index ec8af97..4905022 100644 --- a/lib/prompts.sh +++ b/lib/prompts.sh @@ -45,7 +45,7 @@ prompt_confirm_default() { local answer="" local prompt_suffix="[y/N]" - if [[ "$default_answer" =~ ^[Yy]$ ]]; then + if [[ "$default_answer" =~ ^([Yy]|yes|YES|Yes)$ ]]; then prompt_suffix="[Y/n]" fi @@ -76,7 +76,31 @@ prompt_select_from_list() { local selection="" for selection in "${options[@]}"; do - printf ' %d. %s\n' "$index" "$selection" + printf ' %d. %s\n' "$index" "$selection" >&2 + index=$((index + 1)) + done + + selection="$(prompt_select_number "$label" 1 "${#options[@]}")" + printf '%s\n' "${options[$((selection - 1))]}" +} + +prompt_select_described_from_list() { + local label="$1" + shift + local entries=("$@") + local entry="" + local option="" + local description="" + local options=() + local index=1 + local selection="" + + for entry in "${entries[@]}"; do + option="${entry%%|*}" + description="${entry#*|}" + options+=("$option") + printf ' %d. %s\n' "$index" "$option" >&2 + printf ' %s\n' "$description" >&2 index=$((index + 1)) done @@ -99,7 +123,7 @@ prompt_select_multiple_from_list() { IFS=$'\n' read -r -d '' -a labels < <(printf '%s\0' "$labels_csv") for raw_index in "${labels[@]}"; do - printf ' %d. %s\n' "$index" "$raw_index" + printf ' %d. %s\n' "$index" "$raw_index" >&2 index=$((index + 1)) done diff --git a/menus/main.sh b/menus/main.sh index 93fd526..084da6c 100644 --- a/menus/main.sh +++ b/menus/main.sh @@ -60,6 +60,64 @@ menu_system_configuration() { menu_modules_by_prefix "system" "Configuration systeme" } +menu_tests() { + local selection="" + local modules=() + local module_id="" + local index=1 + + while true; do + ui_section "Tests" + printf ' 1. Smoke test\n' + printf ' 2. Tous les modules\n' + printf ' 3. Un module\n' + printf ' 0. Retour\n' + + selection="$(prompt_select_number "Selectionner un test" 0 3)" + + case "$selection" in + 0) + return 0 + ;; + 1) + test_runner_smoke + ui_pause + ;; + 2) + test_runner_all_modules + ui_pause + ;; + 3) + modules=() + index=1 + while IFS= read -r module_id; do + [[ -n "$module_id" ]] || continue + modules+=("$module_id") + done < <(registry_list) + + if [[ "${#modules[@]}" -eq 0 ]]; then + ui_warn "Aucun module disponible" + ui_pause + continue + fi + + ui_section "Selection du module a tester" + for module_id in "${modules[@]}"; do + printf ' %d. %s\n' "$index" "$module_id" + index=$((index + 1)) + done + printf ' 0. Retour\n' + + selection="$(prompt_select_number "Selectionner un module" 0 "${#modules[@]}")" + if [[ "$selection" != "0" ]]; then + test_runner_module "${modules[$((selection - 1))]}" + ui_pause + fi + ;; + esac + done +} + menu_main() { local selection="" @@ -92,6 +150,9 @@ menu_main() { 4) menu_system_configuration ;; + 5) + menu_tests + ;; *) dispatcher_not_implemented "menu $selection" ui_pause diff --git a/modules/boot/grub-theme/config.sh b/modules/boot/grub-theme/config.sh index 3851299..aa8bef7 100644 --- a/modules/boot/grub-theme/config.sh +++ b/modules/boot/grub-theme/config.sh @@ -1,4 +1,14 @@ POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_PRIMARY="assets/grub" +POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_SECONDARY="theme/grub" POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_FALLBACK="themes/grub" POSTINSTALL_GRUB_THEME_INSTALL_DIR="/boot/grub/themes/postinstall-debian" POSTINSTALL_GRUB_THEME_CONFIG_FILE="/etc/default/grub.d/postinstall-debian.cfg" +POSTINSTALL_GRUB_THEME_CONFIG_BACKUP_FILE="/etc/default/grub.d/postinstall-debian.cfg.bak" +POSTINSTALL_GRUB_THEME_SETTINGS_FILE="config/grub-theme.yaml" +POSTINSTALL_GRUB_DEFAULT_MODE="saved" +POSTINSTALL_GRUB_SAVEDEFAULT="true" +POSTINSTALL_GRUB_TIMEOUT="5" +POSTINSTALL_GRUB_TIMEOUT_STYLE="menu" +POSTINSTALL_GRUB_DISABLE_OS_PROBER="false" +POSTINSTALL_GRUB_GFXMODE="auto" +POSTINSTALL_GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" diff --git a/modules/boot/grub-theme/module.sh b/modules/boot/grub-theme/module.sh index 03c3c57..9c72c5f 100644 --- a/modules/boot/grub-theme/module.sh +++ b/modules/boot/grub-theme/module.sh @@ -14,12 +14,121 @@ module_grub_theme_metadata() { printf '%s|%s|%s\n' "$MODULE_ID" "$MODULE_NAME" "$MODULE_DESCRIPTION" } -module_grub_theme_archive_dir() { - if [[ -d "$MODULE_GRUB_THEME_PROJECT_ROOT/$POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_PRIMARY" ]]; then - printf '%s\n' "$MODULE_GRUB_THEME_PROJECT_ROOT/$POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_PRIMARY" - else - printf '%s\n' "$MODULE_GRUB_THEME_PROJECT_ROOT/$POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_FALLBACK" +module_grub_theme_settings_path() { + printf '%s/%s\n' "$MODULE_GRUB_THEME_PROJECT_ROOT" "$POSTINSTALL_GRUB_THEME_SETTINGS_FILE" +} + +module_grub_theme_settings() { + local config_path="" + local theme_archive="" + local default_mode="$POSTINSTALL_GRUB_DEFAULT_MODE" + local save_default="$POSTINSTALL_GRUB_SAVEDEFAULT" + local timeout="$POSTINSTALL_GRUB_TIMEOUT" + local timeout_style="$POSTINSTALL_GRUB_TIMEOUT_STYLE" + local disable_os_prober="$POSTINSTALL_GRUB_DISABLE_OS_PROBER" + local gfxmode="$POSTINSTALL_GRUB_GFXMODE" + local cmdline="$POSTINSTALL_GRUB_CMDLINE_LINUX_DEFAULT" + + config_path="$(module_grub_theme_settings_path)" + if [[ -f "$config_path" ]]; then + while IFS='=' read -r key value; do + case "$key" in + theme_archive) theme_archive="$value" ;; + default_mode) default_mode="$value" ;; + save_default) save_default="$value" ;; + timeout) timeout="$value" ;; + timeout_style) timeout_style="$value" ;; + disable_os_prober) disable_os_prober="$value" ;; + gfxmode) gfxmode="$value" ;; + cmdline_linux_default) cmdline="$value" ;; + esac + done < <( + awk ' + /^[[:space:]]*theme_archive:/ { sub(/^[^:]+:[[:space:]]*/, "", $0); print "theme_archive=" $0 } + /^[[:space:]]*default_mode:/ { print "default_mode=" $2 } + /^[[:space:]]*save_default:/ { print "save_default=" $2 } + /^[[:space:]]*timeout:/ { print "timeout=" $2 } + /^[[:space:]]*timeout_style:/ { print "timeout_style=" $2 } + /^[[:space:]]*disable_os_prober:/ { print "disable_os_prober=" $2 } + /^[[:space:]]*gfxmode:/ { print "gfxmode=" $2 } + /^[[:space:]]*cmdline_linux_default:/ { + sub(/^[^:]+:[[:space:]]*/, "", $0) + print "cmdline_linux_default=" $0 + } + ' "$config_path" + ) fi + + printf '%s|%s|%s|%s|%s|%s|%s|%s\n' \ + "$theme_archive" \ + "$default_mode" \ + "$save_default" \ + "$timeout" \ + "$timeout_style" \ + "$disable_os_prober" \ + "$gfxmode" \ + "$cmdline" +} + +module_grub_theme_current_cmdline() { + local grub_file="/etc/default/grub" + + if [[ ! -f "$grub_file" ]]; then + printf '\n' + return 0 + fi + + awk -F'"' '/^GRUB_CMDLINE_LINUX_DEFAULT=/{ print $2; exit }' "$grub_file" +} + +module_grub_theme_extra_cmdline_options() { + local desired_cmdline="$1" + local current_cmdline="" + local option="" + local extras="" + + current_cmdline="$(module_grub_theme_current_cmdline)" + + for option in $current_cmdline; do + if [[ " $desired_cmdline " != *" $option "* ]]; then + extras="${extras:+$extras }$option" + fi + done + + printf '%s\n' "$extras" +} + +module_grub_theme_merge_cmdline_options() { + local desired_cmdline="$1" + local extra_cmdline="$2" + local merged="$desired_cmdline" + local option="" + + for option in $extra_cmdline; do + if [[ " $merged " != *" $option "* ]]; then + merged="${merged:+$merged }$option" + fi + done + + printf '%s\n' "$merged" +} + +module_grub_theme_archive_dir() { + local candidates=( + "$MODULE_GRUB_THEME_PROJECT_ROOT/$POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_PRIMARY" + "$MODULE_GRUB_THEME_PROJECT_ROOT/$POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_SECONDARY" + "$MODULE_GRUB_THEME_PROJECT_ROOT/$POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_FALLBACK" + ) + local candidate="" + + for candidate in "${candidates[@]}"; do + if [[ -d "$candidate" ]] && find "$candidate" -maxdepth 1 -type f \( -name '*.zip' -o -name '*.tar.gz' -o -name '*.tgz' \) | grep -q .; then + printf '%s\n' "$candidate" + return 0 + fi + done + + printf '%s\n' "$MODULE_GRUB_THEME_PROJECT_ROOT/$POSTINSTALL_GRUB_THEME_ARCHIVE_DIR_FALLBACK" } module_grub_theme_list_archives() { @@ -28,16 +137,33 @@ module_grub_theme_list_archives() { find "$archive_dir" -maxdepth 1 -type f \( -name '*.zip' -o -name '*.tar.gz' -o -name '*.tgz' \) -printf '%f\n' | sort } +module_grub_theme_archive_label() { + local archive_name="$1" + local label="" + + label="${archive_name%.zip}" + label="${label%.tar.gz}" + label="${label%.tgz}" + label="${label//-/ }" + printf '%s\n' "$label" +} + module_grub_theme_extract() { local archive_name="$1" local archive_dir="" local archive_path="" local target_dir="" + local theme_file="" archive_dir="$(module_grub_theme_archive_dir)" archive_path="$archive_dir/$archive_name" target_dir="$POSTINSTALL_GRUB_THEME_INSTALL_DIR/${archive_name%.*}" + if [[ ! -f "$archive_path" ]]; then + ui_error "Archive GRUB introuvable : $archive_path" + return 1 + fi + mkdir -p "$target_dir" case "$archive_name" in @@ -57,22 +183,90 @@ module_grub_theme_extract() { ;; esac - find "$target_dir" -type f -name 'theme.txt' | head -n 1 + theme_file="$(find "$target_dir" -type f -name 'theme.txt' | head -n 1)" + if [[ -z "$theme_file" ]]; then + ui_error "Aucun fichier theme.txt detecte dans l'archive $archive_name" + return 1 + fi + + printf '%s\n' "$theme_file" +} + +module_grub_theme_backup_config() { + if [[ -f "$POSTINSTALL_GRUB_THEME_CONFIG_FILE" ]]; then + cp "$POSTINSTALL_GRUB_THEME_CONFIG_FILE" "$POSTINSTALL_GRUB_THEME_CONFIG_BACKUP_FILE" + fi +} + +module_grub_theme_preview() { + local archive_name="$1" + local default_mode="$2" + local timeout="$3" + local timeout_style="$4" + local disable_os_prober="$5" + local archive_dir="" + + archive_dir="$(module_grub_theme_archive_dir)" + ui_info "Archive selectionnee : $archive_name" + ui_info "Source : $archive_dir/$archive_name" + ui_info "Demarrage par defaut : $default_mode" + ui_info "Timeout menu : $timeout" + ui_info "Style menu : $timeout_style" + ui_info "Detection autres OS : $disable_os_prober" } module_grub_theme_install() { - local archive_name="$1" + local archive_name="${1:-}" + local default_mode="${2:-}" + local save_default="${3:-}" + local timeout="${4:-}" + local timeout_style="${5:-}" + local disable_os_prober="${6:-}" + local gfxmode="${7:-}" + local cmdline="${8:-}" + local settings="" local theme_path="" + settings="$(module_grub_theme_settings)" + IFS='|' read -r \ + default_archive \ + settings_default_mode \ + settings_save_default \ + settings_timeout \ + settings_timeout_style \ + settings_disable_os_prober \ + settings_gfxmode \ + settings_cmdline <<< "$settings" + + archive_name="${archive_name:-$default_archive}" + default_mode="${default_mode:-$settings_default_mode}" + save_default="${save_default:-$settings_save_default}" + timeout="${timeout:-$settings_timeout}" + timeout_style="${timeout_style:-$settings_timeout_style}" + disable_os_prober="${disable_os_prober:-$settings_disable_os_prober}" + gfxmode="${gfxmode:-$settings_gfxmode}" + cmdline="${cmdline:-$settings_cmdline}" + if [[ -z "$archive_name" ]]; then ui_error "Aucune archive de theme specifiee" return 1 fi + module_grub_theme_preview "$archive_name" "$default_mode" "$timeout" "$timeout_style" "$disable_os_prober" mkdir -p /etc/default/grub.d + module_grub_theme_backup_config theme_path="$(module_grub_theme_extract "$archive_name")" || return 1 - printf 'GRUB_THEME="%s"\n' "$theme_path" > "$POSTINSTALL_GRUB_THEME_CONFIG_FILE" + cat > "$POSTINSTALL_GRUB_THEME_CONFIG_FILE" <&2 + exit 1 +fi + if ! test -f /etc/default/grub.d/postinstall-debian.cfg; then printf 'grub-theme test SKIPPED: module configuration not applied\n' exit 0 diff --git a/modules/network/ftp-server/config.sh b/modules/network/ftp-server/config.sh new file mode 100644 index 0000000..d07b031 --- /dev/null +++ b/modules/network/ftp-server/config.sh @@ -0,0 +1,3 @@ +POSTINSTALL_FTP_SETTINGS_FILE="config/ftp-server.yaml" +POSTINSTALL_FTP_CONFIG_DIR="/etc/vsftpd" +POSTINSTALL_FTP_CONFIG_FILE="/etc/vsftpd.conf" diff --git a/modules/network/ftp-server/metadata.conf b/modules/network/ftp-server/metadata.conf new file mode 100644 index 0000000..86448b0 --- /dev/null +++ b/modules/network/ftp-server/metadata.conf @@ -0,0 +1,4 @@ +MODULE_ID="network/ftp-server" +MODULE_NAME="Serveur FTP" +MODULE_CATEGORY="network" +MODULE_DESCRIPTION="Installe et configure un serveur FTP via vsftpd" diff --git a/modules/network/ftp-server/module.sh b/modules/network/ftp-server/module.sh new file mode 100644 index 0000000..cd62c41 --- /dev/null +++ b/modules/network/ftp-server/module.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash + +MODULE_FTP_SERVER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +MODULE_FTP_SERVER_PROJECT_ROOT="$(cd "$MODULE_FTP_SERVER_DIR/../../.." && pwd)" + +# shellcheck source=lib/package.sh +source "$MODULE_FTP_SERVER_PROJECT_ROOT/lib/package.sh" +# shellcheck source=modules/network/ftp-server/config.sh +source "$MODULE_FTP_SERVER_DIR/config.sh" +# shellcheck source=modules/network/ftp-server/metadata.conf +source "$MODULE_FTP_SERVER_DIR/metadata.conf" + +module_ftp_server_metadata() { + printf '%s|%s|%s\n' "$MODULE_ID" "$MODULE_NAME" "$MODULE_DESCRIPTION" +} + +module_ftp_server_config_path() { + printf '%s/%s\n' "$MODULE_FTP_SERVER_PROJECT_ROOT" "$POSTINSTALL_FTP_SETTINGS_FILE" +} + +module_ftp_server_settings() { + local config_path="" + local listen_port="21" + local anonymous_enable="no" + local local_enable="yes" + local write_enable="no" + local local_root="/home/gilles" + + config_path="$(module_ftp_server_config_path)" + if [[ -f "$config_path" ]]; then + while IFS='=' read -r key value; do + case "$key" in + listen_port) listen_port="$value" ;; + anonymous_enable) anonymous_enable="$value" ;; + local_enable) local_enable="$value" ;; + write_enable) write_enable="$value" ;; + local_root) local_root="$value" ;; + esac + done < <( + awk ' + /^[[:space:]]*listen_port:/ { print "listen_port=" $2 } + /^[[:space:]]*anonymous_enable:/ { print "anonymous_enable=" $2 } + /^[[:space:]]*local_enable:/ { print "local_enable=" $2 } + /^[[:space:]]*write_enable:/ { print "write_enable=" $2 } + /^[[:space:]]*local_root:/ { print "local_root=" $2 } + ' "$config_path" + ) + fi + + printf '%s|%s|%s|%s|%s\n' "$listen_port" "$anonymous_enable" "$local_enable" "$write_enable" "$local_root" +} + +module_ftp_server_write_config() { + local listen_port="$1" + local anonymous_enable="$2" + local local_enable="$3" + local write_enable="$4" + local local_root="$5" + + cat > "$POSTINSTALL_FTP_CONFIG_FILE" </dev/null 2>&1 || true +} diff --git a/modules/network/ftp-server/tests.sh b/modules/network/ftp-server/tests.sh new file mode 100644 index 0000000..0de1649 --- /dev/null +++ b/modules/network/ftp-server/tests.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +MODULE_FTP_SERVER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$MODULE_FTP_SERVER_DIR/../../.." && pwd)" + +# shellcheck source=lib/ui.sh +source "$PROJECT_ROOT/lib/ui.sh" +# shellcheck source=lib/log.sh +source "$PROJECT_ROOT/lib/log.sh" +# shellcheck source=lib/package.sh +source "$PROJECT_ROOT/lib/package.sh" +# shellcheck source=core/runtime.sh +source "$PROJECT_ROOT/core/runtime.sh" +# shellcheck source=modules/network/ftp-server/module.sh +source "$MODULE_FTP_SERVER_DIR/module.sh" + +runtime_init "$PROJECT_ROOT" +log_init + +if ! test -f "$PROJECT_ROOT/config/ftp-server.yaml"; then + printf 'ftp-server test FAILED: missing repository config\n' >&2 + exit 1 +fi + +if ! package_is_installed vsftpd; then + printf 'ftp-server test SKIPPED: vsftpd not installed\n' + exit 0 +fi + +if module_ftp_server_test; then + printf 'ftp-server test OK\n' +else + printf 'ftp-server test FAILED\n' >&2 + exit 1 +fi diff --git a/tools.md b/tools.md index 9c0d2d7..ccc5362 100644 --- a/tools.md +++ b/tools.md @@ -144,18 +144,18 @@ Questions : le besoin existe-t-il vraiment alors que SSH permet deja SFTP plus p Methode installation : a definir uniquement si le besoin est maintenu apres validation Tests : a definir Difficulte : moyenne -Statut : en attente de validation +Statut : implemente ``` ### 11. boot/grub-theme ```text -Nom : Theme GRUB -Description : configure GRUB pour utiliser un theme present dans assets/grub +Nom : Theme et options GRUB +Description : configure GRUB pour utiliser un theme et des options utiles de boot, y compris dual boot Windows Categorie : boot -Questions : quel theme choisir, faut-il memoriser la derniere entree selectionnee, faut-il modifier le timeout ou la resolution ? -Methode installation : lister les themes disponibles, copier ou referencer le theme choisi, mettre a jour la configuration GRUB puis regenerer la configuration -Tests : grep GRUB_THEME /etc/default/grub ; update-grub ; verification visuelle au reboot +Questions : quel theme choisir, faut-il memoriser la derniere entree selectionnee, faut-il modifier le timeout, la resolution, le style du menu et activer os-prober pour Windows ? +Methode installation : lister les themes disponibles, appliquer le theme choisi, configurer GRUB_DEFAULT, GRUB_SAVEDEFAULT, GRUB_TIMEOUT, GRUB_TIMEOUT_STYLE, GRUB_DISABLE_OS_PROBER, GRUB_GFXMODE et regenerer la configuration +Tests : grep GRUB_THEME /etc/default/grub.d/postinstall-debian.cfg ; grep GRUB_DEFAULT /etc/default/grub.d/postinstall-debian.cfg ; update-grub ; verification visuelle au reboot Difficulte : moyenne Statut : implemente ``` @@ -186,6 +186,18 @@ Difficulte : moyenne Statut : implemente ``` +```text +Nom : gnome extension +Description : liste les extension gnome a installer +Categorie : gnome +Questions : dans un fichier .yml de config des extension par defaut a installer avec confirmation systematique possible +Methode installation : +Tests : +Difficulte : +Statut : +``` + + ## Ordre de dev recommande 1. system/user-sudo