#!/bin/bash MCORE_LIBDIR="@@MCORE_LIBDIR@@" source @@SYSCONFDIR@@/mcore/mcore.conf source ${MCORE_LIBDIR}/include/common.global.class GLOBAL_PIXMAPS_PATH="@@GLOBAL_PIXMAPS_PATH@@" LOCAL_PIXMAPS_PATH="${MCORE_CONFIG_PATH}/icons/default" ICON_INFO_PATH="${MCORE_CONFIG_PATH}/icons/info" ICON_INFO_SUFFIX="@@ICON_INFO_SUFFIX@@" ICON_SUFFIX="@@ICON_SUFFIX@@" die() { echo "ERROR: $@"; exit 1; } # very basic getops for i in $* do case $1 in --add|--del|--print) method="${1//--}" ;; --resource|-r) shift; icon_resource="$1" ;; --name|-n) shift; argv_name="$1" ;; --command|-c) shift; argv_command="$1" ;; --icon|-i) shift; argv_icon="$1" ;; --filename|-f) shift; argv_filename="$1" ;; --xpos|-x) shift; argv_xpos="$1" ;; --ypos|-y) shift; argv_ypos="$1" ;; --icon-width|-w) shift; argv_iwidth="$1" ;; --icon-height|-h) shift; argv_iheight="$1" ;; --default-icon) shift; argv_deficon="$1" ;; esac shift done # some sanity checks: [[ -z ${method} ]] && die "No method given" case "${method}" in add) if [[ -n ${icon_resource} ]] then [[ -f ${icon_resource} ]] || die "Icon resource '${icon_resource}' does not exist" else name="${argv_name}" command="${argv_command}" filename="${argv_filename}" xpos="${argv_xpos}" ypos="${argv_ypos}" icon="${argv_icon}" deficon="${argv_deficon}" iwidth="${argv_iwidth}" iheight="${argv_iheight}" # abort if name or command not given [[ -z ${name} ]] && die "No name given" [[ -z ${command} ]] && die "No command given" [[ -z ${filename} ]] && filename="${name}" # use some defaults for icon, dest, {x,y}pos [[ -z ${xpos} ]] && xpos=50 [[ -z ${ypos} ]] && ypos=50 if [[ -z ${icon} ]] then # if no default icon is given use default.png [[ -z ${deficon} ]] && deficon="default.png" icon="${deficon}" fi ${MCORE_LIBDIR}/idesk-generate-icon-info \ --add \ --name "${name}" \ --command "${command}" \ --icon "${icon}" \ --filename "${filename}" \ --xpos "${xpos}" \ --ypos "${ypos}" \ --icon-width "${iwidth}" \ --icon-height "${iheight}" \ --default-icon "${deficon}" \ || die "adding icon-info" icon_resource="${ICON_INFO_PATH}/${filename}.${ICON_INFO_SUFFIX}" fi source "${icon_resource}" # icon resource overrides [[ -n ${argv_name} ]] && name="${argv_name}" [[ -n ${argv_command} ]] && command="${argv_command}" [[ -n ${argv_filename} ]] && filename="${argv_filename}" [[ -n ${argv_xpos} ]] && xpos="${argv_xpos}" [[ -n ${argv_ypos} ]] && ypos="${argv_ypos}" [[ -n ${argv_icon} ]] && icon="${argv_icon}" [[ -n ${argv_deficon} ]] && deficon="${argv_deficon}" [[ -n ${argv_iwidth} ]] && iwidth="${argv_iwidth}" [[ -n ${argv_iheight} ]] && iheight="${argv_iheight}" [[ -z ${filename} ]] && die "Error \$filename is empty in icon resource '${icon_resource}'" # get the right icon path, local overrides global [[ -f ${GLOBAL_PIXMAPS_PATH}/${icon} ]] && icon_path="${GLOBAL_PIXMAPS_PATH}" [[ -f ${LOCAL_PIXMAPS_PATH}/${icon} ]] && icon_path="${LOCAL_PIXMAPS_PATH}" # no icon found, use default icon if [[ -z ${icon_path} ]] then icon_path="${GLOBAL_PIXMAPS_PATH}" icon="default.png" fi CONFIG="${MCORE_UNPRIV_HOME}/.config/idesktop/${filename}.${ICON_SUFFIX}" clearconfig # fix permissions chown "${MCORE_UNPRIV_USER}":"${MCORE_UNPRIV_GROUP}" "${MCORE_UNPRIV_HOME}/.config/idesktop" addconfig 'table Icon' addconfig " Caption: ${name}" addconfig " Command: ${command}" addconfig " Icon: ${icon_path}/${icon}" addconfig " X: ${xpos}" addconfig " Y: ${ypos}" # add these only if not zero if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]] then addconfig " Width: ${iwidth}" addconfig " Height: ${iheight}" fi addconfig 'end' ;; del) if [[ -n ${icon_resource} ]] then [[ -f ${icon_resource} ]] || die "Icon resource '${icon_resource}' does not exist" source "${icon_resource}" fi # icon resource overrides [[ -n ${argv_name} ]] && name="${argv_name}" [[ -n ${argv_command} ]] && command="${argv_command}" [[ -n ${argv_filename} ]] && filename="${argv_filename}" [[ -n ${argv_xpos} ]] && xpos="${argv_xpos}" [[ -n ${argv_ypos} ]] && ypos="${argv_ypos}" [[ -n ${argv_icon} ]] && icon="${argv_icon}" [[ -n ${argv_deficon} ]] && deficon="${argv_deficon}" [[ -n ${argv_iwidth} ]] && iwidth="${argv_iwidth}" [[ -n ${argv_iheight} ]] && iheight="${argv_iheight}" [[ -z ${filename} ]] && filename="${name}" ${MCORE_LIBDIR}/idesk-generate-icon-info --del --name "${name}" --filename "${filename}" || die "deleting icon info" if [[ -f ${MCORE_UNPRIV_HOME}/.config/idesktop/${filename}.${ICON_SUFFIX} ]] then rm ${MCORE_UNPRIV_HOME}/.config/idesktop/${filename}.${ICON_SUFFIX} fi ;; print) ${MCORE_LIBDIR}/idesk-generate-icon-info --print ;; esac