#!/usr/bin/env nu 
# Info: Prepare for Provisioning installation
# Author: JesusPerezLorenzo 
# Release: 1.0.2
# Date: 14-11-2023

use lib_provisioning/cmd/env.nu * 
#use lib_provisioning/cmd/lib.nu *

use lib_provisioning/utils/ui.nu *

print $"(_ansi green_bold)Provisioning(_ansi reset) with ($env.PROVISIONING_VARS)" 

#let defs = load_defs

let make_pack = ($env.PROVISIONING | path join "distro" | path join "pack")
if ($make_pack | path exists) { 
    ^$"($make_pack)" 
    let pack_path = ("/tmp" | path join $"($env.PROVISIONING_NAME).tar.gz") 
    if ($pack_path | path exists ) { 
       ^cp -pr $pack_path $env.PROVISIONING_WK_ENV_PATH
       print $"\npack saved in ($env.PROVISIONING_WK_ENV_PATH)"
    }
} else if ($env.PROVISIONING | path exists) { 
    ^cp -pr $env.PROVISIONING $env.PROVISIONING_WK_ENV_PATH
} else { 
    print "Error: no PROVISIONING found in environment"
}
