first
This commit is contained in:
98
core/bootstrap.sh
Normal file
98
core/bootstrap.sh
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BOOTSTRAP_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
# shellcheck source=lib/log.sh
|
||||
source "$BOOTSTRAP_ROOT/lib/log.sh"
|
||||
# shellcheck source=lib/ui.sh
|
||||
source "$BOOTSTRAP_ROOT/lib/ui.sh"
|
||||
# shellcheck source=lib/system.sh
|
||||
source "$BOOTSTRAP_ROOT/lib/system.sh"
|
||||
# shellcheck source=lib/network.sh
|
||||
source "$BOOTSTRAP_ROOT/lib/network.sh"
|
||||
# shellcheck source=lib/prompts.sh
|
||||
source "$BOOTSTRAP_ROOT/lib/prompts.sh"
|
||||
# shellcheck source=lib/validation.sh
|
||||
source "$BOOTSTRAP_ROOT/lib/validation.sh"
|
||||
# shellcheck source=core/runtime.sh
|
||||
source "$BOOTSTRAP_ROOT/core/runtime.sh"
|
||||
# shellcheck source=core/registry.sh
|
||||
source "$BOOTSTRAP_ROOT/core/registry.sh"
|
||||
# shellcheck source=core/dispatcher.sh
|
||||
source "$BOOTSTRAP_ROOT/core/dispatcher.sh"
|
||||
# shellcheck source=menus/main.sh
|
||||
source "$BOOTSTRAP_ROOT/menus/main.sh"
|
||||
|
||||
bootstrap_parse_args() {
|
||||
BOOTSTRAP_MODE="menu"
|
||||
BOOTSTRAP_MODULE_ID=""
|
||||
BOOTSTRAP_TARGET_USER=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--module)
|
||||
BOOTSTRAP_MODE="module"
|
||||
BOOTSTRAP_MODULE_ID="${2:-}"
|
||||
shift 2
|
||||
;;
|
||||
--user)
|
||||
BOOTSTRAP_TARGET_USER="${2:-}"
|
||||
shift 2
|
||||
;;
|
||||
--help|-h)
|
||||
BOOTSTRAP_MODE="help"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
ui_error "Argument non reconnu : $1"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$BOOTSTRAP_MODE" == "module" && -z "$BOOTSTRAP_MODULE_ID" ]]; then
|
||||
ui_error "Option --module incomplete"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
bootstrap_print_help() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
bash install.sh
|
||||
bash install.sh --module <module-id> [--user <username>]
|
||||
|
||||
Exemples:
|
||||
bash install.sh --module system/user-sudo
|
||||
bash install.sh --module system/user-sudo --user gilles
|
||||
EOF
|
||||
}
|
||||
|
||||
bootstrap_run() {
|
||||
bootstrap_parse_args "$@" || exit 1
|
||||
|
||||
runtime_init "$BOOTSTRAP_ROOT"
|
||||
log_init
|
||||
|
||||
ui_header "Postinstall Debian"
|
||||
ui_info "Initialisation du framework"
|
||||
|
||||
system_require_bash
|
||||
system_require_debian
|
||||
system_require_root
|
||||
network_warn_if_offline
|
||||
|
||||
registry_init
|
||||
|
||||
case "$BOOTSTRAP_MODE" in
|
||||
help)
|
||||
bootstrap_print_help
|
||||
;;
|
||||
module)
|
||||
dispatcher_run_module "$BOOTSTRAP_MODULE_ID" "$BOOTSTRAP_TARGET_USER"
|
||||
;;
|
||||
*)
|
||||
menu_main
|
||||
;;
|
||||
esac
|
||||
}
|
||||
190
core/dispatcher.sh
Normal file
190
core/dispatcher.sh
Normal file
@@ -0,0 +1,190 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
dispatcher_prompt_and_run_module() {
|
||||
local module_id="$1"
|
||||
local target_user=""
|
||||
local selected_groups=""
|
||||
local ssh_port=""
|
||||
local ssh_password_auth=""
|
||||
local ssh_root_login=""
|
||||
local avahi_enable=""
|
||||
local avahi_publish_workstation=""
|
||||
local host_name=""
|
||||
local domain_name=""
|
||||
local iface=""
|
||||
local ip_mode=""
|
||||
local ip_address=""
|
||||
local ip_prefix=""
|
||||
local ip_gateway=""
|
||||
local ip_dns=""
|
||||
local selected_nfs_shares=""
|
||||
local share_name=""
|
||||
local share_path=""
|
||||
local share_user=""
|
||||
local share_read_only=""
|
||||
local share_public=""
|
||||
local archive_name=""
|
||||
local docker_data_dir=""
|
||||
local default_nfs_ids=""
|
||||
local nfs_entry=""
|
||||
local nfs_item_id=""
|
||||
local nfs_item_name=""
|
||||
local nfs_mount_path=""
|
||||
local nfs_access=""
|
||||
local nfs_enabled=""
|
||||
local nfs_item_labels=()
|
||||
local nfs_item_ids=()
|
||||
local nfs_labels_blob=""
|
||||
local default_nfs_indices=""
|
||||
local nfs_action=""
|
||||
local nfs_mount_now=""
|
||||
local nfs_server_mode=""
|
||||
local samba_mode=""
|
||||
|
||||
case "$module_id" in
|
||||
system/user-sudo)
|
||||
target_user="$(prompt_read_default "Nom de l'utilisateur a configurer" "${POSTINSTALL_DEFAULT_USER:-gilles}")"
|
||||
dispatcher_run_module "$module_id" "$target_user"
|
||||
;;
|
||||
system/user-groups)
|
||||
target_user="$(prompt_read_default "Nom de l'utilisateur a configurer" "${POSTINSTALL_DEFAULT_USER:-gilles}")"
|
||||
selected_groups="$(prompt_read_csv_default "Groupes a ajouter, separes par des virgules" "${POSTINSTALL_USER_GROUPS_DEFAULT_GROUPS:-audio,video,plugdev,dialout,netdev,lpadmin,scanner}")"
|
||||
dispatcher_run_module "$module_id" "$target_user" "$selected_groups"
|
||||
;;
|
||||
network/ssh-server)
|
||||
ssh_port="$(prompt_read_default "Port SSH" "${POSTINSTALL_SSH_PORT:-22}")"
|
||||
ssh_password_auth="$(prompt_confirm_default "Autoriser l'authentification par mot de passe" "${POSTINSTALL_SSH_PASSWORD_AUTH:-yes}")"
|
||||
ssh_root_login="$(prompt_confirm_default "Autoriser la connexion root SSH" "${POSTINSTALL_SSH_ROOT_LOGIN:-no}")"
|
||||
dispatcher_run_module "$module_id" "$ssh_port" "$ssh_password_auth" "$ssh_root_login"
|
||||
;;
|
||||
network/mdns-avahi)
|
||||
avahi_enable="$(prompt_confirm_default "Activer la publication mDNS de la machine" "${POSTINSTALL_MDNS_AVAHI_ENABLE:-yes}")"
|
||||
avahi_publish_workstation="$(prompt_confirm_default "Publier la machine comme poste de travail" "${POSTINSTALL_MDNS_AVAHI_PUBLISH_WORKSTATION:-yes}")"
|
||||
dispatcher_run_module "$module_id" "$avahi_enable" "$avahi_publish_workstation"
|
||||
;;
|
||||
network/identity)
|
||||
host_name="$(prompt_read_default "Hostname" "${POSTINSTALL_NETWORK_IDENTITY_DEFAULT_HOSTNAME:-debian}")"
|
||||
domain_name="$(prompt_read_default "Domaine local" "${POSTINSTALL_NETWORK_IDENTITY_DEFAULT_DOMAIN:-local}")"
|
||||
dispatcher_run_module "$module_id" "$host_name" "$domain_name"
|
||||
;;
|
||||
network/ip-config)
|
||||
iface="$(prompt_read_default "Interface reseau" "${POSTINSTALL_NETWORK_IP_DEFAULT_INTERFACE:-$(system_primary_interface)}")"
|
||||
ip_mode="$(prompt_read_default "Mode reseau (dhcp ou static)" "${POSTINSTALL_NETWORK_IP_DEFAULT_MODE:-dhcp}")"
|
||||
if [[ "$ip_mode" == "static" ]]; then
|
||||
ip_address="$(prompt_read_default "Adresse IP" "${POSTINSTALL_NETWORK_IP_DEFAULT_ADDRESS:-10.0.0.10}")"
|
||||
ip_prefix="$(prompt_read_default "Prefixe CIDR" "${POSTINSTALL_NETWORK_IP_DEFAULT_PREFIX:-22}")"
|
||||
ip_gateway="$(prompt_read_default "Passerelle" "${POSTINSTALL_NETWORK_IP_DEFAULT_GATEWAY:-10.0.0.1}")"
|
||||
ip_dns="$(prompt_read_default "DNS" "${POSTINSTALL_NETWORK_IP_DEFAULT_DNS:-10.0.0.1}")"
|
||||
else
|
||||
ip_address=""
|
||||
ip_prefix=""
|
||||
ip_gateway=""
|
||||
ip_dns=""
|
||||
fi
|
||||
dispatcher_run_module "$module_id" "$iface" "$ip_mode" "$ip_address" "$ip_prefix" "$ip_gateway" "$ip_dns"
|
||||
;;
|
||||
network/nfs-client)
|
||||
# shellcheck source=/dev/null
|
||||
source "$RUNTIME_PROJECT_ROOT/modules/network/nfs-client/module.sh"
|
||||
nfs_action="$(prompt_select_from_list "Action NFS client" "activer des partages" "desactiver des partages")"
|
||||
nfs_item_labels=()
|
||||
nfs_item_ids=()
|
||||
if [[ "$nfs_action" == "desactiver des partages" ]]; then
|
||||
ui_section "Partages NFS actifs dans fstab"
|
||||
while IFS= read -r nfs_entry; do
|
||||
[[ -n "$nfs_entry" ]] || continue
|
||||
IFS='|' read -r nfs_item_id nfs_item_name nfs_mount_path nfs_remote nfs_access <<< "$nfs_entry"
|
||||
nfs_item_ids+=("$nfs_item_id")
|
||||
nfs_item_labels+=("$nfs_item_id : $nfs_item_name -> $nfs_mount_path ($nfs_access)")
|
||||
done < <(module_nfs_client_active_entries)
|
||||
if [[ "${#nfs_item_ids[@]}" -eq 0 ]]; then
|
||||
ui_info "Aucun partage NFS actif a desactiver"
|
||||
return 0
|
||||
fi
|
||||
nfs_labels_blob="$(printf '%s\n' "${nfs_item_labels[@]}")"
|
||||
selected_nfs_shares="$(prompt_select_multiple_from_list "Selectionner les partages a retirer de fstab, indexes separes par des virgules" "" "$nfs_labels_blob" "${nfs_item_ids[@]}")"
|
||||
dispatcher_run_module "$module_id" "disable" "$selected_nfs_shares"
|
||||
else
|
||||
ui_section "Partages NFS client disponibles"
|
||||
while IFS= read -r nfs_entry; do
|
||||
[[ -n "$nfs_entry" ]] || continue
|
||||
IFS='|' read -r nfs_item_id nfs_item_name _ _ _ nfs_mount_path nfs_access _ nfs_enabled <<< "$nfs_entry"
|
||||
nfs_item_ids+=("$nfs_item_id")
|
||||
nfs_item_labels+=("$nfs_item_id : $nfs_item_name -> $nfs_mount_path ($nfs_access)")
|
||||
done < <(module_nfs_client_entries)
|
||||
default_nfs_indices="$(module_nfs_client_default_indices)"
|
||||
nfs_labels_blob="$(printf '%s\n' "${nfs_item_labels[@]}")"
|
||||
selected_nfs_shares="$(prompt_select_multiple_from_list "Selectionner les partages a activer dans fstab, indexes separes par des virgules" "$default_nfs_indices" "$nfs_labels_blob" "${nfs_item_ids[@]}")"
|
||||
nfs_mount_now="$(prompt_confirm_default "Monter immediatement les partages selectionnes" "yes")"
|
||||
dispatcher_run_module "$module_id" "enable" "$selected_nfs_shares" "$nfs_mount_now"
|
||||
fi
|
||||
;;
|
||||
network/nfs-server)
|
||||
nfs_server_mode="$(prompt_select_from_list "Mode de synchronisation NFS serveur" "add-only" "strict")"
|
||||
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")"
|
||||
ui_info "Synchronisation des partages Samba depuis le fichier YAML du repo"
|
||||
dispatcher_run_module "$module_id" "$samba_mode"
|
||||
;;
|
||||
hardware/detect)
|
||||
dispatcher_run_module "$module_id"
|
||||
;;
|
||||
boot/grub-theme)
|
||||
# shellcheck source=/dev/null
|
||||
source "$RUNTIME_PROJECT_ROOT/modules/boot/grub-theme/module.sh"
|
||||
mapfile -t grub_archives < <(module_grub_theme_list_archives)
|
||||
if [[ "${#grub_archives[@]}" -eq 0 ]]; then
|
||||
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"
|
||||
;;
|
||||
containers/docker-engine)
|
||||
target_user="$(prompt_read_default "Utilisateur a ajouter au groupe docker" "${POSTINSTALL_DOCKER_TARGET_USER:-gilles}")"
|
||||
docker_data_dir="$(prompt_read_default "Dossier Docker" "/home/${target_user}/docker")"
|
||||
dispatcher_run_module "$module_id" "$target_user" "$docker_data_dir"
|
||||
;;
|
||||
*)
|
||||
dispatcher_run_module "$module_id"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
dispatcher_run_module() {
|
||||
local module_id="$1"
|
||||
local module_path=""
|
||||
local module_slug=""
|
||||
local install_function=""
|
||||
|
||||
shift
|
||||
|
||||
if ! registry_has_module "$module_id"; then
|
||||
ui_error "Module introuvable : $module_id"
|
||||
return 1
|
||||
fi
|
||||
|
||||
module_path="$(registry_module_path "$module_id")"
|
||||
# shellcheck source=/dev/null
|
||||
source "$module_path"
|
||||
|
||||
module_slug="${module_id##*/}"
|
||||
module_slug="${module_slug//-/_}"
|
||||
install_function="module_${module_slug}_install"
|
||||
|
||||
if ! declare -F "$install_function" >/dev/null 2>&1; then
|
||||
ui_error "Fonction d'installation absente pour le module : $module_id"
|
||||
return 1
|
||||
fi
|
||||
|
||||
ui_section "Execution du module $module_id"
|
||||
"$install_function" "$@"
|
||||
}
|
||||
|
||||
dispatcher_not_implemented() {
|
||||
local feature="$1"
|
||||
ui_warn "Fonction non implementee : $feature"
|
||||
}
|
||||
42
core/registry.sh
Normal file
42
core/registry.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
REGISTRY_MODULE_COUNT=0
|
||||
declare -a REGISTRY_MODULES=()
|
||||
declare -A REGISTRY_MODULE_PATHS=()
|
||||
|
||||
registry_init() {
|
||||
local module_file=""
|
||||
local module_id=""
|
||||
REGISTRY_MODULE_COUNT=0
|
||||
REGISTRY_MODULES=()
|
||||
REGISTRY_MODULE_PATHS=()
|
||||
|
||||
while IFS= read -r module_file; do
|
||||
# shellcheck source=/dev/null
|
||||
source "$module_file"
|
||||
module_id="${module_file#"$RUNTIME_PROJECT_ROOT/modules/"}"
|
||||
module_id="${module_id%/module.sh}"
|
||||
REGISTRY_MODULES+=("$module_id")
|
||||
REGISTRY_MODULE_PATHS["$module_id"]="$module_file"
|
||||
done < <(find "$RUNTIME_PROJECT_ROOT/modules" -mindepth 3 -maxdepth 3 -type f -name 'module.sh' | sort)
|
||||
|
||||
REGISTRY_MODULE_COUNT="${#REGISTRY_MODULES[@]}"
|
||||
}
|
||||
|
||||
registry_summary() {
|
||||
printf '%s' "$REGISTRY_MODULE_COUNT"
|
||||
}
|
||||
|
||||
registry_list() {
|
||||
printf '%s\n' "${REGISTRY_MODULES[@]}"
|
||||
}
|
||||
|
||||
registry_has_module() {
|
||||
local module_id="$1"
|
||||
[[ -n "${REGISTRY_MODULE_PATHS[$module_id]:-}" ]]
|
||||
}
|
||||
|
||||
registry_module_path() {
|
||||
local module_id="$1"
|
||||
printf '%s\n' "${REGISTRY_MODULE_PATHS[$module_id]:-}"
|
||||
}
|
||||
12
core/runtime.sh
Normal file
12
core/runtime.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
RUNTIME_PROJECT_ROOT=""
|
||||
RUNTIME_LOG_DIR=""
|
||||
RUNTIME_LOG_FILE=""
|
||||
|
||||
runtime_init() {
|
||||
RUNTIME_PROJECT_ROOT="$1"
|
||||
RUNTIME_LOG_DIR="${TMPDIR:-/tmp}/postinstall-debian"
|
||||
RUNTIME_LOG_FILE="$RUNTIME_LOG_DIR/install.log"
|
||||
mkdir -p "$RUNTIME_LOG_DIR"
|
||||
}
|
||||
Reference in New Issue
Block a user