refactor of repo to mainly install into host shell directory from here. so folders are various code that can be installed to particular host

master
David Kebler 2023-02-23 10:23:19 -08:00
parent 4ad0c913b0
commit dd25a68355
26 changed files with 203 additions and 48 deletions

View File

@ -1 +0,0 @@
load

0
distro/alpine Normal file
View File

10
distro/arch/pacman Normal file
View File

@ -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-'"

2
distro/distro.inst Normal file
View File

@ -0,0 +1,2 @@
module_load host-utils
ln -s $BASH_SHELL_ANY_HOST/distro/$(get_distro) $BASH_SHELL_HOST/load

View File

@ -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

99
modules/bindfs.lib Normal file
View File

@ -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
# }

36
modules/copyrootfs.func Normal file
View File

@ -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
}

View File

@ -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_platform() {
echo $(uname -s)-$(get_chip_type)
}
# 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
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
# }

1
sudoers/20-dir Normal file
View File

@ -0,0 +1 @@
%sudo, %wheel ALL=(ALL) NOPASSWD:/bin/mkdir, /bin/chown

1
sudoers/21-bindfs Normal file
View File

@ -0,0 +1 @@
%sudo, %wheel ALL=(ALL) NOPASSWD:/bin/bindfs, /bin/fusermount

1
sudoers/22-btrfs Normal file
View File

@ -0,0 +1 @@
%sudo, %wheel ALL=(ALL) NOPASSWD:/bin/btrfs, /bin/btrbk