summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Camera <cdist@dtnr.ch>2021-03-21 23:27:05 +0100
committerDennis Camera <cdist@dtnr.ch>2021-03-21 23:37:27 +0100
commite6f3cfbba18862a02e27bd0da2823f5ea8440808 (patch)
treee2d88bb4ccc265b725e9bf93e445f7cfe4037e85
parent13a44d885ac1a0f745d152331bb561b28867094d (diff)
download__dtnrch_egov-e6f3cfbba18862a02e27bd0da2823f5ea8440808.tar.gz
__dtnrch_egov-e6f3cfbba18862a02e27bd0da2823f5ea8440808.zip
[type/__dtnrch_etax_sgnp] Patch icons on freedesktop systems
-rw-r--r--type/__dtnrch_etax_sgnp/files/extract_icon_map.awk41
-rwxr-xr-xtype/__dtnrch_etax_sgnp/gencode-remote63
-rwxr-xr-xtype/__dtnrch_etax_sgnp/manifest3
3 files changed, 107 insertions, 0 deletions
diff --git a/type/__dtnrch_etax_sgnp/files/extract_icon_map.awk b/type/__dtnrch_etax_sgnp/files/extract_icon_map.awk
new file mode 100644
index 0000000..c295fc1
--- /dev/null
+++ b/type/__dtnrch_etax_sgnp/files/extract_icon_map.awk
@@ -0,0 +1,41 @@
+#!/usr/bin/awk -f
+# Extracts a mapping from file extension to .ico file stored in i4jparams.conf
+
+/<object class="com.install4j.runtime.beans.actions.desktop.CreateFileAssociationAction">/ {
+ match($0, /^[ ]*/)
+ file_assoc = RLENGTH
+ next
+}
+/<\/object>/ && file_assoc {
+ match($0, /^[ ]*/)
+ if (RLENGTH == file_assoc) {
+ if (file_ext && file_icon)
+ printf "%s\t%s\n", file_ext, file_icon
+ file_assoc = 0
+ file_ext = ""
+ file_icon = ""
+ next
+ }
+}
+
+file_assoc && /<void property="extension">/ {
+ while (getline && !/<\/void>/) {
+ if (/<string>.*<\/string>/) {
+ file_ext = $0
+ sub(/^.*<string>/, "", file_ext)
+ sub(/<\/string>.*$/, "", file_ext)
+ break
+ }
+ }
+}
+
+/<void property="windowsIconFile">/ {
+ while (getline && !/<\/void>/) {
+ if (/<string>.*<\/string>/) {
+ file_icon = $0
+ sub(/^.*<string>/, "", file_icon)
+ sub(/<\/string>.*$/, "", file_icon)
+ break
+ }
+ }
+}
diff --git a/type/__dtnrch_etax_sgnp/gencode-remote b/type/__dtnrch_etax_sgnp/gencode-remote
index 215f66b..2618939 100755
--- a/type/__dtnrch_etax_sgnp/gencode-remote
+++ b/type/__dtnrch_etax_sgnp/gencode-remote
@@ -18,6 +18,9 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
+quote() { printf "'%s'" "$(printf '%s\n' "$*" | sed -e "s/'/'\\\\''/g")"; }
+drop_awk_comments() { quote "$(sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@")"; }
+
version=$(cat "${__object:?}/parameter/version")
if test -s "${__object:?}/parameter/prefix"
@@ -126,4 +129,64 @@ then
# NOTE:
# xdg-desktop-menu install --mode system "\${main_desktop_file}"
# only works for files with no spaces
+
+ # Install icons
+ cat <<-EOF
+
+
+ install_icon() {
+ _mime=application-x-\$1
+ _ico=\$2
+
+ _tmp=\$(mktemp "${TMPDIR:-/tmp}/ico-XXXXXX.png")
+ chown 0:0 "\${_tmp}"
+ chmod 0644 "\${_tmp}"
+
+
+ identify "\${_ico}" \\
+ | while read -r _i _fmt _size _
+ do
+ convert "\${_i}" -alpha on "\${_tmp}"
+
+ xdg-icon-resource install --mode system --context mimetypes \\
+ --size "\${_size#*x}" "\${_tmp}" "\${_mime}"
+ done
+
+ rm -f "\${_tmp}"
+ }
+
+ awk $(drop_awk_comments "${__type:?}/files/extract_icon_map.awk") $(quote "${install_dir}/.install4j/i4jparams.conf") \\
+ | while read -r _ext _ico_file
+ do
+ case \${_ext}
+ in
+ (sgnp$((version)))
+ install_icon sgnp$((version)) $(quote "${install_dir}/.install4j")/\${_ico_file}
+ ;;
+ (sgnp$((version + 100)))
+ install_icon sgnp$((version))-submission $(quote "${install_dir}/.install4j")/\${_ico_file}
+ ;;
+ (sgbe$((version + 1)))
+ install_icon sgbe$((version + 1)) $(quote "${install_dir}/.install4j")/\${_ico_file}
+ ;;
+ (sgbe$((version + 101)))
+ install_icon sgbe$((version + 1))-submission $(quote "${install_dir}/.install4j")/\${_ico_file}
+ ;;
+ esac
+ done
+ EOF
+
+elif grep -q "^__dtnrch_install4j${i4j_object_name}:uninstalled" "${__messages_in:?}" \
+ && ${is_freedesktop}
+then
+ # Remove icons
+ cat <<-EOF
+ for _mime in sgnp$((version)) sgnp$((version))-submission sgbe$((version+1)) sgbe$((version+1))-submission
+ do
+ for _size in 16 32 48 128
+ do
+ xdg-icon-resource uninstall --mode system --context mimetypes --size \$((_size)) application-x-\${_mime}
+ done
+ done
+ EOF
fi
diff --git a/type/__dtnrch_etax_sgnp/manifest b/type/__dtnrch_etax_sgnp/manifest
index db89d70..63262e9 100755
--- a/type/__dtnrch_etax_sgnp/manifest
+++ b/type/__dtnrch_etax_sgnp/manifest
@@ -221,6 +221,9 @@ if ${is_freedesktop}
then
if test "${custom_mime_state}" = 'present'
then
+ # required for icon conversion
+ __package imagemagick
+
# Generate custom MIME declaration for SGnP application
mkdir "${__object:?}/files"
"${__type:?}/files/mkmime.xml.sh" >"${__object:?}/files/mime-sgnp${version}.xml"