Commit a9d39c32 authored by Lorenzo Faletra's avatar Lorenzo Faletra

Import Debian version 2019.05.20

parrot-menu (2:2019.05.20) testing; urgency=medium

  * Update (and fix) new golang launcher updater.
parent 42c14f58
parrot-menu (2:2019.05.20) testing; urgency=medium
* Update (and fix) new golang launcher updater.
-- Lorenzo "Palinuro" Faletra <palinuro@parrotsec.org> Sun, 19 May 2019 23:35:32 +0200
parrot-menu (2:2019.05.19) testing; urgency=medium
* Rewrite the menu lanucher updater in golang.
......
......@@ -7,6 +7,7 @@ import (
"log"
"os"
"os/exec"
"os/user"
"strings"
)
......@@ -21,9 +22,14 @@ type launcher struct {
}
func main() {
if uid, _ := user.Current(); uid.Uid != "0" {
os.Stderr.WriteString(fmt.Sprintf("Wrong user %s! - Run this program as root\n", uid.Name))
os.Exit(1)
}
fmt.Println("Scanning application launchers")
// get list of files in /usr/share/parrot-menu/applications (source)
// get list of files in /usr/share/parrot-menu/applications (source)""
sfiles, err := ioutil.ReadDir("/usr/share/parrot-menu/applications/")
if err != nil {
log.Fatal(err)
......@@ -38,34 +44,23 @@ func main() {
// get list of installed packages
tmp, _ := exec.Command("bash", "-c", "apt list --installed | cut -d'/' -f1").Output()
packages := strings.Split(string(tmp), "\n")
fmt.Println(len(packages))
// create source and destination structures
source := make([]launcher, len(sfiles))
destination := make([]launcher, len(dfiles))
// initialize source structure
sfinished := make(chan bool)
var spath string
for i, f := range sfiles {
spath = fmt.Sprintf("/usr/share/parrot-menu/applications/%s", f.Name())
go getLauncherContent(sfinished, &source[i], spath, f.Name())
getLauncherContent(&source[i], spath, f.Name())
}
// initialize destination structure
dfinished := make(chan bool)
var dpath string
for i, f := range dfiles {
dpath = fmt.Sprintf("/usr/share/applications/%s", f.Name())
go getLauncherContent(dfinished, &destination[i], dpath, f.Name())
}
// wait for initialization goroutines to finish
for i := 0; i < len(dfiles); i++ {
<-dfinished
}
for i := 0; i < len(sfiles); i++ {
<-sfinished
getLauncherContent(&destination[i], dpath, f.Name())
}
fmt.Println("Updating active launchers")
......@@ -77,7 +72,7 @@ func main() {
fmt.Println("Done")
}
func getLauncherContent(finished chan bool, s *launcher, path string, filename string) {
func getLauncherContent(s *launcher, path string, filename string) {
// set path
s.path = path
......@@ -93,9 +88,6 @@ func getLauncherContent(finished chan bool, s *launcher, path string, filename s
tmpdeb, _ := exec.Command("bash", "-c",
fmt.Sprintf("grep X-Parrot-Package= %s | sed -e 's/X-Parrot-Package=//g'", path)).Output()
s.deb = strings.Trim(string(tmpdeb), "\n")
// send signal
finished <- true
}
func removeOldLaunchers(files []launcher) {
......@@ -106,27 +98,33 @@ func removeOldLaunchers(files []launcher) {
}
}
func copyLauncher(source string, destination string) (error, error, error) {
in, errOpen := os.Open(source)
if errOpen != nil {
fmt.Printf("[WARNING] Can't open: %s - %v\n", source, errOpen)
}
out, errClose := os.Create(destination)
if errClose != nil {
fmt.Printf("[WARNING] Can't create: %s - %v\n", destination, errClose)
}
_, errCopy := io.Copy(out, in)
if errCopy != nil {
fmt.Printf("[WARNING] Can't install launcher - %v\n", errCopy)
}
defer in.Close()
defer out.Close()
return errOpen, errClose, errCopy
}
func copyActiveLaunchers(launchers []launcher, packages []string) {
for _, l := range launchers {
for _, p := range packages {
if l.deb == p {
in, err := os.Open(l.path)
if err != nil {
fmt.Printf("[WARNING] Can't find source launcher to copy: %s\n", l.path)
}
defer in.Close()
out, err := os.Create(fmt.Sprintf("/usr/share/applications/%s", l.filename))
if err != nil {
fmt.Printf("[WARNING] Can't create target launcher to write: %s%s\n", "/usr/share/applications/", l.filename)
}
defer out.Close()
if _, err := io.Copy(out, in); err != nil {
fmt.Printf("[WARNING] Can't create new launcher for %s\n", l.name)
}
copyLauncher(l.path, fmt.Sprintf("/usr/share/applications/%s", l.filename))
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment