#!/bin/sh # shellcheck disable=SC2086 # truepng - POSIX-compliant shell script to help running TruePNG through Wine # # Written in 2016-2017 by Daniel Bermond < yahoo.com: danielbermond > # # To the extent possible under law, the author(s) have dedicated all # copyright and related and neighboring rights to this software to the # public domain worldwide. This software is distributed without any # warranty. # # You should have received a copy of the CC0 Public Domain Dedication # along with this software. If not, see # . truepng_dir='/usr/share/truepng' truepng_file='TruePNG.exe' # cd_error function: print a message indicating a failed cd command and exit # arguments: $1 - the directory that failed to cd into # return value: none # return code (status): not relevant, will exit the program cd_error() { printf '%s\n' "error: could not cd into '${1%/}/' directory" >&2 exit 1 } # enable some options if the executing shell is zsh if [ -n "$ZSH_VERSION" ] then command -v setopt >/dev/null 2>&1 || { printf '%s\n' 'script appears to be running in zsh but setopt was not found'; exit 1; } setopt SH_WORD_SPLIT # enable variable word splitting fi # check if requirements are installed (wine and TruePNG.exe) command -v wine >/dev/null 2>&1 || { printf '%s\n' 'error: wine not found' >&2; printf '%s\n' ' please install wine' >&2; exit 1; } test -f "${truepng_dir}/${truepng_file}" || { printf '%s\n' "error: '${truepng_file}' not found" >&2; printf '%s\n' " please copy it to '${truepng_dir}/'" >&2; exit 1; } # Parse command line arguments and build a string with options # and PNG files to be passed to TruePNG. We cannot simply pass # the untouched command line arguments to TruePNG because it's # necessary to map paths for wine. for arg in "$@" do # test if command line argument is a valid file if [ -f "$arg" ] then # map path for wine using default WINEPREFIX fullpath="$(printf '%s' "$(cd "$(dirname "$arg")" || cd_error "$(dirname "$arg")"; pwd)/$(basename "$arg")")" pngfiles="${pngfiles} ${HOME}/.wine/dosdevices/z:${fullpath} " else # if not a valid file, just store it (should be an option) truepng_opts="${truepng_opts} ${arg}" fi done # delete the first character of strings (a blank character) pngfiles="$(printf '%s' "$pngfiles" | sed 's/.//')" truepng_opts="$(printf '%s' "$truepng_opts" | sed 's/.//')" # execute TruePNG through wine cd "$truepng_dir" || cd_error "$truepng_dir" IFS=' ' wine ./"$truepng_file" $truepng_opts $pngfiles