shell-host/modules/chromium/chromium.sh

64 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# user to start MUST be first in arguments
# if not supplied then will use default
chromium_() {
local DEFAULT=/opt/chromium
local DEFAULT_USER=$HOME/.browsers
# local DEFAULT="$HOME/.local/share/chromium"
local exe="/usr/bin/chromium"
if [[ $1 == "-version" ]]; then
$exe -version
return
fi
[[ $1 == -g ]] && exe=$(command -v google-chrome) && shift
echo execuatble to be used: $exe
if [[ ! -f $exe ]]; then
echo chromium/chrome not installed, checking for flatpak version
flatpak=$(flatpak info com.github.Eloston.UngoogledChromium | grep error:)
if [[ $flatpak ]]; then
echo no flatpak version either - exiting
return 1
else
flatpak=true
exe="/usr/bin/flatpak run --branch=stable --arch=x86_64 --filesystem=<dir> --command=/app/bin/chromium --file-forwarding com.github.Eloston.UngoogledChromium @@u"
fi
fi
local instance=${CHROMIUM_INSTANCE}
[[ $1 && (! $1 == -*) ]] && instance=$1 && shift
[[ $1 && (! $1 == -*) ]] && url=$1 && shift
if [[ $instance =~ http[s]?:\/\/ ]]; then
url=$instance
instance=""
if [[ $url =~ ^-+ ]]; then
url=""
set -- "$@" $url
url=""
fi
fi
local dir
if [[ ! $instance ]]; then
unset CHROME_CONFIG_HOME
$HOME/.config/chromium
echo starting chromium for $USER in
dir=$HOME/.config/chromium
exe="${exe/<dir>/$dir}"
else
[[ $instance == "incognito" ]] && set -- "$@" "-incognito"
dir=${DEFAULT_USER}/$instance
dir=$([[ -d "$dir" ]] && echo $dir || echo "${CHROMIUM_HOME:-$DEFAULT}/$instance")
exe="${exe/<dir>/$dir}"
fi
mkdir -p $dir
echo $exe $@ --user-data-dir=$dir $url $([[ $flatpak ]] && echo "@@")
$exe $@ --user-data-dir=$dir $url $([[ $flatpak ]] && echo "@@")
}
# # if script was executed then call the function
(return 0 2>/dev/null) || chromium_ $@