changeset 28:c310ec097194

Add Linux support.
author David Barts <n5jrn@me.com>
date Fri, 25 Dec 2020 19:07:47 -0800
parents 404eb7e57fe6
children e90d290a9a8d
files build.xml make-debian-package package-files/linux/deb/Packages package-files/linux/deb/changelog package-files/linux/deb/control package-files/linux/deb/copyright package-files/linux/deb/imageprep package-files/linux/deb/imageprep.desktop package-files/linux/deb/postinst package-files/linux/deb/postrm package-files/linux/icon_48x48.png package-files/linux/imageprep package-files/linux/imageprep.1
diffstat 13 files changed, 255 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/build.xml	Fri Dec 25 18:58:45 2020 -0800
+++ b/build.xml	Fri Dec 25 19:07:47 2020 -0800
@@ -29,6 +29,31 @@
     ]]>
   </scriptdef>
 
+  <!-- estimate disk usage -->
+  <scriptdef language="javascript" name="du">
+    <attribute name="path" />
+    <attribute name="target" />
+    <![CDATA[
+      "use strict";
+      var File = Java.type('java.io.File');
+      function du(fp) {
+        if (fp.isDirectory()) {
+          var files = fp.listFiles();
+          if (!files) return 0;
+          var total = 0;
+          for (var i=0; i<files.length; i++)
+            total += du(files[i]);
+          return total;
+        } else {
+          return fp.length();
+        }
+      }
+      var path = new File(attributes.get("path"));
+      project.setProperty(attributes.get("target"),
+        Math.round(du(path) / 1024) + "");
+    ]]>
+  </scriptdef>
+
   <!-- Define the properties used by the build -->
   <property name="app.name"      value="${ant.project.name}"/>
   <toLowerCase target="lc.app.name" value="${app.name}"/>
@@ -191,4 +216,64 @@
     </sequential>
   </target>
 
+  <target name="deb" depends="jar" description="Create Debian package.">
+    <fail message="Linux packages can only be built on Linux.">
+      <condition>
+        <not><os family="unix"/></not>
+      </condition>
+    </fail>
+    <sequential>
+      <mkdir dir="${dist.home}/data/usr/share/applications"/>
+      <copy file="${pf.home}/linux/deb/imageprep.desktop"
+        tofile="${dist.home}/data/usr/share/applications/imageprep.desktop"/>
+      <mkdir dir="${dist.home}/data/usr/share/icons/hicolor/48x48/apps"/>
+      <copy file="${pf.home}/linux/icon_48x48.png"
+        tofile="${dist.home}/data/usr/share/icons/hicolor/48x48/apps/imageprep.png"/>
+      <mkdir dir="${dist.home}/data/usr/share/imageprep"/>
+      <copy file="${jar.name}" todir="${dist.home}/data/usr/share/imageprep"/>
+      <mkdir dir="${dist.home}/data/usr/share/doc/imageprep"/>
+      <copy todir="${dist.home}/data/usr/share/doc/imageprep">
+        <filelist dir="${basedir}" files="Readme.html,Readme.rst"/>
+      </copy>
+      <copy todir="${dist.home}/data/usr/share/doc/imageprep" encoding="UTF-8" overwrite="true">
+        <fileset file="${pf.home}/linux/deb/copyright"/>
+        <filterset>
+          <filter token="app.copyright" value="${app.copyright}"/>
+        </filterset>
+      </copy>
+      <gzip src="${pf.home}/linux/deb/changelog"
+        destfile="${dist.home}/data/usr/share/doc/imageprep/changelog.gz"/>
+      <mkdir dir="${dist.home}/data/usr/share/man/man1"/>
+      <gzip src="${pf.home}/linux/imageprep.1"
+        destfile="${dist.home}/data/usr/share/man/man1/imageprep.1.gz"/>
+      <mkdir dir="${dist.home}/data/usr/bin"/>
+      <copy todir="${dist.home}/data/usr/bin" encoding="UTF-8" overwrite="true">
+        <fileset file="${pf.home}/linux/imageprep"/>
+        <filterset>
+          <filter token="jar.filename" value="${lc.app.name}.jar"/>
+        </filterset>
+      </copy>
+      <chmod file="${dist.home}/data/usr/bin/imageprep" perm="755"/>
+      <du path="${dist.home}/data" target="deb.installed.size"/>
+      <mkdir dir="${dist.home}/control"/>
+      <copy todir="${dist.home}/control" encoding="UTF-8" overwrite="true">
+        <fileset file="${pf.home}/linux/deb/control"/>
+        <filterset>
+          <filter token="app.version" value="${app.version}"/>
+          <filter token="deb.installed.size" value="${deb.installed.size}"/>
+        </filterset>
+      </copy>
+      <copy todir="${dist.home}/control">
+        <filelist dir="${pf.home}/linux/deb" files="postinst,postrm"/>
+      </copy>
+      <chmod perm="755">
+        <filelist dir="${dist.home}/control" files="postinst,postrm"/>
+      </chmod>
+      <exec executable="${basedir}/make-debian-package" failonerror="true">
+        <arg value="${dist.home}"/>
+        <arg value="${lc.app.name}_${app.version}.deb"/>
+      </exec>
+    </sequential>
+  </target>
+
 </project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make-debian-package	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,57 @@
+#!/bin/bash
+# A v. 2.0 Debian package is nothing but an ar(1) archive that contains
+# three members:
+# 1. A debian-binary file containing the string "2.0" and a newline,
+# 2. A compressed tar archive with a name of control,
+# 3. A compressed tar archive with a name of data.
+# (See https://en.wikipedia.org/wiki/Deb_%28file_format%29.) Make one.
+#
+# There are other ways to do this, but they tend to be so complex and
+# badly-documented that I found it easier to just roll my own.
+
+# Name executed as
+myname="${0##*/}"
+
+# We must specify single directory name and an output file.
+if [ $# -ne 2 ]
+then
+    1>&2 echo "$myname: expecting directory and output file"
+    exit 2
+fi
+
+# Change to the directory, die if we can't
+cd "$1" || exit 2
+
+# Do some sanity checks.
+for i in data control
+do
+    if [ ! -d "$i" ]
+    then
+        1>&2 echo "$myname: '$1/$i', no such directory"
+        exit 2
+    fi
+done
+
+# If there is no debian-binary file, make one.
+dbin="debian-binary"
+if [ ! -e "$dbin" ]
+then
+    1>&2 echo "$myname: warning - '$dbin' does not exist, creating it"
+    echo "2.0" > "$dbin" || exit 1
+fi
+
+# Remember where we are, and bail on errors
+set -e
+
+# Process data
+cd data
+find * -type f -print0 | xargs -0 md5sum > ../control/md5sums
+tar -c -z --owner=0 --group=0 -f ../data.tar.gz *
+
+# Process control
+cd ../control
+tar -c -z --owner=0 --group=0 -f ../control.tar.gz *
+
+# Finally, make deb file
+cd ..
+ar r "$2" "$dbin" control.tar.gz data.tar.gz
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/deb/Packages	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,15 @@
+Package: imageprep
+Version: @app.version@
+Architecture: all
+Installed-Size: @deb.installed.size@
+Recommends: default-jre | openjdk-8-jre
+Suggests: default-jdk | openjdk-8-jdk
+Filename: @deb.repository.file@
+Size: @deb.size@
+MD5sum: @deb.md5@
+SHA1: @deb.sha1@
+SHA256: @deb.sha256@
+Section: contrib/graphics
+Homepage: http://notyouraveragetechie.com/ImagePrep.html
+Priority: optional
+Description: Prepare photos for sharing on social media.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/deb/changelog	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,7 @@
+imageprep (1.01) unstable; urgency=low
+
+  * 1.01 First Debian package for ImagePrep.
+
+ -- David Barts <opensource@bartsent.com>  Fri, 25 Dec 2020 18:09:00 -0800
+
+# This comment to make lintian happy.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/deb/control	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,13 @@
+Package: imageprep
+Version: @app.version@
+Architecture: all
+Section: contrib/graphics
+Homepage: http://notyouraveragetechie.com/ImagePrep.html
+Recommends: default-jre | openjdk-8-jre
+Build-depends: default-jdk | openjdk-8-jdk, ant
+Suggests: default-jdk | openjdk-8-jdk
+Priority: optional
+Installed-Size: @deb.installed.size@
+Description: Prepare photos for sharing on social media.
+ This dummy line here to make lintian happy.
+Maintainer: David Barts <opensource@bartsent.com>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/deb/copyright	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,13 @@
+    @app.copyright@
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    See: /usr/share/common-licenses/GPL-3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/deb/imageprep	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,2 @@
+?package(imageprep):needs="X11" section="Contrib/Graphics" \
+  title="ImagePrep" command="/usr/bin/imageprep"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/deb/imageprep.desktop	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,13 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=ImagePrep
+GenericName=Image Preparer
+Comment=Resize, rotate, generate clean, metadata-free JPEG
+Exec=imageprep
+Icon=imageprep
+Terminal=false
+Type=Application
+Categories=Graphics;Photography;Security;
+StartupNotify=true
+StartupWMClass=imageprep
+Keywords=Photo;Resize;Rotate;JPEG;Privacy
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/deb/postinst	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,3 @@
+#!/bin/sh
+set -e
+if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ]; then update-menus ; fi
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/deb/postrm	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,3 @@
+#!/bin/sh
+set -e
+if [ -x "`which update-menus 2>/dev/null`" ]; then update-menus ; fi
Binary file package-files/linux/icon_48x48.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/imageprep	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Runs ImagePrep. Adopted from a similar script in the jEdit distribution.
+#
+# Find a java installation.
+if [ -z "${JAVA_HOME}" ]; then
+	echo 'Warning: $JAVA_HOME environment variable not set! Consider setting it.'
+	echo '         Attempting to locate java...'
+	j=`which java 2>/dev/null`
+	if [ -z "$j" ]; then
+		echo "Failed to locate the java virtual machine! Bailing..."
+		exit 1
+	else
+		echo "Found a virtual machine at: $j..."
+		JAVA="$j"
+	fi
+else
+	JAVA="${JAVA_HOME}/bin/java"
+fi
+
+# Antialias menus and dockable text:
+ANTIALIAS_ALL="-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true"
+
+# Launch application.
+exec "${JAVA}" ${ANTIALIAS_ALL} -jar "/usr/share/imageprep/@jar.filename@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package-files/linux/imageprep.1	Fri Dec 25 19:07:47 2020 -0800
@@ -0,0 +1,19 @@
+.TH IMAGEPREP 1
+.SH NAME
+.B ImagePrep
+\- prepare digital photos for sharing on the Internet
+.SH SYNOPSIS
+.B "imageprep"
+.SH DESCRIPTION
+This is a simple (and hopefully user-friendly), GUI-based tool for preparing
+digital photographs for sharing on the Internet. It resizes the image file
+without distortion to the specified maximum dimension, allows the user to
+rotate the image if needed, then saves the result as a minimal JPEG file with
+no metadata.
+.SH FILES
+.TP
+~/.imageprep/*
+Various configuration and other cached data lives here.
+.SH "SEE ALSO"
+.BR java (1)
+.BR kotlin (1)