Skip to content

Commit

Permalink
First Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Laky-64 committed Nov 14, 2022
1 parent 61a37e5 commit e7059be
Show file tree
Hide file tree
Showing 14 changed files with 742 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.exe
*.exe~
.env
.idea/*
temp/*
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# OwlGramUploader
# [OwlGram](https://owlgram.org/) Publisher — solution that automatically builds and sends to OwlGram Servers

![OwlGram Publisher](/images/cover.png)

This is the complete source code for the solution that automatically build and publish it to [Google Play], [Huawei Store] and OwlGram Servers.

**This solution is made as a tool for the official [OwlGram source code] and is not designed to be used in other projects.**

## License

`OwlGram Publisher` is licensed under the terms of the GNU General Public License v2.0.

For more information, see [LICENSE](/LICENSE) file.

[Google Play]: https://play.google.com/store/apps/details?id=it.owlgram.android
[Huawei Store]: https://appgallery.cloud.huawei.com/marketshare/app/C105849965
[OwlGram source code]: https://github.com/OwlGramDev/OwlGram
28 changes: 28 additions & 0 deletions android/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package android

import (
"bytes"
"errors"
"os"
"os/exec"
"path"
"publish/consts"
"strings"
)

func BuildGradlew(buildVariant string) error {
var errRes bytes.Buffer
cmd := exec.Command(path.Join(consts.ProjectPath, "gradlew"), strings.Split(buildVariant, " ")...)
cmd.Stderr = &errRes
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "JAVA_HOME="+consts.JavaPath)
cmd.Dir = consts.ProjectPath
err := cmd.Run()
if err != nil {
if len(errRes.String()) > 0 {
return errors.New(errRes.String())
}
return err
}
return nil
}
6 changes: 6 additions & 0 deletions consts/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package consts

const ProjectPath = "C:/Users/iraci/StudioProjects/OwlGram"
const BuildOutputsPath = ProjectPath + "/TMessagesProj_App/build/outputs"
const ApiNotifyUrl = "https://app.owlgram.org/notify_upload"
const JavaPath = "C:/Program Files/Android/Android Studio/jre"
34 changes: 34 additions & 0 deletions consts/load_env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package consts

import (
"github.com/joho/godotenv"
"os"
"path"
"runtime"
"strconv"
)

var (
CurrentPath string
SshHost string
SshPort int
SshUser string
SshPassword string
SshFolderOutput string
PublisherToken string
)

func LoadEnv() {
_, filename, _, _ := runtime.Caller(0)
CurrentPath = path.Join(path.Dir(filename), "..")
err := godotenv.Load(path.Join(CurrentPath, ".env"))
if err != nil {
panic("Error loading .env file")
}
PublisherToken = os.Getenv("PUBLISHER_TOKEN")
SshHost = os.Getenv("SSH_HOST")
SshPort, _ = strconv.Atoi(os.Getenv("SSH_PORT"))
SshUser = os.Getenv("SSH_USER")
SshPassword = os.Getenv("SSH_PASSWORD")
SshFolderOutput = os.Getenv("SSH_FOLDER_OUTPUT")
}
38 changes: 38 additions & 0 deletions file_manager/get_files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package file_manager

import (
"os"
"path"
"publish/consts"
)

func GetFiles(folder string) ([]string, error) {
var filesReturn []string
if folder == consts.BuildOutputsPath {
getApks, err := GetFiles(path.Join(folder, "apk", "release"))
if err != nil {
return nil, err
}
filesReturn = append(filesReturn, getApks...)
getBundles, err := GetFiles(path.Join(folder, "bundle", "play"))
if err != nil {
return nil, err
}
filesReturn = append(filesReturn, getBundles...)
return filesReturn, nil
}
f, err := os.Open(folder)
if err != nil {
return nil, err
}
files, err := f.Readdir(0)
if err != nil {
return nil, err
}
for _, file := range files {
if path.Ext(file.Name()) == ".apk" || path.Ext(file.Name()) == ".aab" {
filesReturn = append(filesReturn, path.Join(folder, file.Name()))
}
}
return filesReturn, nil
}
59 changes: 59 additions & 0 deletions file_manager/zip_files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package file_manager

import (
"archive/zip"
"fmt"
"github.com/cheggaaa/pb"
"io"
"os"
)

func ZipFiles(files []string, output string) error {
archive, err := os.Create(output)
if err != nil {
return err
}
defer func(archive *os.File) {
_ = archive.Close()
}(archive)
zipWriter := zip.NewWriter(archive)
for _, file := range files {
zipFile, err := os.Open(file)
if err != nil {
return err
}
//goland:noinspection GoDeferInLoop
defer func(zipFile *os.File) {
_ = zipFile.Close()
}(zipFile)
info, err := zipFile.Stat()
if err != nil {
return err
}
fmt.Println(fmt.Sprintf("Zipping %s...", info.Name()))
bar := pb.StartNew(int(info.Size()))
bar.SetUnits(pb.U_BYTES_DEC)
bar.ShowSpeed = true
bar.ShowTimeLeft = true
bar.Format("[##.]")
header, err := zip.FileInfoHeader(info)
if err != nil {
return err
}
header.Method = zip.Deflate
writer, err := zipWriter.CreateHeader(header)
if err != nil {
return err
}
if _, err := io.Copy(bar.NewProxyWriter(writer), zipFile); err != nil {
return err
}
bar.Finish()
fmt.Println()
}
err = zipWriter.Close()
if err != nil {
return err
}
return nil
}
21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module publish

go 1.18

require (
github.com/bramvdbogaerde/go-scp v1.2.0
github.com/cheggaaa/pb v1.0.29
github.com/joho/godotenv v1.4.0
github.com/valyala/fasthttp v1.35.0
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29
)

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/klauspost/compress v1.15.0 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 // indirect
)
55 changes: 55 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bramvdbogaerde/go-scp v1.2.0 h1:mNF1lCXQ6jQcxCBBuc2g/CQwVy/4QONaoD5Aqg9r+Zg=
github.com/bramvdbogaerde/go-scp v1.2.0/go.mod h1:s4ZldBoRAOgUg8IrRP2Urmq5qqd2yPXQTPshACY8vQ0=
github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo=
github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U=
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.35.0 h1:wwkR8mZn2NbigFsaw2Zj5r+xkmzjbrA/lyTmiSlal/Y=
github.com/valyala/fasthttp v1.35.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 h1:tkVvjkPTB7pnW3jnid7kNyAMPVWllTNOf/qKDze4p9o=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 h1:QyVthZKMsyaQwBTJE04jdNN0Pp5Fn9Qga0mrgxyERQM=
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
29 changes: 29 additions & 0 deletions http/notify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package http

import (
"errors"
"github.com/valyala/fasthttp"
"publish/consts"
)

func Notify() error {
req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req)
req.SetRequestURI(consts.ApiNotifyUrl)
req.Header.SetMethod("POST")
req.Header.Set("Token", consts.PublisherToken)
resp := fasthttp.AcquireResponse()
defer fasthttp.ReleaseResponse(resp)
err := fasthttp.Do(req, resp)
if err != nil {
return err
}
if resp.StatusCode() != fasthttp.StatusOK && resp.StatusCode() != fasthttp.StatusCreated {
return err
}
res := string(resp.Body())
if res != "ok" {
return errors.New("error while sending message")
}
return nil
}
Binary file added images/cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"
"path"
"publish/android"
"publish/consts"
"publish/file_manager"
"publish/http"
"publish/server"
)

func main() {
consts.LoadEnv()
fmt.Println("Building Bundle...")
err := android.BuildGradlew(":TMessagesProj_App:bundlePlay")
if err != nil {
panic(err)
}
fmt.Println("Building APKs...")
err = android.BuildGradlew(":TMessagesProj_App:assembleRelease")
if err != nil {
panic(err)
}
files, err := file_manager.GetFiles(consts.BuildOutputsPath)
if err != nil {
panic(err)
}
zipFile := path.Join(consts.CurrentPath, "temp", "publish.zip")
err = file_manager.ZipFiles(files, zipFile)
if err != nil {
panic(err)
}
fmt.Println("Sending to NAOS Server...")
err = server.UploadFile(zipFile)
if err != nil {
panic(err)
}
err = http.Notify()
if err != nil {
fmt.Println("\nError when sending to OwlGram Servers, ", err)
} else {
fmt.Println("\nSent to OwlGram Servers!")
}
}
Loading

0 comments on commit e7059be

Please sign in to comment.