@ -1,13 +1,27 @@
#!/bin/bash
# Make a 'native app' wrapper using nativefier for a site.
u sag e() { echo "Usage: $0 -u -s h ttps://example.com -n Nativ eExample"; exit 1; }
set -e
while getopts "us:n:" option; do
echo "mknative"
echo "========"
usage() {
echo "Basic Usage: $ mknative [-u] -n NativeExample -s https://example.com "
echo "---------------------------------------------------------------------------"
echo " -n NativeExample installed application name (basically an id)"
echo " -s https://example.com website address "
echo " -u [optional] uninstall application (destructive) "
echo " -i example.com [optional] domain name to fetch favicon from. "
echo " -e '--extra-args' [optional] pass some extra args to nativefier build. "
exit 1
}
while getopts "us:n:i:e:" option; do
case ${option} in
u)
uninstall=1
echo "Uninstalling ..."
;;
s)
url=${OPTARG}
@ -17,6 +31,14 @@ while getopts "us:n:" option; do
name=${OPTARG}
echo "Name: $name"
;;
i)
icon_domain=${OPTARG}
echo "Icon Domain: $icon_domain"
;;
e)
extra=${OPTARG}
echo "Extra args: $extra"
;;
*)
usage
;;
@ -24,6 +46,8 @@ while getopts "us:n:" option; do
done
if [ -n "${uninstall}" ]; then
echo "Uninstalling ..."
if [ -z "${name}" ]; then
usage
fi
@ -38,12 +62,31 @@ if [ -z "${name}" ] || [ -z "${url}" ]; then
usage
fi
if [ -n "${icon_domain}" ]; then
echo "Fetching potential icons using favicongrabber.com API (retry if fails, flaky API )..."
urls_resp=$(curl --silent "https://favicongrabber.com/api/grab/${icon_domain}" | jq ".icons | .[] | .src ")
urls=( $( echo "$urls_resp" | tr -d '"' | tr ',' '\n' ) )
echo "Here's the icons I found, which would you like?"
for i in "${!urls[@]}"; do
echo " $i) ${urls[$i]}";
done
read -n 1 -p "Selection: " url_choice
echo " "
echo "getting ${urls[$url_choice]}"
wget -nv -O $HOME/.local/share/mknative/icons/${name}.png -e robots=off ${urls[$url_choice]}
fi
docker run --privileged -ti \
-v $HOME/.local/bin/nativefier:/target/ \
-v $HOME/.local/share/mknative/icons:/src \
jiahaog/nativefier:latest \
--name $name \
--icon /src/$name.png \
${extra} \
-p linux \
-a x64 \
$url \