Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
Finish magefile and delete unwanted scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom5521 committed Jan 3, 2024
1 parent 760a640 commit ef2c4b8
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 431 deletions.
167 changes: 151 additions & 16 deletions Magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ var (
Mesa64Url = "https://downloads.fdossena.com/geth.php?r=mesa64-latest"
MainDir = "./cmd/EduTrack/"
WindowsEnv = windowsEnv()
// Mage config.
Aliases = map[string]interface{}{
"user-install": UserInstall,
}
build = Build{}
)

type Build mg.Namespace

func Test() error {
return movefile("cmd/EduTrack/builds/EduTrack.exe", "builds/EduTrack.exe")
return nil
}
type Install mg.Namespace

func copyfile(src, dest string) error {
source, err := os.ReadFile(src)
Expand Down Expand Up @@ -108,6 +101,20 @@ func (Build) LinuxInstaller() error {
if err := checkdir(); err != nil {
return err
}
if _, err := os.Stat("builds/EduTrack-linux64.tar.xz"); os.IsNotExist(err) {
err = build.Linux()
if err != nil {
return err
}
}
err := copyfile("./builds/EduTrack-linux64.tar.xz", "./internal/installer/install/files/EduTrack-linux64.tar.xz")
if err != nil {
return err
}
err = sh.RunV("go", "build", "-v", "-o", "builds/EduTrack-Installer-linux64", "./cmd/Installer/main_linux.go")
if err != nil {
return err
}
return nil
}

Expand All @@ -120,16 +127,33 @@ func (Build) WindowsInstaller() error {
return err
}
}
return nil
}

func (Build) Installer() error {
if err := checkdir(); err != nil {
err := copyfile("tmp/opengl32.dll", "./internal/installer/install/files/opengl32.dll")
if err != nil {
return err
}
if _, err = os.Stat("builds/EduTrack.exe"); os.IsNotExist(err) {
err = build.Windows()
if err != nil {
return err
}
}
err = copyfile("builds/EduTrack.exe", "./internal/installer/install/files/EduTrack.exe")
if err != nil {
return err
}
err = sh.RunWith(WindowsEnv, "fyne", "package", "--os", "windows", "--release", "--src", "./cmd/Installer/",
"--exe", "builds/EduTrack-Installer-win64.exe", "--tags", "windows")
if err != nil {
return err
}
err = movefile("./cmd/Installer/builds/EduTrack-Installer-win64.exe", "builds/EduTrack-Installer-win64.exe")
if err != nil {
return err
}
return nil
}

// Compile the program to be distributed on windows, NOTE: This will only return an .exe of the program, the installation in windows can only be done through the installer.
func (Build) Windows() error {
if err := checkdir(); err != nil {
return err
Expand All @@ -146,21 +170,76 @@ func (Build) Windows() error {
return nil
}

// Compile the program to be distributed on linux.
func (Build) Linux() error {
if err := checkdir(); err != nil {
return err
}
err := sh.RunV("fyne", "package", "--os", "linux", "--release", "--tags", "linux", "--src", MainDir)
if err != nil {
return err
}
err = movefile("EduTrack.tar.xz", "builds/EduTrack-linux64.tar.xz")
if err != nil {
return err
}
return nil
}

func Install() error {
func setupLinuxInstall() error {
if _, err := os.Stat("builds/EduTrack-linux64.tar.xz"); os.IsNotExist(err) {
err = build.LinuxInstaller()
if err != nil {
return err
}
}
err := os.Chdir("builds")
if err != nil {
return err
}
err = sh.RunV("tar", "-xvf", "EduTrack-linux64.tar.xz")
if err != nil {
return err
}

return nil
}

// NOTE: Only works in linux, in windows you will have to use the installer.
func (Install) Root() error {
err := setupLinuxInstall()
if err != nil {
return err
}
err = sh.RunV("sudo", "make", "install")
if err != nil {
return err
}
err = os.Chdir("..")
if err != nil {
return err
}
return nil
}

func UserInstall() error {
// NOTE: Only works in linux, in windows you will have to use the installer.
func (Install) User() error {
err := setupLinuxInstall()
if err != nil {
return err
}
err = sh.RunV("make", "user-install")
if err != nil {
return err
}
err = os.Chdir("..")
if err != nil {
return err
}
return nil
}

// Delete temporary directories, compilation files, etc, It leaves it as if it had just been cloned.
func Clean() {
var errorList []error
appendErr := func(err error) {
Expand All @@ -184,3 +263,59 @@ func Clean() {
messages.Warning(e.Error())
}
}

func MakeWindowsZip() error {
if _, err := os.Stat("windows-tmp"); os.IsNotExist(err) {
err = os.Mkdir("windows-tmp", os.ModePerm)
if err != nil {
return err
}
}
if _, err := os.Stat("tmp/opengl32.dll"); os.IsNotExist(err) {
err = downloadWinFiles()
if err != nil {
return err
}
}
err := copyfile("tmp/opengl32.dll", "windows-tmp/opengl32.dll")
if err != nil {
return err
}
if _, err = os.Stat("builds/EduTrack.exe"); os.IsNotExist(err) {
err = build.Windows()
if err != nil {
return err
}
}
err = copyfile("builds/EduTrack.exe", "windows-tmp/EduTrack.exe")
if err != nil {
return err
}
err = copyfile("README.md", "windows-tmp/README.md")
if err != nil {
return err
}
if _, err = os.Stat("builds/EduTrack-win64.zip"); os.IsExist(err) {
err = os.Remove("builds/EduTrack-win64.zip")
if err != nil {
return err
}
}
err = os.Chdir("windows-tmp")
if err != nil {
return err
}
err = sh.RunV("zip", "-r", "../builds/EduTrack-win64.zip", ".")
if err != nil {
return err
}
err = os.Chdir("..")
if err != nil {
return err
}
err = os.RemoveAll("windows-tmp")
if err != nil {
return err
}
return nil
}
95 changes: 0 additions & 95 deletions Makefile

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ You can compile it, you need:

- C compiler
- Go compiler
- Mage
- wget
- xz (on linux)
- winrar/7zip (on windows)
Expand All @@ -54,15 +55,15 @@ Compiling and installing in Linux
```bash
git clone https://github.com/Tom5521/EduTrack
git checkout <latest version>
make user-install # make install for root installation
mage install:user # mage install:root for root installation
```

On Windows

```batch
git clone https://github.com/Tom5521/EduTrack
git checkout <latest version>
go run -tags release scripts/main.go -compile-to-windows
mage build:windows
# Go to builds folder and unzip EduTrack-win64.zip
# Then run the executable, and done!
# The windows(and linux executable is fully portable)
Expand Down
2 changes: 1 addition & 1 deletion cmd/EduTrack/FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Name = "EduTrack"
ID = "github.Tom5521.EduTrack"
Version = "1.1.2"
Build = 167
Build = 168
2 changes: 1 addition & 1 deletion cmd/Installer/FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Name = "EduTrack Installer"
ID = "github.Tom5521.EduTrack"
Version = "1.0.0"
Build = 10
Build = 12
10 changes: 0 additions & 10 deletions scripts/main.go

This file was deleted.

18 changes: 0 additions & 18 deletions scripts/src/MakeRelease.go

This file was deleted.

Loading

0 comments on commit ef2c4b8

Please sign in to comment.