install_connectprotocol.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # Adds the handler for the connect protocol for AssaultCube to your system.
  3. CUBE_DIR=$(dirname "$(readlink -f "${0}")")
  4. CUBE_EXEC=assaultcube.sh
  5. LAUNCHERPATH="${HOME}/.local/share/applications/"
  6. LAUNCHERFILE=assaultcube-connectprotocol.desktop
  7. LAUNCHERTITLE="AssaultCube Connect Protocol"
  8. # Remove existing desktop entries, if they exist:
  9. # avoiding clashing with menuitem scripts & filenames which look for "assaultcube*"
  10. EXISTINGEXEC=`find "${LAUNCHERPATH}" -name "connectprotocol-assaultcube*" | xargs`
  11. if [ "$EXISTINGEXEC" != "" ]; then
  12. echo "The following entries currently exist:"
  13. echo "$EXISTINGEXEC"
  14. read -p "Would you like them all to be deleted? (y/N): " -r REPLY
  15. if [ "$REPLY" = "y" ] || [ "$REPLY" = "yes" ] || [ "$REPLY" = "Y" ] || [ "$REPLY" = "YES" ]; then
  16. find "${LAUNCHERPATH}" -name "connectprotocol-assaultcube*" -delete
  17. echo "Deleted entries as requested." && echo ""
  18. exit 0
  19. else
  20. echo "The existing entries will remain." && echo ""
  21. fi
  22. fi
  23. mkdir -p "${LAUNCHERPATH}"
  24. cat > "${LAUNCHERPATH}"${LAUNCHERFILE} << EOF
  25. [Desktop Entry]
  26. Type=Application
  27. Name=$LAUNCHERTITLE
  28. StartupNotify=false
  29. Exec=$CUBE_DIR/$CUBE_EXEC %u
  30. MimeType=x-scheme-handler/assaultcube;
  31. EOF
  32. havexdgmime=$(which xdg-mime)
  33. if [ "$havexdgmime" != "" ]; then
  34. # ignoring any previously registered handler. this should be the current default.
  35. xdg-mime default assaultcube-connectprotocol.desktop x-scheme-handler/assaultcube
  36. worked=$(xdg-mime query default x-scheme-handler/assaultcube 2>/dev/null)
  37. if [ "$worked" != "${LAUNCHERFILE}" ]; then
  38. # non-empty output should be the desktop filename
  39. # due to the EXISTINGEXEC routine we can leave the desktop entry for analysis
  40. echo "The AssaultCube desktop entry could not be hooked to the x-scheme-handler/assaultcube mimetype."
  41. exit 1
  42. fi
  43. else
  44. echo "your system does not appear to have xdg-mime to register an x-scheme-handler for the AssaultCube connect protocol."
  45. # you are welcome to provide a patch via PR on our github https://github.com/assaultcube/AC/
  46. fi
  47. if [ -f "${LAUNCHERPATH}"${LAUNCHERFILE} ]; then
  48. echo "The AssaultCube connect protocol desktop entry has been successfully created at"
  49. echo "${LAUNCHERPATH}"${LAUNCHERFILE}
  50. exit 0
  51. else
  52. echo "For some reason, we're unable to install the AssaultCube connect protocol desktop entry."
  53. exit 1
  54. fi