first commit

This commit is contained in:
julien
2026-03-15 19:58:46 +01:00
commit bbc4e4da65
32 changed files with 1854 additions and 0 deletions

177
run.sh Executable file
View File

@@ -0,0 +1,177 @@
#!/usr/bin/env bash
# Point d'entree pour le provisioning NETbian
export PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
export ROLE_DIR="$PROJECT_DIR/roles"
export PROFILE_DIR="$PROJECT_DIR/profiles"
source "$PROJECT_DIR/lib.sh"
enable_strict_mode
PROG="$(basename "$0")"
usage() {
local exit_code="${1:-1}"
cat <<EOM >&2
Usage: $PROG [options]
Options:
-p, --profile <server|desktop|devel|cli> Profile to install (required)
-l, --lang <code> Language code if translations are needed (e.g. fr, es, de)
--config <path> Config file path (default: /etc/netbian.conf)
--list-profiles List available profiles and exit
--list-roles List available roles and exit
-h, --help Show this help
EOM
exit "$exit_code"
}
PROFILE_OVERRIDE="${NETBIAN_PROFILE:-}"
LANG_OVERRIDE="${NETBIAN_LANG:-}"
CONFIG_FILE="${NETBIAN_CONFIG_FILE:-/etc/netbian.conf}"
ARGS_PROVIDED=false
LIST_PROFILES=false
LIST_ROLES=false
if [[ $# -gt 0 ]]; then
ARGS_PROVIDED=true
while [[ $# -gt 0 ]]; do
case "$1" in
-p | --profile)
shift
[[ $# -gt 0 && -n "${1:-}" ]] || {
err "Option --profile requires a value."
usage
}
PROFILE_OVERRIDE="$1"
shift
;;
-l | --lang)
shift
[[ $# -gt 0 && -n "${1:-}" ]] || {
err "Option --lang requires a value."
usage
}
LANG_OVERRIDE="$1"
shift
;;
--config)
shift
[[ $# -gt 0 && -n "${1:-}" ]] || {
err "Option --config requires a path."
usage
}
CONFIG_FILE="$1"
shift
;;
--list-profiles)
LIST_PROFILES=true
shift
;;
--list-roles)
LIST_ROLES=true
shift
;;
-h | --help)
usage 0
;;
-*)
err "Unknown option: $1"
usage
;;
*)
err "Positional arguments are not supported."
usage
;;
esac
done
fi
if $LIST_PROFILES; then
list_available_profiles | sort
exit 0
fi
if $LIST_ROLES; then
list_available_roles | sort
exit 0
fi
[[ "$(id -u)" -eq 0 ]] || fatal "Please run this script as root."
require_debian_version "13"
if exists_cmd curl; then
curl -fsSI --connect-timeout 10 https://deb.debian.org/ >/dev/null || fatal "Network unavailable (HTTP test failed with curl)."
elif exists_cmd wget; then
wget -q --timeout=10 --spider https://deb.debian.org/ >/dev/null 2>&1 || fatal "Network unavailable (HTTP test failed with wget)."
else
fatal "curl or wget is required for the network availability check."
fi
cat <<'EOM'
_ _ _____ _____ _ _
| \ | | ____|_ _| |__ (_) __ _ _ __
| \| | _| | | | '_ \| |/ _` | '_ \
| |\ | |___ | | | |_) | | (_| | | | |
|_| \_|_____| |_| |_.__/|_|\__,_|_| |_|
EOM
declare -A CFG
CONFIG_EXISTED=false
if [[ -f "$CONFIG_FILE" ]]; then
CONFIG_EXISTED=true
validate_config_file "$CONFIG_FILE"
source "$CONFIG_FILE"
[[ -n "${profile:-}" ]] && CFG[profile]="$profile"
[[ -n "${lang:-}" ]] && CFG[lang]="$lang"
fi
if [[ -n "$PROFILE_OVERRIDE" ]]; then
PROFILE_OVERRIDE="$(tr '[:upper:]' '[:lower:]' <<<"$PROFILE_OVERRIDE")"
case "$PROFILE_OVERRIDE" in
server | desktop | devel | cli) CFG[profile]="$PROFILE_OVERRIDE" ;;
*)
err "Invalid profile"
usage
;;
esac
fi
if [[ -n "$LANG_OVERRIDE" ]]; then
CFG[lang]="$(tr '[:upper:]' '[:lower:]' <<<"$LANG_OVERRIDE" | tr '_' '-')"
fi
[[ -n "${CFG[profile]:-}" ]] || {
err "Profile not provided. Use --profile or NETBIAN_PROFILE."
usage
}
TMP_IN="$(mktemp --tmpdir netbian.conf.in.XXXXXX)" || TMP_IN="/tmp/netbian.conf.in.$$"
TMP_OUT="$(mktemp --tmpdir netbian.conf.out.XXXXXX)" || TMP_OUT="/tmp/netbian.conf.out.$$"
trap 'rm -f "$TMP_IN" "$TMP_OUT"' EXIT
if [[ -f "$CONFIG_FILE" ]]; then
grep -v -E '^(profile|lang)=' "$CONFIG_FILE" >"$TMP_IN" || true
else
: >"$TMP_IN"
fi
{
cat "$TMP_IN"
printf 'profile=%s\n' "${CFG[profile]}"
[[ -n "${CFG[lang]:-}" ]] && printf 'lang=%s\n' "${CFG[lang]}"
} >"$TMP_OUT"
if write_if_changed "$TMP_OUT" "$CONFIG_FILE"; then
echo "Configuration written to $CONFIG_FILE:"
grep -E '^(profile|lang)=' "$CONFIG_FILE" || true
elif $CONFIG_EXISTED; then
if $ARGS_PROVIDED; then
echo "No changes; configuration remains in $CONFIG_FILE:"
else
echo "Configuration read from $CONFIG_FILE:"
fi
grep -E '^(profile|lang)=' "$CONFIG_FILE" || true
else
echo "No configuration file present and no changes were made."
fi
export CONFIG_FILE
exec "$PROJECT_DIR/roles.sh"