parent
8b703e9c10
commit
44553cdd39
@ -0,0 +1,229 @@
|
|||||||
|
#!/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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
CONF_DIR="${HOME}/.config"
|
||||||
|
EWA_PRFX="org.gnome.Epiphany.WebApp-"
|
||||||
|
LOCALDIR="${HOME}/.local"
|
||||||
|
SHAREDIR="${LOCALDIR}/share"
|
||||||
|
|
||||||
|
APPS_DIR="${SHAREDIR}/applications"
|
||||||
|
ICONSDIR="${SHAREDIR}/icons"
|
||||||
|
|
||||||
|
WAPPDIRF="${SHAREDIR}/desktop-directories/web-applications.directory"
|
||||||
|
WAPPMENF="${CONF_DIR}/menus/applications-merged/web-applications.menu"
|
||||||
|
|
||||||
|
WA_BRWSR="${1}"
|
||||||
|
WAPPNAME="${2}"
|
||||||
|
WAPPDESC="${3}"
|
||||||
|
WAPPADDR="${4}"
|
||||||
|
WAPPICON="${5}"
|
||||||
|
|
||||||
|
### 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}"
|
||||||
|
<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
|
||||||
|
"http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">
|
||||||
|
<Menu>
|
||||||
|
<Name>Applications</Name>
|
||||||
|
<Menu>
|
||||||
|
<Name>Web Applications</Name>
|
||||||
|
<Directory>web-applications.directory</Directory>
|
||||||
|
<Include>
|
||||||
|
<Category>WebApplications</Category>
|
||||||
|
</Include>
|
||||||
|
</Menu>
|
||||||
|
</Menu>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
### ASK FOR A BROWSER NAME IF $1 WASN'T SPECIFIED OR INVALID
|
||||||
|
|
||||||
|
if [ -z "${WA_BRWSR}" ]; then
|
||||||
|
printf 'Supported browsers are (google-)chrome, chromium, epiphany, firefox, iridium).\n'
|
||||||
|
printf 'Browser: '
|
||||||
|
read -r WA_BRWSR
|
||||||
|
fi
|
||||||
|
|
||||||
|
### ASK FOR AN APPLICATION NAME IF $2 WASN'T SPECIFIED
|
||||||
|
|
||||||
|
if [ -z "${WAPPNAME}" ]; then
|
||||||
|
printf 'Application Name: '
|
||||||
|
read -r WAPPNAME
|
||||||
|
fi
|
||||||
|
|
||||||
|
### ASK FOR A DESCRIPTION IF $3 WASN'T SPECIFIED
|
||||||
|
|
||||||
|
if [ -z "${WAPPDESC}" ]; then
|
||||||
|
printf 'Description: '
|
||||||
|
read -r WAPPDESC
|
||||||
|
fi
|
||||||
|
|
||||||
|
### ASK FOR AN APPLICATION URL IF $4 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 $5 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
|
||||||
|
|
||||||
|
### CORRECT SHORT NAMES TO FULL NAMES
|
||||||
|
[ "${WA_BRWSR}" ] = "chrome" && WA_BRWSR="google-chrome"
|
||||||
|
|
||||||
|
### SET SUFFIX AND BIN BASED ON BROWSER
|
||||||
|
case "${WA_BRWSR}" in
|
||||||
|
"chrome") WDSUFFIX="pwa" ; BRWSRBIN="google-chrome" ; break;;
|
||||||
|
"chromium") WDSUFFIX="pwa" ; BRWSRBIN="chromium" ; break;;
|
||||||
|
"firefox") WDSUFFIX="ssb" ; BRWSRBIN="firefox" ; break;;
|
||||||
|
"google-chrome") WDSUFFIX="pwa" ; BRWSRBIN="google-chrome" ; break;;
|
||||||
|
"epiphany") WDSUFFIX="ewa" ; BRWSRBIN="epiphany" ; break;;
|
||||||
|
"iridium") WDSUFFIX="pwa" ; BRWSRBIN="iridium-browser" ; break;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
### PLACES FOR STUFF
|
||||||
|
WAPP_DIR="${APPS_DIR}/${WDSUFFIX}"
|
||||||
|
WAPP_ICO="${ICONSDIR}/${WAPPNAME,,}.${WAPPICON##*.}"
|
||||||
|
WAPP_DTF="${APPS_DIR}/${WDSUFFIX}/${WAPPNAME,,}.desktop"
|
||||||
|
|
||||||
|
### EPIPHANY WEB APPS ARE SNOWFLAKE
|
||||||
|
|
||||||
|
if [ "${WA_BRWSR}" = "epiphany" ]; then
|
||||||
|
WAPP_DIR="${SHAREDIR}/${EWA_PRFX}${WAPPNAME,,}"
|
||||||
|
WAPP_ICO="${WAPP_DIR}/app-icon.${WAPPICON##*.}"
|
||||||
|
WAPP_DTF="${WAPP_DIR}/${EWA_PRFX}${WAPPNAME,,}.desktop"
|
||||||
|
else
|
||||||
|
EWA_PRFX=
|
||||||
|
fi
|
||||||
|
|
||||||
|
### FIREFOX IS ALSO SNOWFLAKE
|
||||||
|
if [ "${WA_BRWSR}" = "firefox" ]; then
|
||||||
|
|
||||||
|
### CREATE DIRECTORY FOR FIREFOX CACHE
|
||||||
|
printf -- ':: ' && mkdir -pv "/run/user/${UID}/${WAPPNAME,,}-ssb"
|
||||||
|
|
||||||
|
### CREATE A NEW PROFILE FOR THIS WEB APP
|
||||||
|
echo /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
|
||||||
|
USRPREF1='user_pref("browser.cache.disk.parent_directory", "/run/user/'"${UID}"'/'"${WAPPNAME,,}"'-ssb");'
|
||||||
|
USRPREF2='user_pref("browser.ssb.enabled", true);'
|
||||||
|
USRPREF3='user_pref("extensions.pocket.enabled", false);'
|
||||||
|
USRPREF4='user_pref("privacy.donottrackheader.enabled", true);'
|
||||||
|
printf '%s\n%s\n%s\n%s\n' "${USRPREF1}" "${USRPREF2}" "${USRPREF3}" "${USRPREF4}" > "${FFPFDIR}/user.js"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
### MAKE WEBAPP DIRECTORY
|
||||||
|
printf -- ':: ' && mkdir -pv "${WAPP_DIR}"
|
||||||
|
|
||||||
|
### SNOWFLAKE EPIPHANY REQUIRES A HIDDEN FILE IN THE WEBAPP DIRECTORY
|
||||||
|
[ "${WA_BRWSR}" = "epiphany" ] && touch "${WAPP_DIR}/.app"
|
||||||
|
|
||||||
|
### GRAB THE ICON AND WRITE IT TO THE WEB APP ICON DIRECTORY
|
||||||
|
curl -s "${WAPPICON}" -o "${WAPP_ICO}" -w ':: curl: wrote "%{url_effective}" to "%{filename_effective}"\n'
|
||||||
|
|
||||||
|
### CREATE COMMAND LINE FOR THE .desktop FILE
|
||||||
|
case "${WDSUFFIX}" in
|
||||||
|
ewa) WAPP_CMD="${BRWSRBIN} --application-mode --profile='${WAPP_DIR}' ${WAPPADDR}";;
|
||||||
|
pwa) WAPP_CMD="${BRWSRBIN} --user-data-dir='${CONF_DIR}/${WA_BRWSR}/${WAPPNAME,,}-pwa' --no-first-run --no-default-browser-check --app='${WAPPADDR}'";;
|
||||||
|
ssb) WAPP_CMD="${BRWSRBIN} -P ${WAPPNAME,,}-ssb --class ${WAPPNAME,,}-ssb --no-remote --ssb ${WAPPADDR}";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
### CREATE WMCLASS FOR THE .desktop FILE
|
||||||
|
case "${WDSUFFIX}" in
|
||||||
|
ewa) WAWMCLAS="${EWA_PRFX}${WAPPNAME,,}";;
|
||||||
|
pwa) WAWMCLAS="${WAPPNAME,,}-pwa";;
|
||||||
|
ssb) WAWMCLAS="${WAPPNAME,,}-ssb";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
### CREATE A DESKTOP ENTRY FOR THE WEB APP
|
||||||
|
DTE0="[Desktop Entry]"
|
||||||
|
DTE1="Name=${WAPPNAME} (${WDSUFFIX^^})"
|
||||||
|
DTE2="GenericName=${WAPPDESC}"
|
||||||
|
DTE3="Exec=${WAPP_CMD}"
|
||||||
|
DTE4="StartupNotify=true"
|
||||||
|
DTE5="Terminal=false"
|
||||||
|
DTE6="Type=Application"
|
||||||
|
DTE7="Categories=WebApplications"
|
||||||
|
DTE8="Icon=${WAPP_ICO}"
|
||||||
|
DTE9="StartupWMClass=${WAWMCLAS}"
|
||||||
|
|
||||||
|
printf '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' "${DTE0}" "${DTE1}" "${DTE2}" "${DTE3}" "${DTE4}" "${DTE5}" "${DTE6}" "${DTE7}" "${DTE8}" "${DTE9}" > "${WAPP_DTF}"
|
||||||
|
|
||||||
|
printf -- ':: chmod: '
|
||||||
|
chmod -v +x "${WAPP_DTF}"
|
||||||
|
|
||||||
|
if [ -n "${EWA_PRFX}" ]; then
|
||||||
|
printf -- ':: ln -s: '
|
||||||
|
ln -sv "../${EWA_PRFX}${WAPPNAME,,}/${EWA_PRFX}${WAPPNAME,,}.desktop" "${APPS_DIR}/${EWA_PRFX}${WAPPNAME,,}.desktop"
|
||||||
|
fi
|
||||||
|
|
||||||
|
### CREATE A PROXIED VERSION
|
||||||
|
WAPP_DTF="${WAPP_DTF/.desktop/.proxied.desktop}"
|
||||||
|
[ "${WDSUFFIX}" = "pwa" ] && PRX_MTHD="Local Proxy" && WAPP_CMD="${WAPP_CMD} --proxy-server=socks://127.0.0.1:8080"
|
||||||
|
[ ! "${WDSUFFIX}" = "pwa" ] && PRX_MTHD="Proxychains" && WAPP_CMD="proxychains ${WAPP_CMD}"
|
||||||
|
|
||||||
|
DTE0="[Desktop Entry]"
|
||||||
|
DTE1="Name=${WAPPNAME} (${WDSUFFIX^^}) via ${PRX_MTHD}"
|
||||||
|
DTE2="GenericName=${WAPPDESC}"
|
||||||
|
DTE3="Exec=${WAPP_CMD}"
|
||||||
|
DTE4="StartupNotify=true"
|
||||||
|
DTE5="Terminal=false"
|
||||||
|
DTE6="Type=Application"
|
||||||
|
DTE7="Categories=WebApplications"
|
||||||
|
DTE8="Icon=${WAPP_ICO}"
|
||||||
|
DTE9="StartupWMClass=${WAWMCLAS}"
|
||||||
|
|
||||||
|
printf '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' "${DTE0}" "${DTE1}" "${DTE2}" "${DTE3}" "${DTE4}" "${DTE5}" "${DTE6}" "${DTE7}" "${DTE8}" "${DTE9}" > "${WAPP_DTF}"
|
||||||
|
|
||||||
|
printf -- ':: chmod: '
|
||||||
|
chmod -v +x "${WAPP_DTF}"
|
||||||
|
|
||||||
|
if [ -n "${EWA_PRFX}" ]; then
|
||||||
|
printf -- ':: ln -s: '
|
||||||
|
ln -sv "../${EWA_PRFX}${WAPPNAME,,}/${EWA_PRFX}${WAPPNAME,,}.proxied.desktop" "${APPS_DIR}/${EWA_PRFX}${WAPPNAME,,}.proxied.desktop"
|
||||||
|
fi
|
Loading…
Reference in new issue