Authentication-Results: mail-b.sr.ht; dkim=pass header.d=secluded.site header.i=@secluded.site Received: from mx.nixnet.email (mx.nixnet.email [94.16.121.167]) by mail-b.sr.ht (Postfix) with ESMTPS id E0BA511F041 for <~whereswaldon/arbor-dev@lists.sr.ht>; Thu, 21 Jul 2022 03:10:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by mx.nixnet.email (Postfix) with ESMTPSA id 8178F20286A; Wed, 20 Jul 2022 23:10:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secluded.site; s=202002021149; t=1658373035; h=from:from:reply-to:subject:subject:to:to:cc:cc; bh=6VfKyOnO5bjcqpprZ2ptlxyqHerMSi8nKz/JaFtsGT8=; b=dzVam3IktaWQ+JkF9ozkVKJsNARRTVfZNSl58Rh0/1QxXz7g6Q8DnkjdQKTjEDeOK20rtr se5PyfmVNVWIy/jYcdTit5RZLFgeApRN08KOnuhe11GDoQvtIIlz5qu2GUTtKWwY+B+cGr K4KFbHmGZslIcImOgP64S0uW45ZITPs= From: Amolith To: ~whereswaldon/arbor-dev@lists.sr.ht Cc: Amolith Subject: [PATCH 05/12] Add Prometheus and Caddy to Apt target Date: Wed, 20 Jul 2022 23:09:54 -0400 Message-Id: <20220721031001.97027-6-amolith@secluded.site> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220721031001.97027-1-amolith@secluded.site> References: <20220721031001.97027-1-amolith@secluded.site> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Signed-off-by: Amolith --- setup.go | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/setup.go b/setup.go index 5fcfb18..1c1c602 100644 --- a/setup.go +++ b/setup.go @@ -5,8 +5,11 @@ package main import ( "embed" "fmt" + "io" "log" + "net/http" "os" + "os/exec" "strings" "text/template" @@ -74,13 +77,48 @@ func SshConfig() error { } func Apt() error { - fmt.Println("Running target apt") - var apt = sh.RunCmd("env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "-qq") + log.Println("Running target apt") + apt := sh.RunCmd("env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "-qq") apt("update") + // Install requisite packages for adding Caddy's PPA + apt("install", "debian-keyring", "debian-archive-keyring", "apt-transport-https") - // Safe to run an install if a package is already installed. - return apt("install", "golang-1.14") + resp, err := http.Get("https://dl.cloudsmith.io/public/caddy/stable/gpg.key") + if err != nil { + return err + } + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("Unexpected response code: %d", resp.StatusCode) + } + + command := exec.Command("apt-key", "add", "-") + command.Stdin = resp.Body + err = command.Run() + if err != nil { + return err + } + + resp, err = http.Get("https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt") + if err != nil { + return err + } + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected response code: %d", resp.StatusCode) + } + command = exec.Command("tee", "/etc/apt/sources.list.d/caddy-stable.list") + command.Stdin = resp.Body + err = command.Run() + if err != nil { + return err + } + + // Update before installing packages + apt("update") + + // Install necessary packages + return apt("install", "prometheus", "git", "acl", "caddy") } func Firewall() error { -- 2.37.1