2023-08-27 15:30:51 +01:00
package main
import (
"log/slog"
"os"
"path/filepath"
"github.com/AlexSSD7/linsk/cmd/imgbuilder/builder"
"github.com/spf13/cobra"
)
var rootCmd = & cobra . Command {
2023-08-29 10:37:52 +01:00
Use : "imgbuilder" ,
Short : "Build an Alpine Linux image for Linsk. A base Alpine VM disc image is required." ,
Args : cobra . ExactArgs ( 2 ) ,
2023-08-27 15:30:51 +01:00
Run : func ( cmd * cobra . Command , args [ ] string ) {
baseISOPath := filepath . Clean ( args [ 0 ] )
outImagePath := filepath . Clean ( args [ 1 ] )
bc , err := builder . NewBuildContext ( slog . With ( "caller" , "build-context" ) , baseISOPath , outImagePath , vmDebugFlag )
if err != nil {
2023-08-29 10:59:50 +01:00
slog . Error ( "Failed to create a new build context" , "error" , err . Error ( ) )
2023-08-27 15:30:51 +01:00
os . Exit ( 1 )
}
err = bc . BuildWithInterruptHandler ( )
if err != nil {
2023-08-29 10:59:50 +01:00
slog . Error ( "Failed to build an image" , "error" , err . Error ( ) )
2023-08-27 15:30:51 +01:00
os . Exit ( 1 )
}
slog . Info ( "Success" )
} ,
}
var vmDebugFlag bool
func init ( ) {
slog . SetDefault ( slog . New ( slog . NewTextHandler ( os . Stderr , nil ) ) )
rootCmd . PersistentFlags ( ) . BoolVar ( & vmDebugFlag , "vmdebug" , false , "Enable VM debug mode. This will open an accessible VM monitor. You can log in with root user and no password." )
}
func main ( ) {
err := rootCmd . Execute ( )
if err != nil {
os . Exit ( 1 )
}
}