171 lines
4.4 KiB
Go
171 lines
4.4 KiB
Go
package main
|
|
|
|
import (
|
|
"archive/zip"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/exec"
|
|
"github.com/BurntSushi/toml"
|
|
"time"
|
|
"log"
|
|
)
|
|
|
|
type Repo struct {
|
|
Timestamp int64 `json:"timestamp"`
|
|
Name string `json:"name"`
|
|
Version int64 `json:"version"`
|
|
Icon string `json:"icon"`
|
|
Address string `json:"address"`
|
|
Description string `json:"description"`
|
|
}
|
|
|
|
type Requests struct {
|
|
Install []string `json:"install"`
|
|
Uninstall []string `json:"uninstall"`
|
|
}
|
|
|
|
type Localized struct {
|
|
ENUS Icon `json:"en-US"`
|
|
}
|
|
|
|
type Icon struct {
|
|
Icon string `json:"icon"`
|
|
}
|
|
|
|
type App struct {
|
|
AuthorName string `json:"authorName"`
|
|
Categories []string `json:"categories"`
|
|
SuggestedVersionCode string `json:"suggestedVersionCode"`
|
|
IssueTracker string `json:"issueTracker"`
|
|
License string `json:"license"`
|
|
Name string `json:"name"`
|
|
SourceCode string `json:"sourceCode"`
|
|
Summary string `json:"summary"`
|
|
WebSite string `json:"webSite"`
|
|
Added int64 `json:"added"`
|
|
PackageName string `json:"packageName"`
|
|
LastUpdated int64 `json:"lastUpdated"`
|
|
Localized Localized `json:"localized,omitempty"`
|
|
}
|
|
|
|
type Index struct {
|
|
Repo Repo `json:"repo"`
|
|
Requests Requests `json:"requests"`
|
|
Apps []App `json:"apps"`
|
|
}
|
|
|
|
type Config struct {
|
|
Name string `toml:"name"`
|
|
Icon string `toml:"icon"`
|
|
Address string `toml:"address"`
|
|
Description string `toml:"description"`
|
|
}
|
|
|
|
func generateJSON(index Index, filename string) error {
|
|
data, err := json.MarshalIndent(index, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ioutil.WriteFile(filename, data, 0644)
|
|
}
|
|
|
|
func createJar(zipFileName string, files []string) error {
|
|
zipFile, err := os.Create(zipFileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer zipFile.Close()
|
|
|
|
zipWriter := zip.NewWriter(zipFile)
|
|
defer zipWriter.Close()
|
|
|
|
for _, file := range files {
|
|
err := addFileToZip(zipWriter, file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func addFileToZip(zipWriter *zip.Writer, file string) error {
|
|
fileToZip, err := os.Open(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer fileToZip.Close()
|
|
|
|
w, err := zipWriter.Create(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = io.Copy(w, fileToZip)
|
|
return err
|
|
}
|
|
|
|
func signJarWithJarsigner(jarFile string, keystore string, password string, alias string) (error, string) {
|
|
cmd := exec.Command("jarsigner", "-sigalg","SHA1withRSA","-digestalg","SHA1","-keystore", keystore, "-storetype", "PKCS12", "-storepass", password, jarFile, alias)
|
|
output, err := cmd.CombinedOutput() // Сначала получаем вывод и ошибку
|
|
return err, string(output) // Возвращаем ошибку и вывод как строку
|
|
}
|
|
|
|
func main() {
|
|
var config Config
|
|
file, err := os.Open("config.toml")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
// Parse the TOML file into the config struct
|
|
if _, err := toml.NewDecoder(file).Decode(&config); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
index := Index {
|
|
Repo: Repo{
|
|
Timestamp: time.Now().Unix(),
|
|
Name: config.Name,
|
|
Icon: "icon.png",
|
|
Version: 1002,
|
|
Address: config.Address,
|
|
Description: config.Description,
|
|
},
|
|
Requests: Requests{
|
|
Install: []string{},
|
|
Uninstall: []string{},
|
|
},
|
|
Apps: []App{},
|
|
}
|
|
// Генерация JSON файла
|
|
err = generateJSON(index, "index-v1.json")
|
|
if err != nil {
|
|
fmt.Println("Error generating JSON:", err)
|
|
return
|
|
}
|
|
fmt.Println("JSON file generated successfully.")
|
|
|
|
// Создание JAR файла
|
|
err = createJar("index-v1.jar", []string{"index-v1.json"})
|
|
if err != nil {
|
|
fmt.Println("Error creating JAR:", err)
|
|
return
|
|
}
|
|
fmt.Println("JAR file created successfully.")
|
|
|
|
// Подпись JAR файла
|
|
p12File := "../../keystore.p12" // Укажите путь к вашему P12 файлу
|
|
password := "u86viXB0FRlTY2K1buzGqWHdDu6pIgu8520R3IJgXAE=" // Укажите пароль для P12 файла
|
|
alias := "curious-invention.aeza.network" // Укажите алиас для ключа
|
|
|
|
err, output := signJarWithJarsigner("index-v1.jar", p12File, password, alias)
|
|
if err != nil {
|
|
fmt.Println("Error signing JAR:", err, output)
|
|
return
|
|
}
|
|
fmt.Println("JAR file signed successfully.")
|
|
}
|