zaneyos/install-zaneyos.sh

115 lines
3.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
if [ -n "$(cat /etc/os-release | grep -i nixos)" ]; then
echo "Verified this is NixOS."
echo "-----"
else
echo "This is not NixOS or the distribution information is not available."
exit
fi
if command -v git &> /dev/null; then
echo "Git is installed, continuing with installation."
else
echo "Git is not installed. Please install Git and try again."
echo "Example: nix-shell -p git"
2024-04-13 08:25:33 +02:00
exit
fi
echo "-----"
echo "Ensure In Home Directory"
2024-04-04 03:26:15 +02:00
cd
echo "-----"
2024-04-04 03:16:41 +02:00
read -p "Enter Your New Hostname: [ hyprnix ] " hostName
if [ -z "$hostName" ]; then
hostName="hyprnix"
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."
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
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
cd zaneyos
mkdir hosts/$hostName
cp hosts/default/*.nix hosts/$hostName
2024-04-04 04:29:41 +02:00
git add .
2024-04-04 03:26:15 +02:00
sed -i "/^\s*setHostname[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$hostName\"/" ./hosts/$hostName/options.nix
sed -i "/^\s*host[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$hostName\"/" ./flake.nix
2024-04-04 03:26:15 +02:00
echo "-----"
echo "Default options are in brackets []"
echo "Just press enter to select the default"
sleep 2
echo "-----"
installusername=$(echo $USER)
read -p "Enter Your Username: [ $installusername ] " userName
if [ -z "$userName" ]; then
userName=$(echo $USER)
else
2024-03-02 22:09:30 +01:00
if [ $installusername != $userName ]; then
echo "This will create a hashedPassword for the new user in the options file."
while true; do
2024-03-02 22:29:19 +01:00
read -s -p "Enter New User Password: " newPass
read -s -p "Enter New User Password Again: " newPass2
2024-03-02 22:09:30 +01:00
if [ $newPass == $newPass2 ]; then
echo "Passwords Match. Setting password."
userPassword=$(mkpasswd -m sha-512 $newPass)
escaped_userPassword=$(echo "$userPassword" | sed 's/\//\\\//g')
sed -i "/^\s*hashedPassword[[:space:]]*=[[:space:]]*\"/s#\"\(.*\)\"#\"$escaped_userPassword\"#" ./system.nix
break
fi
done
fi
fi
2024-04-04 03:16:41 +02:00
sed -i "/^\s*setUsername[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$userName\"/" ./hosts/$hostName/options.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 "-----"
2024-04-18 23:00:04 +02:00
echo "Setting Required Nix Settings & Committing Changes"
git add .
2024-04-04 04:29:41 +02:00
git commit -am "Add new hosts folder and all the new settings"
2024-04-18 23:00:04 +02:00
NIX_CONFIG="experimental-features = nix-command flakes"
2024-03-02 22:09:30 +01:00
if [ $userName != $installusername ]; then
cd
cp -r zaneyos /home/$userName/
sudo chown -R $userName:users /home/$userName/zaneyos
echo "Ensuring ZaneyOS repository is in your users HOME directory."
fi
echo "-----"
2024-04-18 23:00:04 +02:00
echo "ZaneyOS Has Been Setup"
echo "Make Sure To Change Your Options In hosts/<yourhostname>"
echo "To Install Run: sudo nixos-rebuild switch --flake .#<yourhostname>"