guix_jerome/install.sh

134 lines
3.4 KiB
Bash
Raw Normal View History

2024-07-09 16:25:38 +02:00
#!/run/current-system/profile/bin/bash
2024-07-09 16:15:18 +02:00
#
# Guix Simplified Installer
#
# Copyright (C) 2024 Adrien Bourmault <neox@a-lec.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set +x
set -e
# Définition des couleurs
RED='\033[0;31m'
GREEN='\033[0;32m'
2024-07-09 16:29:31 +02:00
LIGHT_RED='\033[1;31m'
LIGHT_GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
2024-07-09 16:15:18 +02:00
NC='\033[0m' # No Color
2024-07-09 16:29:31 +02:00
echo -e "${LIGHT_RED}Welcome to Guix Simplified Installer${NC}"
2024-07-09 16:27:19 +02:00
echo -e "${NC}Copyright (C) 2024 Adrien Bourmault <neox@a-lec.org>${NC}"
echo -e "${NC}This program is free software, released under the GNU AGPL version 3 or later.${NC}"
2024-07-09 16:15:18 +02:00
# Chemin vers le disque
DISK="$1"
2024-07-10 16:21:12 +02:00
if [[ $DISK =~ [0-9]$ ]]; then
PART_SUFFIX="p"
else
PART_SUFFIX=""
fi
2024-07-09 16:15:18 +02:00
# Vérification de l'existence du disque
if [ ! -b "$DISK" ]; then
echo -e "${RED}There is no such disk as $DISK !${NC}"
2024-07-09 16:15:18 +02:00
exit 1
fi
2024-07-09 16:27:19 +02:00
echo -e -n "${BLUE}Downloading configuration...${NC}"
2024-07-09 16:22:34 +02:00
2024-07-09 16:24:26 +02:00
rm -f config.scm
2024-07-09 16:35:03 +02:00
wget --quiet forge.chalec.org/neox/guix_jerome/raw/branch/master/config.scm
2024-07-09 16:22:34 +02:00
2024-07-09 16:27:19 +02:00
echo -e "${GREEN}OK${NC}"
echo -e -n "${BLUE}Creating disk layout...${NC}"
2024-07-09 16:15:18 +02:00
parted -s "$DISK" mklabel gpt
parted -s "$DISK" mkpart primary fat32 1MiB 5%
parted -s "$DISK" mkpart primary ext4 5% 100%
2024-07-09 16:27:19 +02:00
echo -e "${GREEN}OK${NC}"
2024-07-09 16:32:37 +02:00
echo -e "${BLUE}Setting up root partition encryption...${NC}"
2024-07-09 16:15:18 +02:00
2024-07-10 16:21:12 +02:00
cryptsetup luksFormat "${DISK}${PART_SUFFIX}2"
2024-07-09 16:15:18 +02:00
2024-07-09 16:27:19 +02:00
echo -e "${GREEN}OK${NC}"
2024-07-09 16:32:37 +02:00
echo -e "${BLUE}Unlocking root partition...${NC}"
2024-07-09 16:15:18 +02:00
2024-07-10 16:21:12 +02:00
cryptsetup open "${DISK}${PART_SUFFIX}2" ROOT
2024-07-09 16:15:18 +02:00
2024-07-09 16:27:19 +02:00
echo -e "${GREEN}OK${NC}"
2024-07-09 16:32:37 +02:00
echo -e "${BLUE}Formatting disks partitions...${NC}"
2024-07-09 16:15:18 +02:00
2024-07-10 16:21:12 +02:00
mkfs.vfat "${DISK}${PART_SUFFIX}1"
2024-07-09 16:15:18 +02:00
mkfs.ext4 -L ROOT /dev/mapper/ROOT
2024-07-09 16:27:19 +02:00
echo -e "${GREEN}OK${NC}"
echo -e -n "${BLUE}Updating disk configuration...${NC}"
2024-07-09 16:15:18 +02:00
2024-07-10 16:21:12 +02:00
UUID=$(blkid -o value -s UUID "${DISK}${PART_SUFFIX}2")
2024-07-09 16:15:18 +02:00
sed -i "s/CHANGE_THIS_UUID/${UUID}/g" config.scm
2024-07-10 16:21:12 +02:00
UUID2=$(blkid -o value -s UUID "${DISK}${PART_SUFFIX}1")
2024-07-09 16:15:18 +02:00
sed -i "s/CHANGE_THIS_DISK/${UUID2}/g" config.scm
2024-07-09 16:27:19 +02:00
echo -e "${GREEN}OK${NC}"
echo -e -n "${BLUE}Mounting disks...${NC}"
2024-07-09 16:15:18 +02:00
mount LABEL=ROOT /mnt
mkdir -p /mnt/boot/efi
2024-07-10 16:21:12 +02:00
mount "${DISK}${PART_SUFFIX}1" /mnt/boot/efi
2024-07-09 16:15:18 +02:00
2024-07-09 16:27:19 +02:00
echo -e "${GREEN}OK${NC}"
echo -e -n "${BLUE}Moving configuration to its final location...${NC}"
2024-07-09 16:15:18 +02:00
mkdir /mnt/etc
cp config.scm /mnt/etc/config.scm
sed -i '66d' /mnt/etc/config.scm
2024-07-09 16:15:18 +02:00
2024-07-09 16:27:19 +02:00
echo -e "${GREEN}OK${NC}"
2024-07-09 16:15:18 +02:00
2024-07-10 16:23:35 +02:00
echo -e "${BLUE}Installing GNU Guix...${NC}"
2024-07-09 16:15:18 +02:00
herd start cow-store /mnt
2024-07-10 17:39:23 +02:00
install_guix() {
tmpfile=$(mktemp)
2024-07-10 17:59:34 +02:00
guix system init config.scm /mnt >(tee "$tmpfile")
2024-07-10 17:39:23 +02:00
exit_code=$?
output=$(tail -n 3 "$tmpfile")
rm -f "$tmpfile"
if [[ $exit_code -ne 0 && $output == *"died unexpectedly"* ]]; then
return 1
else
return 0
fi
}
max_retries=5
attempt=0
until install_guix; do
attempt=$((attempt + 1))
if [[ $attempt -ge $max_retries ]]; then
echo -e "${RED}Installation has failed${NC}"
exit 1
fi
echo -e "${BLUE}Trying installing GNU Guix again...${NC}"
done