diff --git a/.bash-shell-include b/.bash-shell-include deleted file mode 100644 index 4389836..0000000 --- a/.bash-shell-include +++ /dev/null @@ -1 +0,0 @@ -load diff --git a/install/apps/chromium/chromium.func b/apps/chromium/chromium.func similarity index 100% rename from install/apps/chromium/chromium.func rename to apps/chromium/chromium.func diff --git a/install/apps/chromium/chromium.inst b/apps/chromium/chromium.inst similarity index 100% rename from install/apps/chromium/chromium.inst rename to apps/chromium/chromium.inst diff --git a/install/apps/vscode/vscode.func b/apps/vscode/vscode.func similarity index 100% rename from install/apps/vscode/vscode.func rename to apps/vscode/vscode.func diff --git a/install/apps/vscode/vscode.inst b/apps/vscode/vscode.inst similarity index 100% rename from install/apps/vscode/vscode.inst rename to apps/vscode/vscode.inst diff --git a/distro/alpine b/distro/alpine new file mode 100644 index 0000000..e69de29 diff --git a/distro/arch/pacman b/distro/arch/pacman new file mode 100644 index 0000000..d574470 --- /dev/null +++ b/distro/arch/pacman @@ -0,0 +1,10 @@ +# echo https://wiki.archlinux.org/title/Pacman +alias pm="sudo pacman" +alias pmi="sudo pacman -S" +alias pmi="sudo pacman -Ssq" +alias pmr="sudo pacman -Rs package_name" +alias pmua="sudo pacman -Syu" +alias pmi="sudo pacman -Q" +alias pkgst="sudo pacman -Qi" +alias pkgi="sudo pacman -Si" +# alias pms="sudo pacman -Ss '^vim-'" diff --git a/install/distro/debian/apt b/distro/debian/apt similarity index 100% rename from install/distro/debian/apt rename to distro/debian/apt diff --git a/distro/distro.inst b/distro/distro.inst new file mode 100644 index 0000000..3f940a3 --- /dev/null +++ b/distro/distro.inst @@ -0,0 +1,2 @@ +module_load host-utils +ln -s $BASH_SHELL_ANY_HOST/distro/$(get_distro) $BASH_SHELL_HOST/load diff --git a/modules/add-ppa.sh b/distro/ubuntu/add-ppa.sh similarity index 100% rename from modules/add-ppa.sh rename to distro/ubuntu/add-ppa.sh diff --git a/install/distro/debian/ubuntu/multipass/multipass.alias b/distro/ubuntu/multipass/multipass.alias similarity index 100% rename from install/distro/debian/ubuntu/multipass/multipass.alias rename to distro/ubuntu/multipass/multipass.alias diff --git a/install/distro/debian/ubuntu/multipass/multipass.func b/distro/ubuntu/multipass/multipass.func similarity index 100% rename from install/distro/debian/ubuntu/multipass/multipass.func rename to distro/ubuntu/multipass/multipass.func diff --git a/install/distro/debian/ubuntu/snap/snap.alias b/distro/ubuntu/snap/snap.alias similarity index 100% rename from install/distro/debian/ubuntu/snap/snap.alias rename to distro/ubuntu/snap/snap.alias diff --git a/install/distro/debian/ubuntu/snap/snap.func b/distro/ubuntu/snap/snap.func similarity index 100% rename from install/distro/debian/ubuntu/snap/snap.func rename to distro/ubuntu/snap/snap.func diff --git a/install/distro/debian/ubuntu/snap/snap.path b/distro/ubuntu/snap/snap.path similarity index 100% rename from install/distro/debian/ubuntu/snap/snap.path rename to distro/ubuntu/snap/snap.path diff --git a/install/docker/00-docker.env b/docker/00-docker.env similarity index 100% rename from install/docker/00-docker.env rename to docker/00-docker.env diff --git a/install/docker/01-docker.alias b/docker/01-docker.alias similarity index 100% rename from install/docker/01-docker.alias rename to docker/01-docker.alias diff --git a/install/docker/02-docker.lib b/docker/02-docker.lib similarity index 100% rename from install/docker/02-docker.lib rename to docker/02-docker.lib diff --git a/install/docker/docker-compose.func b/docker/docker-compose.func similarity index 100% rename from install/docker/docker-compose.func rename to docker/docker-compose.func diff --git a/install/distro/debian/ubuntu/remina b/install/distro/debian/ubuntu/remina deleted file mode 100644 index 4c0b53f..0000000 --- a/install/distro/debian/ubuntu/remina +++ /dev/null @@ -1,3 +0,0 @@ -# https://remmina.org/how-to-install-remmina/#ubuntu -module_load add-ppa -add_ppa -i -c remmina -p \"remmina remmina-plugin-rdp remmina-plugin-secret\" ppa:remmina-ppa-team/remmina-next diff --git a/modules/bindfs.lib b/modules/bindfs.lib new file mode 100644 index 0000000..885d786 --- /dev/null +++ b/modules/bindfs.lib @@ -0,0 +1,99 @@ +#!/bin/bash + +#bmount () {} +# sudo bindfs -o allow_other -o map=root/1001:@root/@1001 /var/lib/docker/volumes /data/dvols + + +if [ -v PS1 ]; then + alias drbu="dir_rebind_user" + alias dbu="dir_bind_user" + alias dbum="dir_bind_unmount" +fi + +dir_rebind_user () { + local usesudo; local dir;local user;local group + # $1 new owner + # $2 dir + +[ $# -lt 2 ] && echo minimum args needed to rebind are user and directory && return 1 +[[ $EUID -ne 0 ]] && usesudo=sudo + +[[ $(id -u $1 2> /dev/null) ]] || { echo user $1 does not exist can not continue; return 2; } + +dir=$(realpath $2) +user=$(stat -c '%U' $dir) +group=$(stat -c '%G' $dir) +$usesudo bindfs --force-user=$1 --force-group=$1 --create-for-user=$user --create-for-group=$group --chown-ignore --chgrp-ignore $dir $dir +# echo use \'dir_rebind_user_remove $dir\' to remove +} + +dir_bind_unmount () { + local usersudo + [[ $EUID -ne 0 ]] && usesudo=sudo + $usesudo fusermount -u $1 +} + + +dir_bind_user () { + local usesudo; local dir;local user;local group;local mp + +[ $# -lt 3 ] && echo minimum 3 args needed to rebind are user, source directory and mountpoint && return 1 +[[ $EUID -ne 0 ]] && usesudo=sudo + +[[ $(id -u $1 2> /dev/null) ]] || { echo user $1 does not exist can not continue; return 2; } + +dir=$(realpath $2) +mp=$3 +if ! $usesudo mkdir -p $mp; then echo unable to make mountpoint aborting; return 2; fi +$usesudo chown $1:$1 $mp +user=$(stat -c '%U' $dir) +group=$(stat -c '%G' $dir) +$usesudo bindfs --force-user=$1 --force-group=$1 --create-for-user=$user --create-for-group=$group --chown-ignore --chgrp-ignore $dir $mp +# echo use \'dir_rebind_user_remove $dir\' to remove +} + +# module_load bindfs && dir_bind_user david /mnt/datadrive/@images /data/images + + +(return 0 2>/dev/null) || dir_bind_user $@ + + +# 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 +# } + +# must have fuser and bindfs installed +# 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 +# } + diff --git a/modules/copyrootfs.func b/modules/copyrootfs.func new file mode 100644 index 0000000..8e2ee45 --- /dev/null +++ b/modules/copyrootfs.func @@ -0,0 +1,36 @@ +#!/bin/bash +module_load filesystem +module_load confirm + +copy_rootfs () { +local dr="" +# local de=--delete-excluded +[[ ! $(mounted $1) ]] && echo $1 is not a mountpoint exiting && return 2 +cmd=$(echo sudo rsync $dr $de --progress -aAXv --exclude={\ +"/dev/*",\ +"/proc/*",\ +"/sys/*",\ +"tmp/*",\ +"/run/*",\ +"/mnt/*",\ +"/media/*",\ +"/lost+found",\ +"/data/*",\ +"/backup/*",\ +"/snapshots/*",\ +"/remotes/*",\ +"*[Cc]ache*",\ +"*/[Ll]og/*",\ +"*/[Ll]ogs/*",\ +"*.[Ll]og",\ +"/etc/fstab*",\ +"/boot/refind_linux.conf"\ +}\ + / $1 + ) +echo $cmd +if confirm run this copy command; then +$cmd +fi + +} \ No newline at end of file diff --git a/modules/host-utils.mod b/modules/host-utils.mod index 15f60ca..3a01479 100644 --- a/modules/host-utils.mod +++ b/modules/host-utils.mod @@ -1,66 +1,75 @@ #!/bin/bash -function get_platform() { +arch () { + uname -m +} + +function get_chip_type() { - local OS local ARCH - local PLATFORM - OS="$(uname -s)" - ARCH="$(uname -m)" - - case $OS in - "Linux") - case $ARCH in + case $(arch) in "x86_64") ARCH=amd64 ;; "aarch64") ARCH=arm64 ;; - "armv6") - ARCH=armv6l - ;; "armv8") ARCH=arm64 ;; .*386.*) - ARCH=386 + ARCH=amd32 ;; + *) + ARCH=arm32 + ;; esac - PLATFORM="linux-$ARCH" - ;; - "Darwin") - PLATFORM="darwin-amd64" - ;; - esac - - echo $PLATFORM + echo $ARCH } -# function get_distro() { -# /bin/cp /etc/os-release /tmp/os-release.tmp -# source /etc/os-release -# declare valid=${@:-"arch alpine debian ubuntu"} -# [[ "${valid}" =~ $ID ]] && echo $ID && return 0 -# [[ "${valid}" =~ $ID_LIKE ]] && echo $ID_LIKE && return 0 -# return 1 +function get_platform() { + + echo $(uname -s)-$(get_chip_type) + +} + +hostinfo () { + hostnamectl + echo -e "--------------------------" + echo kernel: $(uname -r) + echo chip architecture: $(uname -m) + echo -e "--------------------------" + cat /etc/os-release + echo -e "--------------------------" + [[ -f /etc/upstream-release/lsb-release ]] && cat /etc/upstream-release/lsb-release +} + + +function get_distro() { +source /etc/os-release +declare valid=${@:-"arch alpine debian ubuntu"} +# echo $ID $ID_LIKE +[[ "${valid}" =~ $ID ]] && echo $ID && return 0 +[[ "${valid}" =~ $ID_LIKE ]] && echo $ID_LIKE && return 0 +return 1 +} + +# function get_release() { + # } -function get_release() { - -} - -get_distro() { - local file=/etc/upstream-release/lsb-release - local distro - if [[ -f $file ]]; then - $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq) - return 0 - else - $file=/etc/os-release - if [[ -f $file ]]; then - echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq) - fi -} +# get_distro() { +# local file=/etc/upstream-release/lsb-release +# local distro +# if [[ -f $file ]]; then +# echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq) +# return 0 +# else +# file=/etc/os-release +# if [[ -f $file ]]; then +# echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq) +# fi +# fi +# } diff --git a/sudoers/20-dir b/sudoers/20-dir new file mode 100644 index 0000000..4cae930 --- /dev/null +++ b/sudoers/20-dir @@ -0,0 +1 @@ +%sudo, %wheel ALL=(ALL) NOPASSWD:/bin/mkdir, /bin/chown diff --git a/sudoers/21-bindfs b/sudoers/21-bindfs new file mode 100644 index 0000000..d29d53d --- /dev/null +++ b/sudoers/21-bindfs @@ -0,0 +1 @@ +%sudo, %wheel ALL=(ALL) NOPASSWD:/bin/bindfs, /bin/fusermount diff --git a/sudoers/22-btrfs b/sudoers/22-btrfs new file mode 100644 index 0000000..0122047 --- /dev/null +++ b/sudoers/22-btrfs @@ -0,0 +1 @@ +%sudo, %wheel ALL=(ALL) NOPASSWD:/bin/btrfs, /bin/btrbk