#!/usr/bin/env bash ERR=0 echo "$(tput bold)$(tput setaf 2)==>$(tput sgr0) $(tput bold)PRE-RUN CHECKS$(tput sgr0)" for CMD in node npm nativefier; do OUT=$(command -V ${CMD} 2> /dev/null) [ -n $"${OUT}" ] && echo " -> $(tput bold)${OUT}$(tput sgr0)" || { echo "$(tput bold)$(tput setaf 5)${CMD} not found$(tput sgr0)"; ERR=1; } done TRGT=(linux) if command -V wine &> /dev/null; then echo " -> $(tput bold)$(command -V wine)$(tput sgr0)...adding 'windows' to targets" TRGT+=(win32) else echo " -> $(tput bold)$(tput setaf 5)wine not found$(tput sgr0)...not adding 'windows' to targets" fi TRGT+=(darwin mas) [ ${ERR} -ne 0 ] && echo "$(tput bold)$(tput setaf 4)==>$(tput sgr0) $(tput bold)$(tput setaf 5)ABORTING$(tput sgr0)" && exit ${ERR} SRC="$(readlink -f "${BASH_SOURCE[0]//*\//}")" FQP="${SRC%\/*}" APP="${1}" EUF="${FQP}/urls/${APP}.url" [ -e "${EUF}" ] || { echo "${EUF} not found"; exit 2; } [ -L "${EUF}" ] && EUF="$(readlink -f "${EUF}")" [ -f "${EUF}" ] || { echo "${EUF} not a file"; exit 2; } for PLAT in "${TRGT[@]}"; do for ARCH in ia32 x64 armv7l; do [ "${PLAT}" = "win32" -a "${ARCH}" = "armv7l" ] && continue [ "${PLAT}" = "darwin" -a "${ARCH}" != "x64" ] && continue [ "${PLAT}" = "mas" -a "${ARCH}" != "x64" ] && continue echo "$(tput bold)$(tput setaf 2)==>$(tput sgr0) $(tput bold)${APP}-${PLAT}-${ARCH}$(tput sgr0)" URL="$(< "${EUF}")" EXE=(nativefier --platform "${PLAT}" --arch ${ARCH} --honest --disable-context-menu --disable-dev-tools --name "${APP}") case "${PLAT}" in linux|win32) EIF="${FQP}/icons/${APP}.png" [ -L "${EIF}" ] && EIF="$(readlink -f "${EIF}")" [ -f "${EIF}" ] && EXE+=(--icon "${EIF}") ;; darwin|mas) EIF="${FQP}/icons/${APP}.icns" [ -L "${EIF}" ] && EIF="$(readlink -f "${EIF}")" [ -f "${EIF}" ] && EXE+=(--icon "${EIF}") ;; esac [ "${PLAT}" = "darwin" -o "${PLAT}" = "mas" ] && [ ! -f "${EIF}" ] && \ echo " -> $(tput bold)$(tput setaf 5)Apple platforms require an .icns file$(tput sgr0)" && continue EIF="${FQP}/injects/${APP}.css" [ -L "${EIF}" ] && EIF="$(readlink -f "${EIF}")" [ -f "${EIF}" ] && EXE+=(--inject "${EIF}") EIF="${FQP}/injects/${APP}.js" [ -L "${EIF}" ] && EIF="$(readlink -f "${EIF}")" [ -f "${EIF}" ] && EXE+=(--inject "${EIF}") EXE+=("${URL}") mkdir -pv "${FQP}/${APP}" cd "${FQP}/${APP}" echo "${EXE[@]}" ${EXE[@]} case "${PLAT}" in linux) CPF="${FQP}/desktops/${APP}.desktop" [ -L "${CPF}" ] && CPF="$(readlink -f "${EIF}")" [ -f "${CPF}" ] && cp -v "${CPF}" "${FQP}/${APP}/${APP}-${PLAT}-${ARCH}/" CPF="${FQP}/injects/${APP}.png" [ -L "${CPF}" ] && CPF="$(readlink -f "${EIF}")" [ -f "${CPF}" ] && cp -v "${CPF}" "${FQP}/${APP}/${APP}-${PLAT}-${ARCH}/" ;; win32) CPF="${FQP}/injects/${APP}.png" [ -L "${CPF}" ] && CPF="$(readlink -f "${EIF}")" [ -f "${CPF}" ] && cp -v "${CPF}" "${FQP}/${APP}/${APP}-${PLAT}-${ARCH}/" ;; darwin|mas) CPF="${FQP}/injects/${APP}.icns" [ -L "${CPF}" ] && CPF="$(readlink -f "${EIF}")" [ -f "${CPF}" ] && cp -v "${CPF}" "${FQP}/${APP}/${APP}-${PLAT}-${ARCH}/" ;; esac done done echo "$(tput bold)$(tput setaf 2)==>$(tput sgr0) $(tput bold)FINISHED$(tput sgr0)"