Skip to content

Commit

Permalink
Add checks to make sure canasta's requirements are met
Browse files Browse the repository at this point in the history
* Check that we're running as root (though, I'm not sure it is necessary when you are running a
  non-root container system)
* Check that we have docker-compose installed before attempting create
* Oh, and btw, update gitignore for emacs files
  • Loading branch information
Mark A. Hershberger authored and Mark A. Hershberger committed Aug 19, 2022
1 parent 636a4fd commit 53fc300
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Emacs
*~
.#*
\#*#
9 changes: 8 additions & 1 deletion cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package create
import (
"fmt"
"os"
"os/exec"

"github.com/spf13/cobra"

Expand All @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"os/user"
"syscall"
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 53fc300

Please sign in to comment.