shell-host/apps/chromium/chromium.func

75 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# improve and refactor
chromium_() {
module_load path
local path=/opt/chromium
local user_data_path=$HOME/.browsers
local snap_path=$HOME/snap/chromium/common
# set default exe here (no flag)
local exe="/usr/bin/chromium"
local snap
if [[ $1 == "-version" ]]; then
$exe -version
return
fi
[[ $1 == -d ]] && exe=/usr/bin/chromium && shift
[[ $1 == -g ]] && exe=$(command -v google-chrome) && shift
[[ $1 == -s ]] && snap=true && exe=/snap/bin/chromium && shift
[[ $1 == -u ]] && exe=/opt/bin/ungoogled-chromium && shift
[[ $1 == -v ]] && exe=/opt/vivaldi/vivaldi && shift
[[ $1 == -c ]] && exe=/usr/bin/chromium && shift
echo execuatble to be used: $exe
if [[ ! -f $exe ]]; then
echo chromium/chrome not installed at $exe
return 2
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
[[ ! $instance ]] && instance=chromium && unset CHROME_CONFIG_HOME
[[ $instance == "incognito" ]] && set -- "$@" "-incognito"
local dir
dir=$(isAbsPath $instance)
if [[ ! $dir ]]; then
dir=${user_data_path}/$instance
if [[ ! -d "$dir" ]]; then
dir="${CHROMIUM_HOME:-$path}/$instance"
[[ ! -d "$dir" ]] && [[ -d ${user_data_path} ]] && dir=${user_data_path}/$instance
fi
fi
if [[ $snap ]]; then
local bfs=$(command -v bindfs)
[[ ! $bfs ]] && echo bindfs not installed - exiting && return 3
sdir=${snap_path}/$instance
mkdir -p $sdir
fusermount -u $sdir
$bfs $dir $sdir
dir=$sdir
fi
mkdir -p $dir
echo $exe $@ --user-data-dir=$dir $url
$exe $@ --user-data-dir=$dir $url
}
# # if script was executed then call the function
(return 0 2>/dev/null) || chromium_ $@