From 35a6904cf4670f20dc061c36af2272c04f235a24 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Fri, 5 Feb 2021 12:21:17 -0800 Subject: [PATCH] moved bind-mount vscode and chromium to modules. Made .inst files for them with sensible defaults that can be overridden by env vars. --- all/archive/chromium.inst | 26 ++++++++++ .../chromium.sh.archive} | 0 all/archive/vscode.inst | 6 +++ all/modules/bind-mount/bind-mount.inst | 7 +++ all/modules/bind-mount/bind-mount.sh | 52 +++++++++++++------ all/modules/chromium/chromium.inst | 9 ++++ all/modules/chromium/chromium.sh | 35 +++++++++++++ all/modules/vscode.sh | 21 ++++---- giskard/archive/chromium | 2 + 9 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 all/archive/chromium.inst rename all/{modules/chromium.sh => archive/chromium.sh.archive} (100%) create mode 100644 all/archive/vscode.inst create mode 100755 all/modules/bind-mount/bind-mount.inst create mode 100755 all/modules/chromium/chromium.inst create mode 100755 all/modules/chromium/chromium.sh create mode 100755 giskard/archive/chromium diff --git a/all/archive/chromium.inst b/all/archive/chromium.inst new file mode 100644 index 0000000..35e3efe --- /dev/null +++ b/all/archive/chromium.inst @@ -0,0 +1,26 @@ +#!/bin/bash +module_load notify +_ch=$(command -v _chromium) +if [[ $_ch ]]; then + ch=$(dirname "$_ch")/chromium + ## if chromium exits probably an update to so move again + msg="new version availabe, run: sudo mv $ch $_ch" + [[ -f $ch ]] && llog $msg && notify-send $msg + export CHROME_CONFIG_HOME="/opt/chromium" + # chmod +x $BASH_SHELL_HOST/all/modules/chromium.sh + ln -sf $BASH_SHELL_HOST/all/modules/chromium.sh /opt/bin/chromium + llog "chromium sucessfully set up on $HOSTNAME" + login_notify "chromium sucessfully set up on $HOSTNAME" + else +# echo no _chromium + ch=$(command -v chromium) + if [[ $ch ]];then + llog "chromium availabe, need to run this command and log in again" + login_notify "chromium availabe but need to run this command and log in again" + llog "sudo mv $ch $(dirname $ch)/_chromium" + login_notify "sudo mv $ch $(dirname $ch)/_chromium" + else + llog "Warning: ungoogled chromimum not installed on $HOSTNAME" + login_notify "Warning: ungoogled chromimum not installed on $HOSTNAME" + fi +fi \ No newline at end of file diff --git a/all/modules/chromium.sh b/all/archive/chromium.sh.archive similarity index 100% rename from all/modules/chromium.sh rename to all/archive/chromium.sh.archive diff --git a/all/archive/vscode.inst b/all/archive/vscode.inst new file mode 100644 index 0000000..06cc58b --- /dev/null +++ b/all/archive/vscode.inst @@ -0,0 +1,6 @@ +#!/bin/bash +if [[ $(command -v code) ]]; then +export VSCODE_HOME="/opt/vscode" +chmod +x $BASH_SHELL_HOST/all/modules/vscode.sh +ln -sf $BASH_SHELL_HOST/all/modules/vscode.sh /opt/bin/vscode +fi \ No newline at end of file diff --git a/all/modules/bind-mount/bind-mount.inst b/all/modules/bind-mount/bind-mount.inst new file mode 100755 index 0000000..09ea24a --- /dev/null +++ b/all/modules/bind-mount/bind-mount.inst @@ -0,0 +1,7 @@ +DIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +BIN=${1:-/opt/bin/bmount} +ln -s $DIR/bind-mount.sh $BIN +sudo chown root:sudo $DIR/bind-mount.sh +sudo chmod 771 $DIR/bind-mount.sh +echo "%users $HOSTNAME=(ALL) NOPASSWD:SETENV: /bin/bash $BIN" | sudo tee /etc/sudoers.d/bmount +sudo chmod 440 /etc/sudoers.d/bmount diff --git a/all/modules/bind-mount/bind-mount.sh b/all/modules/bind-mount/bind-mount.sh index ad163fe..6bd0bdb 100755 --- a/all/modules/bind-mount/bind-mount.sh +++ b/all/modules/bind-mount/bind-mount.sh @@ -1,24 +1,42 @@ #!/bin/bash # must have fuser and bindfs installed -function bmount () { - if [ "$1" == "-mp" ]; then - MOUNTED=$(mountpoint "$2" | grep not) - if [ -z "$MOUNTED" ]; then - echo $2 is a mount point so bind mounting $2/$3 to $4 - notify-send "bind mounting ${2}/${3} to ${4}" --icon=dialog-information -t 2000 - bindfs "$2/$3" "$4" - else - notify-send "${2} not a mount point - Unable to bind mount ${2}/${3} to ${4}" --icon=dialog-error -t 2000 - fi - else - echo bind mounting $1 to $2 - notify-send "bind mounting ${1} to ${2}" --icon=dialog-information -t 2000 - bindfs "$1" "$2" - fi -} +# for use by sudoers +# ln -s $BASH_SHELL_HOST/all/modules/bind-mount/bind-mount.sh /opt/bin/bmount +# function xxbmount () { +# if [ "$1" == "-mp" ]; then +# MOUNTED=$(mountpoint "$2" | grep not) +# if [ -z "$MOUNTED" ]; then +# echo $2 is a mount point so bind mounting $2/$3 to $4 +# notify-send "bind mounting ${2}/${3} to ${4}" --icon=dialog-information -t 2000 +# bindfs "$2/$3" "$4" +# else +# notify-send "${2} not a mount point - Unable to bind mount ${2}/${3} to ${4}" --icon=dialog-error -t 2000 +# fi +# else +# echo bind mounting $1 to $2 +# notify-send "bind mounting ${1} to ${2}" --icon=dialog-information -t 2000 +# bindfs "$1" "$2" +# fi +# } -bumount () { +function bumount { echo "removing bind mount at $1" notify-send "removing bind mount at ${1}" --icon=dialog-information -t 2000 fusermount -u "$1" } + +function bmount { + if [ "$1" == "-d" ]; then + bumount $2 + else + # if [[ " ${array[@]} " =~ " ${value} " ]]; then + # # whatever you want to do when array contains value + # fi + # mp="${@: -2}" + echo mounting $@ + bindfs $@ + fi +} + +# if script was executed then call the function +(return 0 2>/dev/null) || bmount $@ \ No newline at end of file diff --git a/all/modules/chromium/chromium.inst b/all/modules/chromium/chromium.inst new file mode 100755 index 0000000..8c9f626 --- /dev/null +++ b/all/modules/chromium/chromium.inst @@ -0,0 +1,9 @@ +#!/bin/bash +source $BASH_SHELL_BASE/module.lib +module_load helpers +NAME=${1:-$(filename $0)} +DIR=$(adirname "$0") +BIN=${1:-/opt/bin/$NAME} +chown :users $DIR/$NAME.sh +chmod 755 $DIR/$NAME.sh +ln -sf $DIR/$NAME.sh $BIN diff --git a/all/modules/chromium/chromium.sh b/all/modules/chromium/chromium.sh new file mode 100755 index 0000000..6f56778 --- /dev/null +++ b/all/modules/chromium/chromium.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# user to start MUST be first in arguments +# if not supplied then will use default +chromium_ () { +local DEFAULT=/opt/chromium +# local DEFAULT="$HOME/.local/share/chromium" +local exe="/usr/bin/chromium" +[[ ! $exe ]] && echo chromium not installed set && return 1 +user=${CHROMIUM_USER} +[[ $1 && ( ! $1 == -* ) ]] && user=$1 && shift +user=${user:-$USER} +if [[ $user == "$USER" ]]; then + unset CHROME_CONFIG_HOME + echo starting chromium for $USER in default directory within users home + echo $exe "$@" + $exe "$@" + else + [[ $user == "incognito" ]] && set -- "$@" "-incognito" + dir=${CHROMIUM_HOME:-$DEFAULT} + echo "$exe $@ --user-data-dir=$dir/$user" + "$exe" "$@" --user-data-dir="$dir"/"$user" + fi +} + +# # if script was executed then call the function +(return 0 2>/dev/null) || chromium_ $@ + + + + + + + + diff --git a/all/modules/vscode.sh b/all/modules/vscode.sh index 47ea61d..c5095b9 100755 --- a/all/modules/vscode.sh +++ b/all/modules/vscode.sh @@ -2,23 +2,20 @@ command -v code >/dev/null 2>&1 || exit +# set default home here +# can pass vscode () { - -home=${VSCODE_HOME:-$1} -home=${home:-$HOME} -echo $home +#local home=$HOME +local home=/opt/vscode +home=${VSCODE_HOME:-$home} +[[ $1 == "-h" ]] && home=$2 && shift 2 +mkdir -p $home +[[ $? -ne 0 ]] && echo "unable to set vscode home at $home, aborting" && return 1 exts=${home}/extensions user=${home}/user exe=$(command -v code) -$exe --user-data-dir=$user --extensions-dir=$exts - +$exe --user-data-dir=$user --extensions-dir=$exts "$@" } # # if script was executed then call the function (return 0 2>/dev/null) || vscode $@ - - - - - - diff --git a/giskard/archive/chromium b/giskard/archive/chromium new file mode 100755 index 0000000..a7869f0 --- /dev/null +++ b/giskard/archive/chromium @@ -0,0 +1,2 @@ +echo setting up bindmounts for chromium +echo sudo -s "/bin/bash /opt/bin/bmount -u $USER -g users /mnt/common/home /mnt/AllData/tempbind" \ No newline at end of file