mirror of
https://github.com/khairul169/vaulterm.git
synced 2025-04-28 16:49:39 +07:00
32 lines
582 B
Go
32 lines
582 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"rul.sh/vaulterm/server/lib"
|
|
)
|
|
|
|
func CheckAndCreateEnvFile() error {
|
|
// Check if .env file exists
|
|
if _, err := os.Stat(".env"); !os.IsNotExist(err) {
|
|
return nil
|
|
}
|
|
|
|
// File doesn't exist, so create it
|
|
randomKey, err := lib.GenerateRandomKey()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Write the random key to the .env file
|
|
envContent := fmt.Sprintf("ENCRYPTION_KEY=%s\n", randomKey)
|
|
err = os.WriteFile(".env", []byte(envContent), 0644)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(".env file created with ENCRYPTION_KEY.")
|
|
|
|
return nil
|
|
}
|