2024-07-13 07:52:30 +00:00
|
|
|
#!/bin/env fish
|
2024-07-16 13:22:15 +00:00
|
|
|
function runSetup
|
2024-07-13 07:52:30 +00:00
|
|
|
set -l dir (status dirname)
|
2024-11-01 12:12:16 +00:00
|
|
|
source "$dir/../../lib/settings.fish"
|
|
|
|
source "$dir/../../lib/hooks.fish"
|
2024-11-01 13:27:32 +00:00
|
|
|
source "$dir/../../lib/nix.fish"
|
2024-09-30 12:57:03 +00:00
|
|
|
|
|
|
|
if [ -z "$CONFIG_NAME" ]
|
|
|
|
selectProfile config
|
|
|
|
set -x CONFIG_NAME "$config"
|
|
|
|
end
|
|
|
|
|
2024-09-22 15:50:05 +00:00
|
|
|
set -l mountDir (getOSConfig partition.rootDir)
|
2024-07-13 08:59:09 +00:00
|
|
|
set -l projectRoot (realpath "$dir/../../..")
|
|
|
|
set -l projectName (basename "$projectRoot")
|
|
|
|
set -l PROJECT_CLONE_ROOT "/opt/$(basename "$projectName")"
|
2024-07-13 09:23:14 +00:00
|
|
|
set -l script (mktemp)
|
2024-09-12 16:44:14 +00:00
|
|
|
chmod +x "$script"
|
2024-07-13 08:59:09 +00:00
|
|
|
|
2024-07-16 20:10:42 +00:00
|
|
|
if not type -q runChroot
|
|
|
|
function runChroot -S
|
|
|
|
command chroot $argv
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-13 10:36:10 +00:00
|
|
|
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
|
|
|
|
|
2024-07-16 14:13:34 +00:00
|
|
|
function runInOS -S
|
2024-10-06 19:25:34 +00:00
|
|
|
set -l script /root/run_once
|
|
|
|
wrapScript $argv | chroot "$mountDir" tee "$script" >/dev/null
|
2024-09-12 16:52:03 +00:00
|
|
|
and runChroot "$mountDir" chmod +x "$script"
|
|
|
|
and runChroot "$mountDir" "$script"
|
|
|
|
and runChroot "$mountDir" rm "$script"
|
2024-07-16 14:13:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function wrapScript -S
|
|
|
|
printf %s\n \
|
|
|
|
"cd $PROJECT_CLONE_ROOT" \
|
|
|
|
"$argv"
|
|
|
|
end
|
|
|
|
|
2024-09-22 22:23:41 +00:00
|
|
|
echo "Partitioning drives..."
|
2024-10-06 19:25:34 +00:00
|
|
|
and getOSConfig partition.script >"$script"
|
2024-09-12 16:44:14 +00:00
|
|
|
and "$script"
|
|
|
|
and rm "$script"
|
2024-07-13 10:36:10 +00:00
|
|
|
|
2024-07-13 13:12:35 +00:00
|
|
|
# Copy `nixpkgs` channel
|
2024-09-22 22:23:41 +00:00
|
|
|
and echo "Preparing nix..."
|
|
|
|
|
2024-07-13 13:12:35 +00:00
|
|
|
and begin
|
2024-11-01 13:27:32 +00:00
|
|
|
mkdir -p (dirname "$mountDir/$nixPkgsDir")
|
|
|
|
cp -r "$nixPkgsDir" "$mountDir/$nixPkgsDir"
|
2024-07-13 13:12:35 +00:00
|
|
|
end
|
|
|
|
|
2024-09-22 22:23:41 +00:00
|
|
|
and echo "Installing dependencies..."
|
2024-10-24 16:20:13 +00:00
|
|
|
and runHook --force installValhallaDeps 'Please set up a function `installValhallaDeps` for installing `fish`, `git`, `jq`, `nix`, `sudo` and `tmux`.'
|
2024-09-22 22:23:41 +00:00
|
|
|
|
|
|
|
and echo "Cloning project..."
|
2024-11-01 12:12:16 +00:00
|
|
|
and source "$dir/../../lib/copy-repo.fish" "$mountDir$PROJECT_CLONE_ROOT"
|
2024-09-12 19:47:13 +00:00
|
|
|
runChroot "$mountDir" git config --system --add safe.directory "$PROJECT_CLONE_ROOT"
|
2024-10-12 15:19:59 +00:00
|
|
|
and runHook setupOS
|
2024-09-22 22:23:41 +00:00
|
|
|
|
|
|
|
and echo "Preparing auto-login..."
|
2024-10-24 16:20:13 +00:00
|
|
|
and runHook --force autologin "Please set up a function `autologin` for setting up autologin for the `root` user"
|
2024-07-16 20:15:37 +00:00
|
|
|
|
2024-07-13 10:36:10 +00:00
|
|
|
and begin
|
2024-07-13 11:23:16 +00:00
|
|
|
set -l script (string escape (getCloneFile (getInstallerScript)))
|
2024-09-12 19:47:29 +00:00
|
|
|
|
|
|
|
wrapScript (
|
|
|
|
string join " " \
|
|
|
|
"CONFIG_NAME=$(string escape "$CONFIG_NAME")" \
|
|
|
|
(string escape $script))
|
|
|
|
|
2024-10-06 19:25:34 +00:00
|
|
|
end | runChroot "$mountDir" tee /root/.bash_profile >/dev/null
|
2024-07-13 10:36:10 +00:00
|
|
|
|
2024-07-13 07:52:30 +00:00
|
|
|
and echo "Setup finished!"
|
2024-07-15 23:05:06 +00:00
|
|
|
and echo "This machine will reboot in 5 seconds..."
|
|
|
|
and echo "Press CTRL-C to abort..."
|
|
|
|
and sleep 5
|
|
|
|
and systemctl reboot
|
2024-07-13 07:52:30 +00:00
|
|
|
end
|