Updated the install script

This commit is contained in:
Tyler Kelley 2024-05-18 19:24:55 -05:00
parent 85fcb2300e
commit f6213d5513

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ -n "$(cat /etc/os-release | grep -i nixos)" ]; then if [ -n "$(grep -i nixos < /etc/os-release)" ]; then
echo "Verified this is NixOS." echo "Verified this is NixOS."
echo "-----" echo "-----"
else else
@ -10,22 +10,27 @@ fi
if command -v git &> /dev/null; then if command -v git &> /dev/null; then
echo "Git is installed, continuing with installation." echo "Git is installed, continuing with installation."
echo "-----"
else else
echo "Git is not installed. Please install Git and try again." echo "Git is not installed. Please install Git and try again."
echo "Example: nix-shell -p git" echo "Example: nix-shell -p git"
exit exit
fi fi
echo "Default options are in brackets []"
echo "Just press enter to select the default"
sleep 2
echo "-----" echo "-----"
echo "Ensure In Home Directory" echo "Ensure In Home Directory"
cd cd || exit
echo "-----" echo "-----"
read -p "Enter Your New Hostname: [ hyprnix ] " hostName read -rp "Enter Your New Hostname: [ default ] " hostName
if [ -z "$hostName" ]; then if [ -z "$hostName" ]; then
hostName="hyprnix" hostName="default"
fi fi
echo "-----" echo "-----"
@ -35,12 +40,12 @@ if [ -d "zaneyos" ]; then
echo "ZaneyOS exists, backing up to .config/zaneyos-backups folder." echo "ZaneyOS exists, backing up to .config/zaneyos-backups folder."
if [ -d ".config/zaneyos-backups" ]; then if [ -d ".config/zaneyos-backups" ]; then
echo "Moving current version of ZaneyOS to backups folder." echo "Moving current version of ZaneyOS to backups folder."
mv $HOME/zaneyos .config/zaneyos-backups/$backupname mv "$HOME"/zaneyos .config/zaneyos-backups/"$backupname"
sleep 1 sleep 1
else else
echo "Creating the backups folder & moving ZaneyOS to it." echo "Creating the backups folder & moving ZaneyOS to it."
mkdir -p .config/zaneyos-backups mkdir -p .config/zaneyos-backups
mv $HOME/zaneyos .config/zaneyos-backups/$backupname mv "$HOME"/zaneyos .config/zaneyos-backups/"$backupname"
sleep 1 sleep 1
fi fi
else else
@ -52,42 +57,16 @@ echo "-----"
echo "Cloning & Entering ZaneyOS Repository" echo "Cloning & Entering ZaneyOS Repository"
git clone https://gitlab.com/zaney/zaneyos.git git clone https://gitlab.com/zaney/zaneyos.git
cd zaneyos cd zaneyos || exit
mkdir hosts/$hostName mkdir hosts/"$hostName"
cp hosts/default/*.nix hosts/$hostName cp hosts/default/*.nix hosts/"$hostName"
git add . git add .
sed -i "/^\s*setHostname[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$hostName\"/" ./hosts/$hostName/options.nix
sed -i "/^\s*host[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$hostName\"/" ./flake.nix sed -i "/^\s*host[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$hostName\"/" ./flake.nix
echo "-----" echo "-----"
echo "Default options are in brackets []" installusername=$("$USER")
echo "Just press enter to select the default" sed -i "/^\s*username[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$installusername\"/" ./flake.nix
sleep 2
echo "-----"
installusername=$(echo $USER)
read -p "Enter Your Username: [ $installusername ] " userName
if [ -z "$userName" ]; then
userName=$(echo $USER)
else
if [ $installusername != $userName ]; then
echo "This will create a hashedPassword for the new user in the options file."
while true; do
read -s -p "Enter New User Password: " newPass
read -s -p "Enter New User Password Again: " newPass2
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
sed -i "/^\s*setUsername[[:space:]]*=[[:space:]]*\"/s/\"\(.*\)\"/\"$userName\"/" ./hosts/$hostName/options.nix
echo "-----" echo "-----"
@ -97,19 +76,10 @@ sudo nixos-generate-config --show-hardware-config > ./hosts/$hostName/hardware.n
echo "-----" echo "-----"
echo "Setting Required Nix Settings & Committing Changes" echo "Setting Required Nix Settings & Committing Changes"
git add .
git commit -am "Add new hosts folder and all the new settings"
NIX_CONFIG="experimental-features = nix-command flakes" NIX_CONFIG="experimental-features = nix-command flakes"
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 "-----" echo "-----"
echo "ZaneyOS Has Been Setup" echo "ZaneyOS Has Been Setup"
echo "Make Sure To Change Your Options In hosts/<yourhostname>" echo "Please Edit Your Hosts Files"
echo "To Install Run: sudo nixos-rebuild switch --flake .#<yourhostname>" echo "Then Run: sudo nixos-rebuild switch --flake .#${hostName}"