In the beginning
This commit is contained in:
commit
62284a29d1
3 changed files with 178 additions and 0 deletions
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module fdroidgo
|
||||
|
||||
go 1.24.2
|
||||
|
||||
require github.com/BurntSushi/toml v1.5.0
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
171
main.go
Normal file
171
main.go
Normal file
|
@ -0,0 +1,171 @@
|
|||
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.")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue