mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-29 22:19:31 +02:00
Check root, existing config, pull containers
This commit is contained in:
parent
b78e7a324d
commit
419eb00583
1 changed files with 52 additions and 33 deletions
|
@ -35,16 +35,24 @@ type Config struct {
|
||||||
func main() {
|
func main() {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
// check if the user is root
|
||||||
|
if os.Geteuid() != 0 {
|
||||||
|
fmt.Println("This script must be run as root")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if there is already a config file
|
||||||
|
if _, err := os.Stat("config/config.yml"); err != nil {
|
||||||
config := collectUserInput(reader)
|
config := collectUserInput(reader)
|
||||||
createConfigFiles(config)
|
createConfigFiles(config)
|
||||||
|
|
||||||
if !isDockerInstalled() && runtime.GOOS == "linux" {
|
if !isDockerInstalled() && runtime.GOOS == "linux" {
|
||||||
if shouldInstallDocker() {
|
if shouldInstallDocker() {
|
||||||
// ask user if they want to install docker
|
|
||||||
if readBool(reader, "Would you like to install Docker?", true) {
|
|
||||||
installDocker()
|
installDocker()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Config file already exists... skipping configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
if isDockerInstalled() {
|
if isDockerInstalled() {
|
||||||
|
@ -124,11 +132,11 @@ func collectUserInput(reader *bufio.Reader) Config {
|
||||||
config.EnableEmail = readBool(reader, "Enable email functionality", false)
|
config.EnableEmail = readBool(reader, "Enable email functionality", false)
|
||||||
|
|
||||||
if config.EnableEmail {
|
if config.EnableEmail {
|
||||||
config.EmailSMTPHost = readString(reader, "Enter SMTP host: ", "")
|
config.EmailSMTPHost = readString(reader, "Enter SMTP host", "")
|
||||||
config.EmailSMTPPort = readInt(reader, "Enter SMTP port (default 587): ", 587)
|
config.EmailSMTPPort = readInt(reader, "Enter SMTP port (default 587)", 587)
|
||||||
config.EmailSMTPUser = readString(reader, "Enter SMTP username: ", "")
|
config.EmailSMTPUser = readString(reader, "Enter SMTP username", "")
|
||||||
config.EmailSMTPPass = readString(reader, "Enter SMTP password: ", "")
|
config.EmailSMTPPass = readString(reader, "Enter SMTP password", "")
|
||||||
config.EmailNoReply = readString(reader, "Enter no-reply email address: ", "")
|
config.EmailNoReply = readString(reader, "Enter no-reply email address", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
|
@ -301,6 +309,26 @@ func installDocker() error {
|
||||||
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo &&
|
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo &&
|
||||||
dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
||||||
`)
|
`)
|
||||||
|
case strings.Contains(osRelease, "ID=opensuse") || strings.Contains(osRelease, "ID=\"opensuse-"):
|
||||||
|
installCmd = exec.Command("bash", "-c", `
|
||||||
|
zypper install -y docker docker-compose &&
|
||||||
|
systemctl enable docker
|
||||||
|
`)
|
||||||
|
case strings.Contains(osRelease, "ID=rhel") || strings.Contains(osRelease, "ID=\"rhel"):
|
||||||
|
installCmd = exec.Command("bash", "-c", `
|
||||||
|
dnf remove -y runc &&
|
||||||
|
dnf -y install yum-utils &&
|
||||||
|
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo &&
|
||||||
|
dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin &&
|
||||||
|
systemctl enable docker
|
||||||
|
`)
|
||||||
|
case strings.Contains(osRelease, "ID=amzn"):
|
||||||
|
installCmd = exec.Command("bash", "-c", `
|
||||||
|
yum update -y &&
|
||||||
|
yum install -y docker &&
|
||||||
|
systemctl enable docker &&
|
||||||
|
usermod -a -G docker ec2-user
|
||||||
|
`)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported Linux distribution")
|
return fmt.Errorf("unsupported Linux distribution")
|
||||||
}
|
}
|
||||||
|
@ -319,36 +347,27 @@ func isDockerInstalled() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func pullAndStartContainers() error {
|
func pullAndStartContainers() error {
|
||||||
containers := []string{
|
|
||||||
"traefik:v3.1",
|
|
||||||
"fossorial/pangolin:latest",
|
|
||||||
"fossorial/gerbil:latest",
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, container := range containers {
|
|
||||||
fmt.Printf("Pulling %s...\n", container)
|
|
||||||
cmd := exec.Command("docker", "pull", container)
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return fmt.Errorf("failed to pull %s: %v", container, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Starting containers...")
|
fmt.Println("Starting containers...")
|
||||||
|
|
||||||
// First try docker compose (new style)
|
// First try docker compose (new style)
|
||||||
cmd := exec.Command("docker", "compose", "-f", "docker-compose.yml", "up", "-d")
|
cmd := exec.Command("docker", "compose", "-f", "docker-compose.yml", "pull")
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
|
|
||||||
// If docker compose fails, try docker-compose (legacy style)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd = exec.Command("docker-compose", "-f", "docker-compose.yml", "up", "-d")
|
fmt.Println("Failed to start containers using docker compose, falling back to docker-compose command")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command("docker", "compose", "-f", "docker-compose.yml", "up", "-d")
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to start containers using docker-compose command")
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue