87 lines
2.7 KiB
Fish
Executable file
87 lines
2.7 KiB
Fish
Executable file
#!/bin/env fish
|
|
function runSetup
|
|
set -l dir (status dirname)
|
|
source "$dir/../Scripts/config.fish"
|
|
source "$dir/../Scripts/hooks.fish"
|
|
|
|
if [ -z "$CONFIG_NAME" ]
|
|
selectProfile config
|
|
set -x CONFIG_NAME "$config"
|
|
end
|
|
|
|
set -l mountDir (getOSConfig partition.rootDir)
|
|
set -l projectRoot (realpath "$dir/../../..")
|
|
set -l projectName (basename "$projectRoot")
|
|
set -l PROJECT_CLONE_ROOT "/opt/$(basename "$projectName")"
|
|
set -l script (mktemp)
|
|
chmod +x "$script"
|
|
|
|
if not type -q runChroot
|
|
function runChroot -S
|
|
command chroot $argv
|
|
end
|
|
end
|
|
|
|
function getCloneFile -S -a path
|
|
set -l relativeDir (realpath --relative-to "$projectRoot" "$dir")
|
|
set -l relativePath (realpath --relative-to "$dir" "$path")
|
|
echo "$PROJECT_CLONE_ROOT/$relativeDir/$relativePath"
|
|
end
|
|
|
|
function runInOS -S
|
|
set -l script /root/run_once
|
|
wrapScript $argv | chroot "$mountDir" tee "$script" >/dev/null
|
|
and runChroot "$mountDir" chmod +x "$script"
|
|
and runChroot "$mountDir" "$script"
|
|
and runChroot "$mountDir" rm "$script"
|
|
end
|
|
|
|
function wrapScript -S
|
|
printf %s\n \
|
|
"cd $PROJECT_CLONE_ROOT" \
|
|
"$argv"
|
|
end
|
|
|
|
echo "Partitioning drives..."
|
|
and getOSConfig partition.script >"$script"
|
|
and "$script"
|
|
and rm "$script"
|
|
|
|
# Copy `nixpkgs` channel
|
|
and echo "Preparing nix..."
|
|
|
|
and begin
|
|
set -l channelDir /nix/var/nix/profiles/per-user/root/channels/nixpkgs
|
|
mkdir -p (dirname "$mountDir/$channelDir")
|
|
cp -r "$channelDir" "$mountDir/$channelDir"
|
|
end
|
|
|
|
and echo "Installing dependencies..."
|
|
and runHook --force installValhallaDeps 'Please set up a function `installValhallaDeps` for installing `fish`, `git`, `jq`, `nix`, `sudo` and `tmux`.'
|
|
|
|
and echo "Cloning project..."
|
|
and source "$dir/../../copy-repo.fish" "$mountDir$PROJECT_CLONE_ROOT"
|
|
runChroot "$mountDir" git config --system --add safe.directory "$PROJECT_CLONE_ROOT"
|
|
and runHook setupOS
|
|
|
|
and echo "Preparing auto-login..."
|
|
and runHook --force autologin "Please set up a function `autologin` for setting up autologin for the `root` user"
|
|
|
|
and begin
|
|
set -l script (string escape (getCloneFile (getInstallerScript)))
|
|
|
|
wrapScript (
|
|
string join " " \
|
|
"INSTALLER_SCRIPT=$(string escape "$script")" \
|
|
"CONFIG_NAME=$(string escape "$CONFIG_NAME")" \
|
|
(string escape $script))
|
|
|
|
end | runChroot "$mountDir" tee /root/.bash_profile >/dev/null
|
|
|
|
and echo "Setup finished!"
|
|
and echo "This machine will reboot in 5 seconds..."
|
|
and echo "Press CTRL-C to abort..."
|
|
and sleep 5
|
|
and systemctl reboot
|
|
end
|