diff --git a/.gitignore b/.gitignore index 66fd13c..9fca046 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,8 @@ # Dependency directories (remove the comment below to include it) # vendor/ + +# Emacs +*~ +.#* +\#*# \ No newline at end of file diff --git a/cmd/create/create.go b/cmd/create/create.go index 7bfb332..d3a7cc2 100644 --- a/cmd/create/create.go +++ b/cmd/create/create.go @@ -3,6 +3,7 @@ package create import ( "fmt" "os" + "os/exec" "github.com/spf13/cobra" @@ -23,7 +24,13 @@ func NewCmdCreate() *cobra.Command { createCmd := &cobra.Command{ Use: "create", Short: "Create a Canasta installation", - Long: `Creates a Canasta installation using an orchestrator of your choice.`, + Long: "Creates a Canasta installation using an orchestrator of your choice.", + PreRun: func(cmd *cobra.Command, args []string) { + _, err := exec.LookPath("docker-compose") + if err != nil { + logging.Fatal(fmt.Errorf("docker-compose should be installed! (%s)", err)) + } + }, RunE: func(cmd *cobra.Command, args []string) error { if canastaInfo, err = mediawiki.PromptUser(canastaInfo); err != nil { logging.Fatal(err) diff --git a/internal/logging/logging.go b/internal/logging/logging.go index f92404a..3d68157 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "os" + "os/user" "syscall" ) @@ -121,8 +122,18 @@ func init() { directory = "/etc/canasta" confFile = directory + "/conf.json" + // Verifies that this is running as root + currentUser, err := user.Current() + if err != nil { + errReport := fmt.Errorf("Unable to get the current user: %s", err) + Fatal(errReport) + } + if currentUser.Username != "root" { + Fatal(fmt.Errorf("This program must be run as root.")) + } + // Checks for the conf.json file - _, err := os.Stat(confFile) + _, err = os.Stat(confFile) if os.IsNotExist(err) { // Check for the configuration folder _, err = os.Stat(directory)