Sfoglia il codice sorgente

Updated: Check euid, use full path to apt.

(Otherwise apt could be replaced in path and be run as root.)
Use linux install program to set permissions and owner.
Steve Thielemann 4 giorni fa
parent
commit
1790f844e6
2 ha cambiato i file con 11 aggiunte e 4 eliminazioni
  1. 7 2
      aptgrade.go
  2. 4 2
      install.sh

+ 7 - 2
aptgrade.go

@@ -32,7 +32,12 @@ func run_command(command []string) error {
 }
 
 func main() {
-	run_command([]string{"apt", "update"})
-	run_command([]string{"apt", "upgrade", "-y"})
+	if os.Geteuid() != 0 {
+		fmt.Println("Use `sudo install -g 0 -o 0 -m 4755 aptgrade ~/bin/aptgrade`")
+		fmt.Println("This program requires SETUID.")
+		os.Exit(2)
+	}
+	run_command([]string{"/usr/bin/apt", "update"})
+	run_command([]string{"/usr/bin/apt", "upgrade", "-y"})
 	fmt.Println("Done")
 }

+ 4 - 2
install.sh

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