From c61e9a504df08528ad81de6fd96561b1dee2146b Mon Sep 17 00:00:00 2001 From: Swee Date: Tue, 10 Sep 2024 16:15:24 -0700 Subject: [PATCH] make script to automatically patch script for packaging --- dpkg/usr/bin/sweecrypt-gtk | 6 +++--- generate-deb.py | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dpkg/usr/bin/sweecrypt-gtk b/dpkg/usr/bin/sweecrypt-gtk index 6b5243b..b8046b8 100644 --- a/dpkg/usr/bin/sweecrypt-gtk +++ b/dpkg/usr/bin/sweecrypt-gtk @@ -1,9 +1,9 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 import gi, os, sys, sweecrypt as sc gi.require_version("Gtk", "3.0") from gi.repository import Gtk, GdkPixbuf, Gdk +UI_FILE = os.path.dirname(os.path.realpath(__file__)) + "/sweecrypt-gtk.ui" UI_FILE = "/opt/sweecrypt-gtk.ui" -class GUI: def __init__(self): self.builder = Gtk.Builder() self.builder.add_from_file(UI_FILE) @@ -33,4 +33,4 @@ def main(): app = GUI() Gtk.main() if __name__ == "__main__": - sys.exit(main()) + sys.exit(main()) \ No newline at end of file diff --git a/generate-deb.py b/generate-deb.py index d547466..73f234f 100644 --- a/generate-deb.py +++ b/generate-deb.py @@ -1,3 +1,16 @@ #!/usr/bin/python3 import os -file = open("sweecrypt-gtk.py").read() +print("Creating Debian package...") +if os.name != "posix": + print("WARNING: Machine is not running Linux (value of os.name is not \"posix\"), the script will not try to auto-build the .deb file. You might need to manually `chmod 1777` the binary.") +file = open("sweecrypt-gtk.py").read().split("\n") +open("dpkg/opt/sweecrypt-gtk.ui",'w').write(open("sweecrypt-gtk.ui").read()) +file[4] = 'UI_FILE = "/opt/sweecrypt-gtk.ui"' +file.insert(0, "#!/usr/bin/env python3") +file = "\n".join(file) +open("dpkg/usr/bin/sweecrypt-gtk",'w').write(file) +os.chmod("dpkg/usr/bin/sweecrypt-gtk", 1777) +if os.name == "posix": + os.chmod("dpkg/DEBIAN/control", 1777) + os.system("dpkg-deb --root-owner-group --build dpkg") + os.rename("dpkg.deb", "sweecrypt-gtk.deb") \ No newline at end of file