zaneyos/install-zaneyos.sh

86 lines
2.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2024-05-19 02:24:55 +02:00
if [ -n "$(grep -i nixos < /etc/os-release)" ]; then
echo "Verified this is NixOS."
echo "-----"
else
2024-05-19 02:24:55 +02:00
echo "This is not NixOS or the distribution information is not available."
exit
fi
if command -v git &> /dev/null; then
2024-05-19 02:24:55 +02:00
echo "Git is installed, continuing with installation."
echo "-----"
else
2024-05-19 02:24:55 +02:00
echo "Git is not installed. Please install Git and try again."
echo "Example: nix-shell -p git"
exit
fi
2024-05-19 02:24:55 +02:00
echo "Default options are in brackets []"
echo "Just press enter to select the default"
sleep 2
echo "-----"
echo "Ensure In Home Directory"
2024-05-19 02:24:55 +02:00
cd || exit
echo "-----"
2024-05-19 02:24:55 +02:00
read -rp "Enter Your New Hostname: [ default ] " hostName
2024-04-04 03:16:41 +02:00
if [ -z "$hostName" ]; then
2024-05-19 02:24:55 +02:00
hostName="default"
fi
echo "-----"
backupname=$(date "+%Y-%m-%d-%H-%M-%S")
if [ -d "zaneyos" ]; then
echo "ZaneyOS exists, backing up to .config/zaneyos-backups folder."
if [ -d ".config/zaneyos-backups" ]; then
echo "Moving current version of ZaneyOS to backups folder."
2024-05-19 02:24:55 +02:00
mv "$HOME"/zaneyos .config/zaneyos-backups/"$backupname"
sleep 1
2024-03-02 22:09:30 +01:00
else
echo "Creating the backups folder & moving ZaneyOS to it."
mkdir -p .config/zaneyos-backups
2024-05-19 02:24:55 +02:00
mv "$HOME"/zaneyos .config/zaneyos-backups/"$backupname"
sleep 1
2024-03-02 22:09:30 +01:00
fi
else
echo "Thank you for choosing ZaneyOS."
echo "I hope you find your time here enjoyable!"
fi
echo "-----"
2024-04-04 03:26:15 +02:00
echo "Cloning & Entering ZaneyOS Repository"
git clone https://gitlab.com/zaney/zaneyos.git
2024-05-19 02:24:55 +02:00
cd zaneyos || exit
mkdir hosts/"$hostName"
cp hosts/default/*.nix hosts/"$hostName"
2024-05-19 20:13:37 +02:00
git config --global user.name "installer"
git config --global user.email "installer@gmail.com"
git add .
sed -i "/^\s*host[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$hostName\"/" ./flake.nix
2024-04-04 03:26:15 +02:00
echo "-----"
2024-05-19 20:20:23 +02:00
installusername=$(echo $USER)
2024-05-19 02:24:55 +02:00
sed -i "/^\s*username[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$installusername\"/" ./flake.nix
echo "-----"
2024-02-19 10:53:07 +01:00
echo "Generating The Hardware Configuration"
2024-04-04 03:16:41 +02:00
sudo nixos-generate-config --show-hardware-config > ./hosts/$hostName/hardware.nix
2024-02-19 10:53:07 +01:00
echo "-----"
echo "Setting Required Nix Settings Then Going To Install"
2024-04-18 23:00:04 +02:00
NIX_CONFIG="experimental-features = nix-command flakes"
2024-03-02 22:09:30 +01:00
echo "-----"
sudo nixos-rebuild switch --flake ~/zaneyos/#${hostName}