mirror of
https://github.com/arthur-pbty/arch-custom-iso.git
synced 2026-08-01 20:28:05 +02:00
update install script
This commit is contained in:
+248
-109
@@ -1,144 +1,283 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
clear
|
# ==========================================
|
||||||
echo "========================"
|
# UI SYSTEM (Robust Bash Nameref)
|
||||||
echo " Arch Custom Installer"
|
# ==========================================
|
||||||
echo "========================"
|
declare -A GRID_DATA
|
||||||
|
GRID_NUM_PAGES=0
|
||||||
|
|
||||||
# =========================
|
grid_menu() {
|
||||||
# 1. KEYBOARD
|
# Crée un alias local vers le tableau passé en argument (nom en string)
|
||||||
# =========================
|
local -n _items=$1
|
||||||
echo "Clavier (fr / us / uk / de / es) :"
|
local max_cols=$3 max_rows=$4
|
||||||
read -r KEYMAP
|
local data_page=0 item_number=0 max_cols_data line
|
||||||
loadkeys "$KEYMAP"
|
|
||||||
|
|
||||||
# =========================
|
GRID_DATA=()
|
||||||
# 2. NETWORK (AUTO + WIFI MANUEL)
|
GRID_NUM_PAGES=0
|
||||||
# =========================
|
local total_items=${#_items[@]}
|
||||||
if ! ping -c 1 archlinux.org &>/dev/null; then
|
|
||||||
echo "Pas d'internet détecté."
|
|
||||||
|
|
||||||
iwctl device list
|
while (( item_number < total_items )); do
|
||||||
echo "Device Wi-Fi (ex: wlan0) :"
|
max_cols_data=1
|
||||||
read -r DEVICE
|
for (( line=0; line<max_rows; line++ )); do
|
||||||
|
if (( item_number >= total_items )); then break; fi
|
||||||
|
local key="P${data_page}L${line}"
|
||||||
|
[[ ! -v GRID_DATA[$key] ]] && GRID_DATA[$key]=""
|
||||||
|
|
||||||
iwctl station "$DEVICE" scan
|
local index=$(( item_number + max_rows - line ))
|
||||||
sleep 3
|
(( index >= total_items )) && index=$(( total_items - 1 ))
|
||||||
|
if (( index < 0 )); then index=$(( total_items + index )); (( index < 0 )) && index=0; fi
|
||||||
|
|
||||||
iwctl station "$DEVICE" get-networks
|
local index_str item_num_plus1 item_num_str spaces_needed spaces add
|
||||||
|
printf -v index_str "%d" "$index"
|
||||||
|
item_num_plus1=$(( item_number + 1 ))
|
||||||
|
printf -v item_num_str "%d" "$item_num_plus1"
|
||||||
|
spaces_needed=$(( ${#index_str} - ${#item_num_str} ))
|
||||||
|
(( spaces_needed < 0 )) && spaces_needed=0
|
||||||
|
printf -v spaces "%*s" "$spaces_needed" ""
|
||||||
|
|
||||||
|
local item="${_items[$item_number]}"
|
||||||
|
add="${spaces}${item_num_plus1}) ${item}"
|
||||||
|
|
||||||
echo "SSID :"
|
local current_line="${GRID_DATA[$key]}"
|
||||||
read -r SSID
|
if (( ${#current_line} + ${#add} > max_cols )); then (( data_page++ )); break; fi
|
||||||
|
|
||||||
|
GRID_DATA[$key]="${current_line}${add}"
|
||||||
|
max_cols_data=$(( max_cols_data > ( ${#item} + 2 ) ? max_cols_data : ( ${#item} + 2 ) ))
|
||||||
|
(( item_number++ ))
|
||||||
|
done
|
||||||
|
|
||||||
echo "Password Wi-Fi :"
|
for (( line=0; line<max_rows; line++ )); do
|
||||||
read -rs PASS
|
local key="P${data_page}L${line}"
|
||||||
echo
|
[[ ! -v GRID_DATA[$key] ]] && continue
|
||||||
|
local idx=$(( item_number - (max_rows - line) ))
|
||||||
|
if (( idx < 0 )); then idx=$(( total_items + idx )); (( idx < 0 )) && idx=0
|
||||||
|
elif (( idx >= total_items )); then idx=$(( total_items - 1 )); fi
|
||||||
|
|
||||||
|
local item="${_items[$idx]}"
|
||||||
|
local pad=$(( max_cols_data - ${#item} ))
|
||||||
|
(( pad < 0 )) && pad=0
|
||||||
|
local spaces_pad; printf -v spaces_pad "%*s" "$pad" ""
|
||||||
|
GRID_DATA[$key]="${GRID_DATA[$key]}${spaces_pad}"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
GRID_NUM_PAGES=$(( data_page + 1 ))
|
||||||
|
}
|
||||||
|
|
||||||
iwctl station "$DEVICE" connect "$SSID" --passphrase "$PASS"
|
print_grid_menu() {
|
||||||
|
local page=$1 found=0 key
|
||||||
|
for key in "${!GRID_DATA[@]}"; do [[ $key == P${page}L* ]] && found=1 && break; done
|
||||||
|
(( found == 0 )) && echo "Page $(( page + 1 )) does not exist." && return
|
||||||
|
|
||||||
sleep 5
|
echo -e "\n--- Page $(( page + 1 )) of $GRID_NUM_PAGES ---\n"
|
||||||
fi
|
for key in $(printf "%s\n" "${!GRID_DATA[@]}" | grep "^P${page}L" | sort -t 'L' -k2 -n); do
|
||||||
|
echo "${GRID_DATA[$key]}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# =========================
|
grid_choose() {
|
||||||
# 3. TIMEZONE
|
local arr_name=$1 cols=${2:-80} rows=${3:-15} page=0
|
||||||
# =========================
|
|
||||||
echo "Fuseau horaire (ex: Europe/Paris) :"
|
grid_menu "$arr_name" "$page" "$cols" "$rows"
|
||||||
read -r TIMEZONE
|
|
||||||
|
|
||||||
# =========================
|
# Crée un alias local pour lire la taille et l'élément choisi
|
||||||
# 4. LOCALE
|
local -n _items=$arr_name
|
||||||
# =========================
|
|
||||||
echo "Langue système (fr_FR.UTF-8 / en_US.UTF-8 / etc) :"
|
|
||||||
read -r LOCALE
|
|
||||||
|
|
||||||
# =========================
|
while true; do
|
||||||
# 5. USER
|
clear
|
||||||
# =========================
|
print_grid_menu "$page"
|
||||||
DEFAULT_USER="user"
|
echo -e "\n[n]ext | [p]rev | [q]uit"
|
||||||
echo "Nom utilisateur [$DEFAULT_USER] :"
|
read -rp "Choice: " choice
|
||||||
read -r USERNAME
|
if [[ "$choice" == "q" ]]; then return 1; fi
|
||||||
USERNAME=${USERNAME:-$DEFAULT_USER}
|
if [[ "$choice" == "n" && $page -lt $((GRID_NUM_PAGES - 1)) ]]; then ((page++)); continue; fi
|
||||||
|
if [[ "$choice" == "p" && $page -gt 0 ]]; then ((page--)); continue; fi
|
||||||
|
|
||||||
echo "Mot de passe utilisateur :"
|
if [[ "$choice" =~ ^[0-9]+$ ]]; then
|
||||||
read -rs USERPASS
|
local idx=$((choice - 1))
|
||||||
echo
|
if (( idx >= 0 && idx < ${#_items[@]} )); then
|
||||||
|
echo "${_items[$idx]}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sleep 0.5
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# =========================
|
ask_confirm() { read -rp "$1 (y/n): " ans; [[ "$ans" =~ ^[yY]$ ]]; }
|
||||||
# 6. HOSTNAME
|
|
||||||
# =========================
|
|
||||||
DEFAULT_HOST="archbox"
|
|
||||||
echo "Hostname [$DEFAULT_HOST] :"
|
|
||||||
read -r HOSTNAME
|
|
||||||
HOSTNAME=${HOSTNAME:-$DEFAULT_HOST}
|
|
||||||
|
|
||||||
# =========================
|
# ==========================================
|
||||||
# 7. DISK
|
# SYSTEM LOGIC
|
||||||
# =========================
|
# ==========================================
|
||||||
lsblk -dpno NAME,SIZE,MODEL
|
|
||||||
|
|
||||||
echo "Disque (ex: /dev/sda ou /dev/nvme0n1) :"
|
cleanup_install_disk() {
|
||||||
read -r DISK
|
local disk="$1"
|
||||||
|
[[ -z "$disk" || ! -b "$disk" ]] && return 1
|
||||||
|
echo "Cleaning up disk: $disk"
|
||||||
|
findmnt -R /mnt >/dev/null && umount -R /mnt || true
|
||||||
|
while read -r dev; do
|
||||||
|
[[ -b "$dev" ]] || continue
|
||||||
|
swapoff "$dev" 2>/dev/null || true
|
||||||
|
while read -r target; do [[ -n "$target" ]] && umount "$target" 2>/dev/null; done < <(findmnt -rn -S "$dev" -o TARGET 2>/dev/null)
|
||||||
|
done < <(lsblk -rnpo PATH "$disk")
|
||||||
|
while read -r dev type; do
|
||||||
|
[[ "$type" == "disk" || "$type" == "part" || "$type" == "crypt" ]] || continue
|
||||||
|
while read -r vg; do [[ -n "$vg" ]] && vgchange -an "$vg" 2>/dev/null; done < <(pvs --noheadings -o vg_name "$dev" 2>/dev/null | awk '{$1=$1; print}' | sort -u)
|
||||||
|
done < <(lsblk -rnpo PATH,TYPE "$disk")
|
||||||
|
while read -r dev type; do [[ "$type" == "crypt" ]] && cryptsetup close "$dev" 2>/dev/null; done < <(lsblk -rnpo PATH,TYPE "$disk")
|
||||||
|
blockdev --flushbufs "$disk" 2>/dev/null || true
|
||||||
|
partprobe "$disk" 2>/dev/null || true
|
||||||
|
udevadm settle || true
|
||||||
|
}
|
||||||
|
|
||||||
echo "⚠️ TOUT SERA EFFACÉ SUR $DISK"
|
install_base_system() {
|
||||||
echo "Taper YES pour confirmer :"
|
pacman-key --init
|
||||||
read -r CONFIRM
|
pacman-key --populate archlinux
|
||||||
[[ "$CONFIRM" != "YES" ]] && exit 1
|
pacman -Sy --noconfirm
|
||||||
|
|
||||||
# =========================
|
local disk
|
||||||
# 8. PARTITIONING
|
disk=$(jq -r '.disk_config.device_modifications[] | select(.wipe==true) | .device' user_configuration.json)
|
||||||
# =========================
|
cleanup_install_disk "$disk"
|
||||||
sgdisk --zap-all "$DISK"
|
|
||||||
|
|
||||||
sgdisk -n 1:0:+512M -t 1:ef00 -c 1:"EFI" "$DISK"
|
archinstall --config user_configuration.json --creds user_credentials.json --silent --skip-ntp --skip-wkd --skip-wifi-check
|
||||||
sgdisk -n 2:0:0 -t 2:8300 -c 2:"ROOT" "$DISK"
|
|
||||||
|
|
||||||
EFI="${DISK}1"
|
mkdir -p /mnt/etc/sudoers.d
|
||||||
ROOT="${DISK}2"
|
echo "%wheel ALL=(ALL:ALL) NOPASSWD: ALL" > /mnt/etc/sudoers.d/99-installer
|
||||||
|
chmod 440 /mnt/etc/sudoers.d/99-installer
|
||||||
|
}
|
||||||
|
|
||||||
mkfs.fat -F32 "$EFI"
|
# ==========================================
|
||||||
mkfs.ext4 -F "$ROOT"
|
# CONFIGURATOR
|
||||||
|
# ==========================================
|
||||||
|
|
||||||
mount "$ROOT" /mnt
|
run_configurator() {
|
||||||
mount --mkdir "$EFI" /mnt/boot
|
command -v jq >/dev/null || pacman -Sy --noconfirm jq
|
||||||
|
|
||||||
# =========================
|
# 1. Keyboard (PAS de 'local' devant le tableau !)
|
||||||
# 9. BASE INSTALL
|
kb_keys=("us" "fr" "de" "uk" "es" "it" "pt-latin1" "br-abnt2" "dvorak" "colemak" "ru" "jp106")
|
||||||
# =========================
|
kb_choice=$(grid_choose kb_keys 80 10) || exit 1
|
||||||
pacstrap -K /mnt \
|
keyboard="$kb_choice"
|
||||||
base linux linux-firmware \
|
[[ $(tty 2>/dev/null) == "/dev/tty"* ]] && loadkeys "$keyboard" 2>/dev/null || true
|
||||||
sudo networkmanager iwd
|
|
||||||
|
|
||||||
genfstab -U /mnt >> /mnt/etc/fstab
|
# 2. User
|
||||||
|
while true; do
|
||||||
|
clear; read -rp "Username: " username
|
||||||
|
[[ "$username" =~ ^[a-z_][a-z0-9_-]*[$]?$ ]] && break
|
||||||
|
done
|
||||||
|
while true; do
|
||||||
|
clear; read -rsp "Password: " password; echo
|
||||||
|
read -rsp "Confirm: " password_confirmation; echo
|
||||||
|
[[ -n "$password" && "$password" == "$password_confirmation" ]] && break
|
||||||
|
done
|
||||||
|
password_hash=$(printf '%s' "$password" | openssl passwd -6 -stdin)
|
||||||
|
clear; read -rp "Hostname [archlinux]: " hostname
|
||||||
|
[[ -z "$hostname" ]] && hostname="archlinux"
|
||||||
|
|
||||||
# =========================
|
# 3. Timezone (PAS de 'local' devant le tableau !)
|
||||||
# 10. CHROOT
|
clear; echo "Loading timezones..."
|
||||||
# =========================
|
mapfile -t timezones < <(timedatectl list-timezones)
|
||||||
arch-chroot /mnt /bin/bash <<EOF
|
timezone=$(grid_choose timezones 100 20) || exit 1
|
||||||
|
|
||||||
set -e
|
# 4. Disk (PAS de 'local' devant les tableaux !)
|
||||||
|
clear
|
||||||
|
local boot_source exclude_disk
|
||||||
|
boot_source=$(findmnt -no SOURCE /run/archiso/bootmnt 2>/dev/null || true)
|
||||||
|
local device_b=$(readlink -f "$boot_source" 2>/dev/null || echo "")
|
||||||
|
while [[ -n "$device_b" ]]; do
|
||||||
|
local parent_b=$(lsblk -dno PKNAME "$device_b" 2>/dev/null | tail -n1)
|
||||||
|
[[ -z "$parent_b" ]] && break; device_b="/dev/$parent_b"
|
||||||
|
done
|
||||||
|
[[ $(lsblk -dno TYPE "$device_b" 2>/dev/null) == "disk" ]] && exclude_disk="$device_b"
|
||||||
|
|
||||||
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
|
disk_options_array=()
|
||||||
hwclock --systohc
|
mapfile -t available_disks < <(lsblk -dpno NAME,TYPE | awk '$2=="disk"{print $1}' | grep -E '/dev/(sd|hd|vd|nvme|mmcblk|xv)' | { [[ -n "${exclude_disk:-}" ]] && grep -Fvx "$exclude_disk" || cat; })
|
||||||
|
for dev in "${available_disks[@]}"; do
|
||||||
|
local size=$(lsblk -dno SIZE "$dev") model=$(lsblk -dno MODEL "$dev" | sed 's/ *$//')
|
||||||
|
disk_options_array+=("$dev ($size) - $model")
|
||||||
|
done
|
||||||
|
selected_disk_display=$(grid_choose disk_options_array 100 10) || exit 1
|
||||||
|
disk=$(echo "$selected_disk_display" | awk '{print $1}')
|
||||||
|
|
||||||
echo "KEYMAP=$KEYMAP" > /etc/vconsole.conf
|
# 5. Encryption
|
||||||
|
clear; local encrypt_installation="false"
|
||||||
|
ask_confirm "Encrypt disk?" && encrypt_installation="true"
|
||||||
|
|
||||||
echo "$LOCALE UTF-8" >> /etc/locale.gen
|
# --- JSON GENERATION ---
|
||||||
locale-gen
|
local pw_esc=$(echo -n "$password" | jq -Rsa)
|
||||||
echo "LANG=$LOCALE" > /etc/locale.conf
|
local hash_esc=$(echo -n "$password_hash" | jq -Rsa)
|
||||||
|
local user_esc=$(echo -n "$username" | jq -Rsa)
|
||||||
|
local enc_line=""; [[ "$encrypt_installation" == "true" ]] && enc_line="\"encryption_password\": $pw_esc,"
|
||||||
|
|
||||||
echo "$HOSTNAME" > /etc/hostname
|
cat <<_EOF_ >user_credentials.json
|
||||||
|
{
|
||||||
|
$enc_line
|
||||||
|
"root_enc_password": $hash_esc,
|
||||||
|
"users": [{ "enc_password": $hash_esc, "groups": [], "sudo": true, "username": $user_esc }]
|
||||||
|
}
|
||||||
|
_EOF_
|
||||||
|
|
||||||
useradd -m -G wheel -s /bin/bash "$USERNAME"
|
local disk_size=$(lsblk -bdno SIZE "$disk") mib=$((1024*1024)) gib=$((mib*1024))
|
||||||
echo "$USERNAME:$USERPASS" | chpasswd
|
local disk_size_in_mib=$((disk_size / mib * mib)) boot_size=$((2 * gib)) main_start=$((boot_size + mib))
|
||||||
|
local main_size=$((disk_size_in_mib - main_start - mib))
|
||||||
|
|
||||||
|
local disk_enc=""
|
||||||
|
[[ "$encrypt_installation" == "true" ]] && disk_enc=$(cat <<_EOF_
|
||||||
|
,
|
||||||
|
"disk_encryption": {
|
||||||
|
"encryption_type": "luks",
|
||||||
|
"lvm_volumes": [],
|
||||||
|
"iter_time": 2000,
|
||||||
|
"partitions": [ "8c2c2b92-1070-455d-b76a-56263bab24aa" ],
|
||||||
|
"encryption_password": $pw_esc
|
||||||
|
}
|
||||||
|
_EOF_
|
||||||
|
)
|
||||||
|
|
||||||
echo "%wheel ALL=(ALL:ALL) ALL" > /etc/sudoers.d/wheel
|
cat <<_EOF_ >user_configuration.json
|
||||||
|
{
|
||||||
|
"archinstall-language": "English",
|
||||||
|
"audio_config": { "audio": "pipewire" },
|
||||||
|
"bootloader": "systemd-boot",
|
||||||
|
"disk_config": {
|
||||||
|
"btrfs_options": { "snapshot_config": { "type": "Snapper" } },
|
||||||
|
"config_type": "default_layout",
|
||||||
|
"device_modifications": [{
|
||||||
|
"device": "$disk",
|
||||||
|
"partitions": [
|
||||||
|
{ "btrfs": [], "dev_path": null, "flags": ["boot", "esp"], "fs_type": "fat32", "mount_options": [], "mountpoint": "/boot", "obj_id": "ea21d3f2-82bb-49cc-ab5d-6f81ae94e18d", "size": { "sector_size": { "unit": "B", "value": 512 }, "unit": "B", "value": $boot_size }, "start": { "sector_size": { "unit": "B", "value": 512 }, "unit": "B", "value": $mib }, "status": "create", "type": "primary" },
|
||||||
|
{ "btrfs": [ {"mountpoint": "/", "name": "@"}, {"mountpoint": "/home", "name": "@home"}, {"mountpoint": "/var/log", "name": "@log"}, {"mountpoint": "/var/cache/pacman/pkg", "name": "@pkg"} ], "dev_path": null, "flags": [], "fs_type": "btrfs", "mount_options": ["compress=zstd"], "mountpoint": null, "obj_id": "8c2c2b92-1070-455d-b76a-56263bab24aa", "size": { "sector_size": { "unit": "B", "value": 512 }, "unit": "B", "value": $main_size }, "start": { "sector_size": { "unit": "B", "value": 512 }, "unit": "B", "value": $main_start }, "status": "create", "type": "primary" }
|
||||||
|
],
|
||||||
|
"wipe": true
|
||||||
|
}]$disk_enc
|
||||||
|
},
|
||||||
|
"hostname": "$hostname",
|
||||||
|
"kernels": ["linux"],
|
||||||
|
"network_config": { "type": "iso" },
|
||||||
|
"ntp": true,
|
||||||
|
"parallel_downloads": 8,
|
||||||
|
"swap": true,
|
||||||
|
"timezone": "$timezone",
|
||||||
|
"locale_config": { "kb_layout": "$keyboard", "sys_enc": "UTF-8", "sys_lang": "en_US.UTF-8" },
|
||||||
|
"mirror_config": {
|
||||||
|
"custom_servers": [
|
||||||
|
{"url": "https://geo.mirror.pkgbuild.com/\$repo/os/\$arch"},
|
||||||
|
{"url": "https://mirror.rackspace.com/archlinux/\$repo/os/\$arch"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"packages": ["base-devel", "git", "snapper"],
|
||||||
|
"profile_config": { "gfx_driver": null, "greeter": null, "profile": {} },
|
||||||
|
"version": "3.0.9"
|
||||||
|
}
|
||||||
|
_EOF_
|
||||||
|
}
|
||||||
|
|
||||||
systemctl enable NetworkManager
|
# ==========================================
|
||||||
|
# MAIN
|
||||||
|
# ==========================================
|
||||||
|
|
||||||
EOF
|
if [[ $(tty) == "/dev/tty1" ]]; then
|
||||||
|
run_configurator
|
||||||
echo "========================"
|
clear
|
||||||
echo " Installation terminée"
|
echo "Installing base system..."
|
||||||
echo "========================"
|
install_base_system
|
||||||
reboot
|
echo "Base installation complete. You can now reboot or chroot into /mnt."
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user