You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
7.8 KiB
243 lines
7.8 KiB
#!/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"
|
|
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
|
|
"chromium") WASUFFIX="pwa" ; BRWSRBIN="chromium" ; break;;
|
|
"firefox") WASUFFIX="ssb" ; BRWSRBIN="firefox" ; break;;
|
|
"google-chrome") WASUFFIX="pwa" ; BRWSRBIN="google-chrome" ; break;;
|
|
"epiphany") WASUFFIX="ewa" ; BRWSRBIN="epiphany" ; break;;
|
|
"iridium") WASUFFIX="pwa" ; BRWSRBIN="iridium-browser" ; break;;
|
|
esac
|
|
|
|
### PLACES FOR STUFF
|
|
if [ "${WA_BRWSR}" = "epiphany" ]; then
|
|
WAPP_PRE="org.gnome.Epiphany.WebApp-"
|
|
WAPP_DIR="${SHAREDIR}/${WAPP_PRE}${WAPPNAME,,}"
|
|
WAPP_ICO="${WAPP_DIR}/app-icon.${WAPPICON##*.}"
|
|
WAPP_DTF="${WAPP_DIR}/${WAPP_PRE}${WAPPNAME,,}.desktop"
|
|
else
|
|
WAPP_DIR="${APPS_DIR}/${WASUFFIX}"
|
|
WAPP_ICO="${ICONSDIR}/${WASUFFIX}/${WAPPNAME,,}.${WAPPICON##*.}"
|
|
WAPP_DTF="${APPS_DIR}/${WASUFFIX}/${WAPPNAME,,}.desktop"
|
|
fi
|
|
|
|
### PROFILE SETTINGS
|
|
if [ "${WASUFFIX}" = "pwa" ]; then
|
|
|
|
WAPP_DPF="${CONF_DIR}/${WA_BRWSR}/${WASUFFIX}-default"
|
|
WAPP_PRF="${CONF_DIR}/${WA_BRWSR}/${WASUFFIX}-${WAPPNAME,,}"
|
|
|
|
elif [ "${WASUFFIX}" = "ssb" ]; then
|
|
|
|
### CREATE DIRECTORY FOR FIREFOX CACHE
|
|
printf -- ':: ' && mkdir -pv "/run/user/${UID}/ssb-${WAPPNAME,,}"
|
|
|
|
### CREATE A NEW PROFILE FOR THIS WEB APP
|
|
echo /usr/bin/firefox -CreateProfile "ssb-${WAPPNAME,,}" -no-remote
|
|
|
|
### FIND THE DIRECTORY FIREFOX CREATED
|
|
FFPFDIR="$(find "${HOME}/.mozilla/firefox" -type d -name '*'."ssb-${WAPPNAME,,}")"
|
|
|
|
### INJECT PREFERENCES
|
|
USRPREF1='user_pref("browser.cache.disk.parent_directory", "/run/user/'"${UID}"'/ssb-'"${WAPPNAME,,}"');'
|
|
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 SURE pwa-default PROFILE EXISTS, COPY IT TO NEW PROFILE.
|
|
if [ "${WASUFFIX}" = "pwa" ]; then
|
|
if [ ! -e "${WAPP_DPF}" ]; then
|
|
${BRWSRBIN} --user-data-dir="${WAPP_DPF}" --no-first-run --no-default-browser-check
|
|
fi
|
|
cp -a "${WAPP_DPF}" "${WAPP_PRF}"
|
|
fi
|
|
|
|
### MAKE SURE WEBAPP DIRECTORY EXISTS
|
|
printf -- ':: ' && mkdir -pv "${WAPP_DIR}"
|
|
|
|
### MAKE SURE ICONS DIRECTORY EXISTS
|
|
[ ! "${WASUFFIX}" = "ewa" ] && printf -- ':: ' && mkdir -pv "${ICONSDIR}/${WASUFFIX}"
|
|
|
|
### 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 "${WASUFFIX}" in
|
|
ewa) WAPP_CMD="${BRWSRBIN} --application-mode --profile='${WAPP_DIR}' ${WAPPADDR}";;
|
|
pwa) WAPP_CMD="${BRWSRBIN} --user-data-dir='${CONF_DIR}/${WA_BRWSR}/pwa-${WAPPNAME,,}' --class pwa-${WAPPNAME,,} --no-first-run --no-default-browser-check --app='${WAPPADDR}'";;
|
|
ssb) WAPP_CMD="${BRWSRBIN} -P ssb-${WAPPNAME,,} --class ssb-${WAPPNAME,,} --no-remote --ssb ${WAPPADDR}";;
|
|
esac
|
|
|
|
### CREATE WMCLASS FOR THE .desktop FILE
|
|
case "${WASUFFIX}" in
|
|
ewa) WAWMCLAS="${WAPP_PRE}${WAPPNAME,,}";;
|
|
pwa) WAWMCLAS="pwa-${WAPPNAME,,}";;
|
|
ssb) WAWMCLAS="ssb-${WAPPNAME,,}";;
|
|
esac
|
|
|
|
### CREATE A DESKTOP ENTRY FOR THE WEB APP
|
|
DTE0="[Desktop Entry]"
|
|
DTE1="Name=${WAPPNAME} (${WASUFFIX^^})"
|
|
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 "${WAPP_PRE}" ]; then
|
|
printf -- ':: ln -s: '
|
|
ln -sv "../${WAPP_PRE}${WAPPNAME,,}/${WAPP_PRE}${WAPPNAME,,}.desktop" "${APPS_DIR}/${WAPP_PRE}${WAPPNAME,,}.desktop"
|
|
fi
|
|
|
|
### CREATE A PROXIED VERSION
|
|
WAPP_DTF="${WAPP_DTF/.desktop/.proxied.desktop}"
|
|
[ "${WASUFFIX}" = "pwa" ] && PRX_MTHD="Local Proxy" && WAPP_CMD="${WAPP_CMD} --proxy-server='socks://127.0.0.1:8080'"
|
|
[ ! "${WASUFFIX}" = "pwa" ] && PRX_MTHD="Proxychains" && WAPP_CMD="proxychains ${WAPP_CMD}"
|
|
[ ! "${WASUFFIX}" = "ewa" ] && WAPP_CMD="${WAPP_CMD/--class ${WASUFFIX}-${WAPPNAME,,}/--class ${WASUFFIX}-${WAPPNAME,,}.proxy}"
|
|
WAWMCLAS="${WAWMCLAS/${WAPPNAME,,}/${WAPPNAME,,}.proxy}"
|
|
|
|
DTE0="[Desktop Entry]"
|
|
DTE1="Name=${WAPPNAME} (${WASUFFIX^^}) 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 "${WAPP_PRE}" ]; then
|
|
printf -- ':: ln -s: '
|
|
ln -sv "../${WAPP_PRE}${WAPPNAME,,}/${WAPP_PRE}${WAPPNAME,,}.proxied.desktop" "${APPS_DIR}/${WAPP_PRE}${WAPPNAME,,}.proxied.desktop"
|
|
fi
|