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 14:32:43 +00:00
|
|
|
source "$dir/../../lib/action.fish"
|
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-11-01 14:32:43 +00:00
|
|
|
function setupAction -V projectRoot -V PROJECT_CLONE_ROOT
|
|
|
|
source "$dir/../../lib/hooks.fish"
|
2024-12-04 18:02:05 +00:00
|
|
|
source "$dir/../../lib/restoration.fish"
|
2024-11-01 14:32:43 +00:00
|
|
|
source "$dir/../../lib/settings.fish"
|
|
|
|
set -l mountDir (getOSConfig partition.rootDir)
|
|
|
|
set -l script (mktemp)
|
|
|
|
chmod +x "$script"
|
|
|
|
|
|
|
|
if not type -q runChroot
|
|
|
|
function runChroot -S
|
|
|
|
command chroot $argv
|
|
|
|
end
|
2024-07-16 20:10:42 +00:00
|
|
|
end
|
|
|
|
|
2024-11-01 14:32:43 +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-13 10:36:10 +00:00
|
|
|
|
2024-11-01 14:32:43 +00:00
|
|
|
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
|
2024-07-16 14:13:34 +00:00
|
|
|
|
2024-11-01 14:32:43 +00:00
|
|
|
function wrapScript -S
|
|
|
|
printf %s\n \
|
|
|
|
"cd $PROJECT_CLONE_ROOT" \
|
|
|
|
"$argv"
|
|
|
|
end
|
2024-07-16 14:13:34 +00:00
|
|
|
|
2024-12-04 18:02:05 +00:00
|
|
|
initBackupConfig --action restore
|
|
|
|
|
|
|
|
if [ -n "$VALHALLA_BACKUP_SERVER_KEY" ]
|
|
|
|
set -l knownHosts /root/.ssh/known_hosts
|
|
|
|
cp "$VALHALLA_BACKUP_SERVER_KEY" "$mountDir$VALHALLA_BACKUP_SERVER_KEY"
|
|
|
|
cp $knownHosts "$mountDir$knownHosts"
|
|
|
|
end
|
|
|
|
|
2024-11-01 14:32:43 +00:00
|
|
|
and echo "Cloning project..."
|
|
|
|
and source "$dir/../../lib/copy-repo.fish" "$mountDir$PROJECT_CLONE_ROOT"
|
|
|
|
runChroot "$mountDir" git config --system --add safe.directory "$PROJECT_CLONE_ROOT"
|
2024-12-05 08:25:52 +00:00
|
|
|
and runHook --force bootstrapSetup "Please set up a function `bootstrapSetup` for installing `fish` into the "
|
2024-11-01 14:32:43 +00:00
|
|
|
and runHook setupOS
|
2024-07-13 10:36:10 +00:00
|
|
|
|
2024-11-01 14:32:43 +00:00
|
|
|
and echo "Preparing auto-login..."
|
|
|
|
and runHook --force autologin "Please set up a function `autologin` for setting up autologin for the `root` user"
|
2024-09-22 22:23:41 +00:00
|
|
|
|
2024-11-01 14:32:43 +00:00
|
|
|
and begin
|
|
|
|
set -l script (string escape (getCloneFile (getInstallerScript)))
|
2024-07-13 13:12:35 +00:00
|
|
|
|
2024-11-01 14:32:43 +00:00
|
|
|
wrapScript (
|
|
|
|
string join " " \
|
2024-12-04 18:02:05 +00:00
|
|
|
(begin
|
|
|
|
for var in \
|
|
|
|
CONFIG_NAME \
|
|
|
|
VALHALLA_BACKUP_DISABLED \
|
|
|
|
VALHALLA_BACKUP_DIR \
|
|
|
|
VALHALLA_BACKUP_SERVER \
|
|
|
|
VALHALLA_BACKUP_SERVER_PORT \
|
|
|
|
VALHALLA_BACKUP_SERVER_USER \
|
|
|
|
VALHALLA_BACKUP_SERVER_KEY
|
|
|
|
echo "$var=$(string escape "$$var")"
|
|
|
|
end
|
|
|
|
end) \
|
2024-11-01 14:32:43 +00:00
|
|
|
(string escape $script))
|
2024-09-22 22:23:41 +00:00
|
|
|
|
2024-11-01 14:32:43 +00:00
|
|
|
end | runChroot "$mountDir" tee /root/.bash_profile >/dev/null
|
|
|
|
end
|
2024-09-22 22:23:41 +00:00
|
|
|
|
2024-11-04 00:34:22 +00:00
|
|
|
function actionPreRun
|
2024-11-01 14:32:43 +00:00
|
|
|
echo "Partitioning drives..."
|
|
|
|
and getOSConfig partition.script >"$script"
|
|
|
|
and "$script"
|
|
|
|
and rm "$script"
|
|
|
|
end
|
2024-09-12 19:47:29 +00:00
|
|
|
|
2024-11-03 21:36:30 +00:00
|
|
|
function actionPostRun
|
2024-11-01 14:32:43 +00:00
|
|
|
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
|
2024-07-13 10:36:10 +00:00
|
|
|
|
2024-11-01 14:32:43 +00:00
|
|
|
runAction setupAction
|
2024-07-13 07:52:30 +00:00
|
|
|
end
|