#!/usr/bin/env sh # ©2021 Brainwrecked Tech # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # For a copy of this license, see . APPS_DIR="${HOME}/.local/share/applications/ssb" WAPPDIRF="${HOME}/.local/share/desktop-directories/web-applications.directory" WAPPMENF="${HOME}/.config/menus/applications-merged/web-applications.menu" WAPPNAME="${1}" WAPPDESC="${2}" WAPPADDR="${3}" WAPPICON="${4}" ### MAKE SURE THE WEB APP DIRECTORY ENTRY EXISTS if [ ! -e "${WAPPDIRF}" ]; then cat << EOF > "${WAPPDIRF}" [Desktop Entry] Type=Directory Encoding=UTF-8 Name=Web Applications EOF fi ### MAKE SURE THE WEB APP MENU ENTRY EXISTS if [ ! -e "${WAPPMENF}" ]; then cat << EOF > "${WAPPMENF}" Applications Web Applications web-applications.directory WebApplications EOF fi ### MAKE SURE THE DIRECTORY FOR WEB APPS EXISTS mkdir -p "${APPS_DIR}" ### ASK FOR AN APPLICATION NAME IF $1 WASN'T SPECIFIED if [ -z "${WAPPNAME}" ]; then printf 'Application Name: ' read -r WAPPNAME fi ### ASK FOR A DESCRIPTION IF $2 WASN'T SPECIFIED if [ -z "${WAPPDESC}" ]; then printf 'Description: ' read -r WAPPDESC fi ### ASK FOR AN APPLICATION URL IF $3 WASN'T SPECIFIED if [ -z "${WAPPADDR}" ]; then printf '\nMake sure this is the address that you want to initially show.' printf '\nThis is usually NOT the address of the login screen.\n' printf '\nApplication Addr: ' read -r WAPPADDR fi ### ASK FOR AN APPLICATION ICON IF $4 WASN'T SPECIFIED if [ -z "${WAPPICON}" ]; then printf '\nNo need to download an icon -- give the URL to an image and this script' printf '\nwill grab it, rename it, and put it in the right place.\n' printf '\nApplication Icon: ' read -r WAPPICON printf '\n' fi ICON_LOC="${APPS_DIR}/${WAPPNAME,,}.${WAPPICON##*.}" DSKTPFIL="${APPS_DIR}/${WAPPNAME,,}.desktop" ### CREATE DIRECTORY FOR FIREFOX CACHE printf -- ':: ' && mkdir -pv "/run/user/${UID}/${WAPPNAME,,}-ssb" ### GRAB THE ICON AND WRITE IT TO THE WEB APP ICON DIRECTORY curl -s "${WAPPICON}" -o "${ICON_LOC}" -w ':: curl: wrote "%{url_effective}" to "%{filename_effective}"\n' ### CREATE A NEW PROFILE FOR THIS WEB APP /usr/bin/firefox -CreateProfile "${WAPPNAME,,}-ssb" -no-remote ### FIND THE DIRECTORY FIREFOX CREATED FFPFDIR="$(find "${HOME}/.mozilla/firefox" -type d -name '*'."${WAPPNAME,,}-ssb")" ### INJECT PREFERENCES echo 'user_pref("browser.cache.disk.parent_directory", "/run/user/'"${UID}"'/'"${WAPPNAME}"'-ssb");' >> "${FFPFDIR}/user.js" echo 'user_pref("browser.ssb.enabled", true);' >> "${FFPFDIR}/user.js" echo 'user_pref("extensions.pocket.enabled", false);' >> "${FFPFDIR}/user.js" echo 'user_pref("privacy.donottrackheader.enabled", true);' >> "${FFPFDIR}/user.js" ### CREATE A DESKTOP ENTRY FOR THE WEB APP echo "[Desktop Entry] Name=${WAPPNAME} (SSB) GenericName=${WAPPDESC} Exec=firefox -P ${WAPPNAME,,}-ssb --class ${WAPPNAME,,}-ssb --no-remote --ssb ${WAPPADDR} StartupNotify=true Terminal=false Type=Application Categories=WebApplications Icon=${ICON_LOC} StartupWMClass=${WAPPNAME,,}-ssb" > "${DSKTPFIL}" && printf -- ':: echo: created %s\n' "${DSKTPFIL}"