Compare commits
	
		
			2 Commits
		
	
	
		
			e33f7b6d3c
			...
			22fb19a550
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 22fb19a550 | |||
| aa98cd81b3 | 
@@ -7,6 +7,7 @@ import (
 | 
				
			|||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/roboogg133/packets/pkg/install"
 | 
				
			||||||
	"github.com/roboogg133/packets/pkg/packet.lua.d"
 | 
						"github.com/roboogg133/packets/pkg/packet.lua.d"
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -92,11 +93,21 @@ var executeCmd = &cobra.Command{
 | 
				
			|||||||
				fmt.Printf("error: %s", err.Error())
 | 
									fmt.Printf("error: %s", err.Error())
 | 
				
			||||||
				os.Exit(1)
 | 
									os.Exit(1)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					 | 
				
			||||||
			pkg.ExecuteBuild(configs)
 | 
								pkg.ExecuteBuild(configs)
 | 
				
			||||||
			pkg.ExecuteInstall(configs)
 | 
								pkg.ExecuteInstall(configs)
 | 
				
			||||||
			os.Chdir(backupDir)
 | 
								os.Chdir(backupDir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								files, err := install.GetPackageFiles(configs.PacketDir)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									fmt.Printf("error: %s", err.Error())
 | 
				
			||||||
 | 
									os.Exit(1)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if err := install.InstallFiles(files, configs.PacketDir); err != nil {
 | 
				
			||||||
 | 
									fmt.Printf("error: %s", err.Error())
 | 
				
			||||||
 | 
									os.Exit(1)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,7 @@
 | 
				
			|||||||
package packet
 | 
					package packet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"archive/tar"
 | 
					 | 
				
			||||||
	"compress/gzip"
 | 
					 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
					 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"math/rand"
 | 
						"math/rand"
 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"path/filepath"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$%!@%&*()-=+[]{}:;.,1234567890"
 | 
					const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$%!@%&*()-=+[]{}:;.,1234567890"
 | 
				
			||||||
@@ -21,61 +13,3 @@ func randStringBytes(n int) string {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return string(b)
 | 
						return string(b)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func Dearchive(archive, outdir string) error {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	switch {
 | 
					 | 
				
			||||||
	case strings.HasSuffix(archive, ".tar.gz"):
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		f, err := os.Open(archive)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		gzReader, err := gzip.NewReader(f)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		tarReader := tar.NewReader(gzReader)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		for {
 | 
					 | 
				
			||||||
			header, err := tarReader.Next()
 | 
					 | 
				
			||||||
			if err == io.EOF {
 | 
					 | 
				
			||||||
				break
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				log.Fatal(err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			destination := filepath.Join(outdir, header.Name)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			fmt.Println(destination)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			switch header.Typeflag {
 | 
					 | 
				
			||||||
			case tar.TypeDir:
 | 
					 | 
				
			||||||
				if err := os.Mkdir(destination, header.FileInfo().Mode()); err != nil {
 | 
					 | 
				
			||||||
					return err
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			case tar.TypeReg:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if err := os.MkdirAll(filepath.Dir(destination), 0777); err != nil {
 | 
					 | 
				
			||||||
					return err
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				outFile, err := os.Create(destination)
 | 
					 | 
				
			||||||
				if err != nil {
 | 
					 | 
				
			||||||
					return err
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				if _, err := io.Copy(outFile, tarReader); err != nil {
 | 
					 | 
				
			||||||
					return err
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				outFile.Close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			default:
 | 
					 | 
				
			||||||
				return fmt.Errorf("unknow filetype")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user