Преглед изворни кода

AptGrade

Automatic `sudo apt update` `sudo apt upgrade -y`.
Steve Thielemann пре 2 недеља
комит
fd2286ecba
5 измењених фајлова са 63 додато и 0 уклоњено
  1. 1 0
      .gitignore
  2. 18 0
      README.md
  3. 35 0
      aptgrade.go
  4. 3 0
      go.mod
  5. 6 0
      install.sh

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+aptgrade

+ 18 - 0
README.md

@@ -0,0 +1,18 @@
+# AptGrade
+
+```
+sudo apt update
+sudo apt upgrade -y
+```
+
+Now all in one command, ready to be SUID.
+
+## Installing
+
+First, update install.sh, unless your username just happens to also be thor.
+
+`go build`
+`sudo ./install.sh`
+
+OK!  You now have an `aptgrade` binary that runs as root.
+It calls the above commands.

+ 35 - 0
aptgrade.go

@@ -0,0 +1,35 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"os/exec"
+	"strings"
+	"syscall"
+)
+
+// Run the given command, showing output.
+func run_command(command []string) error {
+	fmt.Println(strings.Repeat("=", 50))
+	fmt.Println(command)
+	cmd := exec.Command(command[0], command[1:]...)
+	// Connections
+	cmd.Stdout = os.Stdout
+	cmd.Stderr = os.Stderr
+	cmd.Stdin = os.Stdin
+
+	cmd.SysProcAttr = &syscall.SysProcAttr{}
+	cmd.SysProcAttr.Credential = &syscall.Credential{Uid: 0, Gid: 0}
+	err := cmd.Run()
+	fmt.Println(strings.Repeat("=", 50))
+	if err != nil {
+		fmt.Println("Command failed:", err)
+	}
+	return err
+}
+
+func main() {
+	run_command([]string{"apt", "update"})
+	run_command([]string{"apt", "upgrade", "-y"})
+	fmt.Println("Done")
+}

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module aptgrade
+
+go 1.25.3

+ 6 - 0
install.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+
+sudo rm -rf ~thor/bin/aptgrade
+cp ./aptgrade ~thor/bin
+chown root:root ~thor/bin/aptgrade
+chmod a+s ~thor/bin/aptgrade