File install-geogebra-mime-data of Package geogebra-mime-data
#!/bin/bash
#---------------------------------------------
# Script to install the Mime database for GeoGebra files
#
# @author Christian Schött <schoett@gmx.de>
#---------------------------------------------
#---------------------------------------------
# Used environment variables:
#
# INSTALL=<path of install macro> # If unset, './install-sh' will be used. (Distributors may want to set their own install macro.)
#
# CHMOD=<path of chmod macro> # If unset, 'chmod' will be used. (Distributors may want to set their own chmod macro.)
#
# BINDIR=<path for executable binary files> # If unset, 'usr/bin' will be used.
#
# DATADIR=<path for data files> # If unset, '/usr/share' will be used.
#
# CREATE_UNINSTALLER=<boolean> # If unset, 'false' will be used. (Distributors normally have their own uninstaller.)
#
# VERBOSE_MODE=<boolean> # If unset, 'false' will be used.
#
# PREFIX=<path> # If unset, '' will be used.
#---------------------------------------------
# If $INSTALL not set, use './install-sh'.
if [ -z "$INSTALL" ]; then
INSTALL="./install-sh"
fi
#---------------------------------------------
# If $CHMOD not set, use 'chmod'.
if [ -z "$CHMOD" ]; then
CHMOD="chmod"
fi
#---------------------------------------------
# If $BINDIR not set, use '/usr/bin'.
if [ -z "$BINDIR" ]; then
BINDIR="/usr/bin"
fi
#---------------------------------------------
# If $DATADIR not set, use '/usr/share'.
if [ -z "$DATADIR" ]; then
DATADIR="/usr/share"
fi
#---------------------------------------------
# If $CREATE_UNINSTALLER not set, use 'false'.
if [ -z "$CREATE_UNINSTALLER" ]; then
CREATE_UNINSTALLER="false"
fi
#---------------------------------------------
# If $VERBOSE_MODE not set, use 'false'.
if [ -z "$VERBOSE_MODE" ]; then
VERBOSE_MODE='false'
fi
#---------------------------------------------
# If $PREFIX not set, use ''.
if [ -z "$PREFIX" ]; then
PREFIX=''
fi
#---------------------------------------------
# Define usage function.
function func_usage
{
cat << _USAGE
Usage: install-geogebra-mime-data [Options]
Install the Mime database for GeoGebra files
Options:
--help Print this help message
--install=<path of install macro> If unset, '$INSTALL' will be used.
--chmod=<path of chmod macro> If unset, '$CHMOD' will be used.
--bindir=<path for executable binary files> If unset, '$BINDIR' will be used.
--datadir=<path for data files> If unset, '$DATADIR' will be used.
--create_uninstaller=<boolean> If unset, '$CREATE_UNINSTALLER' will be used.
--verbose_mode=<boolean> If unset, '$VERBOSE_MODE' will be used. If unset, 'false' will be used.
--prefix=<path> If unset, '$PREFIX' will be used.
_USAGE
}
#---------------------------------------------
# Check for options.
for i in "$@"; do
case "$i" in
--help | --hel | --he | --h )
func_usage; exit 0 ;;
esac
if [ $(expr match "$i" '.*--install=') -ne 0 ]; then
INSTALL=${i:10}
shift $((1))
elif [ $(expr match "$i" '.*--chmod=') -ne 0 ]; then
CHMOD=${i:8}
shift $((1))
elif [ $(expr match "$i" '.*--bindir=') -ne 0 ]; then
BINDIR=${i:9}
shift $((1))
elif [ $(expr match "$i" '.*--datadir=') -ne 0 ]; then
DATADIR=${i:10}
shift $((1))
elif [ $(expr match "$i" '.*--create_uninstaller=') -ne 0 ]; then
CREATE_UNINSTALLER=${i:21}
shift $((1))
elif [ $(expr match "$i" '.*--verbose_mode=') -ne 0 ]; then
VERBOSE_MODE=${i:15}
shift $((1))
elif [ $(expr match "$i" '.*--prefix=') -ne 0 ]; then
PREFIX=${i:9}
shift $((1))
fi
done
#---------------------------------------------
# Install everything.
INSTALLED_DIRECTORIES=()
INSTALLED_FILES=()
function install_dir
{
if [ ! -w "$PREFIX$1" ]; then
"$INSTALL" -d -m 755 "$PREFIX$1"
fi
INSTALLED_DIRECTORIES[${#INSTALLED_DIRECTORIES[*]}]="$1"
}
function install_file
{
if [ -d "$PREFIX$2" ]; then
"$INSTALL" -m 644 "$1" "$PREFIX$2"
INSTALLED_FILES[${#INSTALLED_FILES[*]}]="$2/`basename $1`"
else
"$INSTALL" -m 644 "$1" "$PREFIX$2"
INSTALLED_FILES[${#INSTALLED_FILES[*]}]="$2"
fi
}
install_dir "$DATADIR"
install_dir "$DATADIR/icons"
install_dir "$DATADIR/icons/hicolor"
for SIZE in 16x16 22x22 32x32 48x48 64x64 128x128 256x256; do
install_dir "$DATADIR/icons/hicolor/$SIZE"
install_dir "$DATADIR/icons/hicolor/$SIZE/mimetypes"
install_file "icons/hicolor/$SIZE/mimetypes/application-vnd.geogebra.file.png" "$DATADIR/icons/hicolor/$SIZE/mimetypes"
install_file "icons/hicolor/$SIZE/mimetypes/application-vnd.geogebra.tool.png" "$DATADIR/icons/hicolor/$SIZE/mimetypes"
done
install_dir "$DATADIR/mime"
install_dir "$DATADIR/mime/packages"
install_file 'geogebra.xml' "$DATADIR/mime/packages"
# Create uninstall script, if $CREATE_UNINSTALLER is not set 'false':
if [ "$CREATE_UNINSTALLER" != "false" ]; then
install_dir "$BINDIR"
cat > "$PREFIX$BINDIR/uninstall-geogebra-mime-data" << EOF
#!/bin/bash
#---------------------------------------------
# Script to uninstall the Mime database for GeoGebra files
#---------------------------------------------
# Define usage function:
function func_usage
{
cat << _USAGE
Usage: uninstall-geogebra-mime-data [Options]
Uninstall the Mime database for GeoGebra files
Options:
--help Print this help message
--force Uninstall without asking questions
_USAGE
}
# Check for options:
FORCE="false"
for i in "\$@"; do
case "\$i" in
--help | --hel | --he | --h )
func_usage; exit 0 ;;
esac
if [ "\$i" = '--force' ]; then
FORCE="true"
fi
done
# Ask to continue, if option --force is not used:
if [ "\$FORCE" = "false" ]; then
KDIALOG_possible="false"
QDBUS_possible="false"
ZENITY_possible="false"
XDIALOG_possible="false"
if [ "\$UID" != "0" ]; then
KDIALOG_possible="true"
QDBUS_possible="false"
ZENITY_possible="false"
XDIALOG_possible="false"
type -P kdialog &>/dev/null || KDIALOG_possible="false"
if [ "\$KDIALOG_possible" = "true" ]; then
QDBUS_possible="true"
type -P qdbus &>/dev/null || QDBUS_possible="false"
else
ZENITY_possible="true"
type -P zenity &>/dev/null || ZENITY_possible="false"
if [ "\$ZENITY_possible" = "false" ]; then
XDIALOG_possible="true"
type -P Xdialog &>/dev/null || XDIALOG_possible="false"
fi
fi
fi
ANSWER=1
if [ "\$KDIALOG_possible" = "true" ]; then
kdialog --caption "Mime database for GeoGebra files" --warningcontinuecancel "This will uninstall the Mime database for GeoGebra files."
ANSWER=\$?
elif [ "\$ZENITY_possible" = "true" ]; then
zenity --title="Mime database for GeoGebra files" --warning --text="This will uninstall the Mime database for GeoGebra files."
ANSWER=\$?
elif [ "\$XDIALOG_possible" = "true" ]; then
Xdialog --title "Mime database for GeoGebra files" --yesno "This will uninstall the Mime database for GeoGebra files.\n\nDo you want to continue?" 0 0
ANSWER=\$?
else
echo "This will uninstall the Mime database for GeoGebra files."
tput bold
read -p "Do you want to continue? [y/n]: "
tput sgr0
case "\$REPLY" in
y | Y | yes | Yes | YES )
ANSWER=0 ;;
esac
fi
if [ \$ANSWER != 0 ]; then
exit 0
fi
fi
# Uninstall files and show progressbar during uninstallation, if possible and option --force is not used:
if [ "\$KDIALOG_possible" = "true" -a "\$QDBUS_possible" = "true" -a "\$FORCE" = "false" ]; then
DBUSREF=\`kdialog --caption "Mime database for GeoGebra files" --progressbar "Uninstalling the Mime database for GeoGebra files." 1\`
fi
INSTALLED_FILES=(${INSTALLED_FILES[*]})
for ((i=\${#INSTALLED_FILES[@]}-1; i>=0; i--)); do
if [ -w "\${INSTALLED_FILES[\$i]}" ]; then
rm -f "\${INSTALLED_FILES[\$i]}"
fi
done
# Run update-mime-database, if possible:
UPDATE_MIME_DATABASE_possible="true"
type -P update-mime-database &>/dev/null || UPDATE_MIME_DATABASE_possible="false"
if [ "\$UPDATE_MIME_DATABASE_possible" = "true" ]; then
update-mime-database "$DATADIR/mime" >/dev/null
else
echo "Could not execute command 'update-mime-database $DATADIR/mime'."
fi
INSTALLED_DIRECTORIES=(${INSTALLED_DIRECTORIES[*]})
for ((i=\${#INSTALLED_DIRECTORIES[@]}-1; i>=0; i--)); do
case "\${INSTALLED_DIRECTORIES[\$i]}" in
"$BINDIR" | "$DATADIR" )
continue ;;
esac
if [ -w "\${INSTALLED_DIRECTORIES[\$i]}" ]; then
rmdir --ignore-fail-on-non-empty "\${INSTALLED_DIRECTORIES[\$i]}"
fi
done
if [ "\$KDIALOG_possible" = "true" -a "\$QDBUS_possible" = "true" -a "\$FORCE" = "false" ]; then
qdbus \$DBUSREF Set "" value 1 >/dev/null
qdbus \$DBUSREF setLabelText "Uninstallation completed." >/dev/null
qdbus \$DBUSREF close >/dev/null
fi
# Selfdestruction:
if [ -w "$BINDIR/uninstall-geogebra-mime-data" ]; then
rm -f "$BINDIR/uninstall-geogebra-mime-data"
fi
EOF
INSTALLED_FILES[${#INSTALLED_FILES[*]}]="$BINDIR/uninstall-geogebra-mime-data"
"$CHMOD" u+x "$PREFIX$BINDIR/uninstall-geogebra-mime-data"
fi
# List pathes of installed files, if $VERBOSE_MODE is not set 'false':
if [ "$VERBOSE_MODE" != "false" ]; then
echo "`tput smul`Files of package 'geogebra-mime-data'`tput sgr0`"
for FILEPATH in ${INSTALLED_FILES[*]}; do
if [ -e "$PREFIX$FILEPATH" ]; then
echo "$FILEPATH"
fi
done
fi