#!/bin/bash ACTION="$1" DEST_DOWNLOAD=$HOME"/Applications/" SLIC3R_DEST_FILE="slic3r-appimage" SLIC3R_APPIMAGE="Slic3r-latest.AppImage" CURA_DEST_FILE="ultimaker_cura-appimage" CURA_APPIMAGE="Ultimaker_Cura-latest.AppImage" PRUSA_DEST_FILE="prusaslicer-appimage" PRUSA_APPIMAGE="PrusaSlicer-latest.AppImage" URL="http://lliurex.net/recursos/" DESKTOP_ORIG_SLIC3R="/usr/share/zero-lliurex-3d-print/slic3r-appimage.desktop" DESKTOP_NAME_SLIC3R="slic3r-appimage.desktop" DESKTOP_ORIG_CURA="/usr/share/zero-lliurex-3d-print/ultimaker_cura-appimage.desktop" DESKTOP_NAME_CURA="ultimaker_cura-appimage.desktop" DESKTOP_ORIG_PRUSA="/usr/share/zero-lliurex-3d-print/prusaslicer-appimage.desktop" DESKTOP_NAME_PRUSA="prusaslicer-appimage.desktop" DESKTOP_DEST=$HOME"/.local/share/applications/" MIME_DEST=$HOME"/.local/share/mime/" LINK_PATH=$HOME"/.local/bin/" shift PACKAGE_LIST=$@ function download_appimage(){ if [ -s ${DEST_DOWNLOAD}"$1" ] then rm -f ${DEST_DOWNLOAD}"$1" fi wget ${URL}"$2" -O ${DEST_DOWNLOAD}"$1" if ! [ -s ${DEST_DOWNLOAD}"$1" ] then echo 1 else echo 0 fi } function install_appimage(){ if [ -s ${DEST_DOWNLOAD}"$1" ] then chmod +x ${DEST_DOWNLOAD}"$1" if ! [ -e ${LINK_PATH}"$1" ] then ln -s ${DEST_DOWNLOAD}"$1" ${LINK_PATH}"$1" fi cp "$2" $DESKTOP_DEST sed -i "s#%%HOME%%#$HOME#" ${DESKTOP_DEST}"$3" chmod +x ${DESKTOP_DEST}"$3" echo 0 else echo 1 fi } function remove_appimage(){ if [ -s ${DEST_DOWNLOAD}"$1" ] then rm -f ${DEST_DOWNLOAD}"$1" fi if [ -s ${DEST_DOWNLOAD}"$1" ] then echo 1 else rm -f ${DESKTOP_DEST}"$2" rm -f ${LINK_PATH}"$1" echo 0 fi } case $ACTION in getStatus) for ix in $PACKAGE_LIST do if [[ " $ix " == " ${SLIC3R_DEST_FILE} " ]];then if [ -s ${DEST_DOWNLOAD}${SLIC3R_DEST_FILE} ] then echo 0 else echo 1 fi elif [[ " $ix " == " ${CURA_DEST_FILE} " ]];then if [ -s ${DEST_DOWNLOAD}${CURA_DEST_FILE} ] then echo 0 else echo 1 fi elif [[ " $ix " == " ${PRUSA_DEST_FILE} " ]];then if [ -s ${DEST_DOWNLOAD}${PRUSA_DEST_FILE} ] then echo 0 else echo 1 fi else echo "Not found" fi done ;; download) pkgs_selected=0 errors=0 if ! [ -d ${DEST_DOWNLOAD} ] then mkdir ${DEST_DOWNLOAD} fi cd ${DEST_DOWNLOAD} for ix in $PACKAGE_LIST do ((pkgs_selected=pkgs_selected+1)) if [[ " $ix " == " ${SLIC3R_DEST_FILE} " ]];then echo "Downlodading "${SLIC3R_DEST_FILE} res=$(download_appimage ${SLIC3R_DEST_FILE} ${SLIC3R_APPIMAGE}) if [ $res -ge 1 ];then ((errors=errors+1)) fi elif [[ " $ix " == " ${CURA_DEST_FILE} " ]];then echo "Downlodading "${CURA_DEST_FILE} res=$(download_appimage ${CURA_DEST_FILE} ${CURA_APPIMAGE}) if [ $res -ge 1 ];then ((errors=errors+1)) fi elif [[ " $ix " == " ${PRUSA_DEST_FILE} " ]];then echo "Downlodading "${PRUSA_DEST_FILE} res=$(download_appimage ${PRUSA_DEST_FILE} ${PRUSA_APPIMAGE}) if [ $res -ge 1 ];then ((errors=errors+1)) fi fi done if [ $errors -ge $pkgs_selected ];then exit 1 fi ;; installPackage) pkgs_selected=0 errors=0 if ! [ -d ${LINK_PATH} ] then mkdir ${LINK_PATH} fi if ! [ -d ${DESKTOP_DEST} ] then mkdir ${DESKTOP_DEST} fi if ! [ -d ${DESKTOP_DEST}"packages" ] then mkdir ${DESKTOP_DEST}"packages" fi if ! [ -d ${MIME_DEST} ] then mkdir ${MIME_DEST} fi if ! [ -d ${MIME_DEST}"packages" ] then mkdir ${MIME_DEST}"packages" fi for ix in $PACKAGE_LIST do ((pkgs_selected=pkgs_selected+1)) if [[ " $ix " == " ${SLIC3R_DEST_FILE} " ]];then echo "Preparing "${SLIC3R_DEST_FILE} res=$(install_appimage ${SLIC3R_DEST_FILE} ${DESKTOP_ORIG_SLIC3R} ${DESKTOP_NAME_SLIC3R}) if [ $res -ge 1 ];then ((errors=errors+1)) fi elif [[ " $ix " == " ${CURA_DEST_FILE} " ]];then echo "Preparing "${CURA_DEST_FILE} res=$(install_appimage ${CURA_DEST_FILE} ${DESKTOP_ORIG_CURA} ${DESKTOP_NAME_CURA}) if [ $res -ge 1 ];then ((errors=errors+1)) fi elif [[ " $ix " == " ${PRUSA_DEST_FILE} " ]];then echo "Preparing "${PRUSA_DEST_FILE} res=$(install_appimage ${PRUSA_DEST_FILE} ${DESKTOP_ORIG_PRUSA} ${DESKTOP_NAME_PRUSA}) if [ $res -ge 1 ];then ((errors=errors+1)) fi fi done sleep 15 update-mime-database $MIME_DEST >/dev/null 2>/dev/null || true update-desktop-database $DESKTOP_DEST >/dev/null 2>/dev/null || true if [ $errors -ge $pkgs_selected ];then exit 1 fi ;; remove) echo "Removing files..." pkgs_selected=0 errors=0 for ix in $PACKAGE_LIST do ((pkgs_selected=pkgs_selected+1)) if [[ " $ix " == " ${SLIC3R_DEST_FILE} " ]];then echo "Removing "${SLIC3R_DEST_FILE} res=$(remove_appimage ${SLIC3R_DEST_FILE} ${DESKTOP_NAME_SLIC3R}) if [ $res -ge 1 ];then ((errors=errors+1)) fi elif [[ " $ix " == " ${CURA_DEST_FILE} " ]];then echo "Removing "${CURA_DEST_FILE} res=$(remove_appimage ${CURA_DEST_FILE} ${DESKTOP_NAME_CURA}) if [ $res -ge 1 ];then ((errors=errors+1)) fi elif [[ " $ix " == " ${PRUSA_DEST_FILE} " ]];then echo "Removing "${PRUSA_DEST_FILE} res=$(remove_appimage ${PRUSA_DEST_FILE} ${DESKTOP_NAME_PRUSA}) if [ $res -ge 1 ];then ((errors=errors+1)) fi fi done if [ $errors -ge $pkgs_selected ];then exit 1 fi ;; esac exit 0