116 lines
4.1 KiB
Plaintext
116 lines
4.1 KiB
Plaintext
|
#!/bin/bash
|
||
|
# assumes that bash is installed
|
||
|
#!/bin/bash
|
||
|
|
||
|
# use this to improve same below
|
||
|
# install_shell_base () {
|
||
|
# # TODO have a cross distro package install
|
||
|
# [[ ! $(which git) ]] && apt-get install --no-install-recommends git -y
|
||
|
# [[ ! $EUID -eq 0 ]] && { echo ERROR script must be run as root; return; }
|
||
|
# local user
|
||
|
# [[ $1 == "-u" ]] && user=$2 && shift 2
|
||
|
# local dir=${2:-/shell}
|
||
|
# local repo=${1:-base}
|
||
|
# local rpath=$dir/$repo
|
||
|
# mkdir -p $rpath
|
||
|
# # TODO set git host via option or env var
|
||
|
# git clone https://git.kebler.net/bash/shell-$repo.git $rpath
|
||
|
# chown -R ${user:-1000}:${user:-1000} $rpath
|
||
|
# chmod -R +r $rpath
|
||
|
# }
|
||
|
|
||
|
# must! be run as sudo
|
||
|
install_shell_base () {
|
||
|
if [[ $BASH_SHELL_BASE ]]; then
|
||
|
echo appears that UCI shell base is already installed at $BASH_SHELL_BASE
|
||
|
echo upgrade instead using: 'module_load uci-shell-install; update_shell_base'
|
||
|
return 1
|
||
|
fi
|
||
|
if [[ ! $BASH_SHELL_GIT_URL ]]; then
|
||
|
echo BASH_SHELL_GIT_URL must be set before install can proceed
|
||
|
return 1
|
||
|
fi
|
||
|
# TODO have a cross distro package install
|
||
|
module_load distro
|
||
|
set_distro
|
||
|
|
||
|
[[ ! $(command -v git) ]] && echo git must be installed first && $INSTALL_PKGS git
|
||
|
# TODO, avoid which in all scripts. or put which in environment if not on machine
|
||
|
[[ ! $(command -v which) ]] && echo 'which' must be installed first && $INSTALL_PKGS which
|
||
|
echo $USER, $EUID
|
||
|
[[ ! $EUID -eq 0 ]] && { echo ERROR script must be run as root; return 2; }
|
||
|
echo I am ROOT, now running script
|
||
|
echo UCI user: $1
|
||
|
# TODO make the repo and clone values dynamic or bundle current base on sending machine a archive
|
||
|
mkdir -p /shell/base
|
||
|
git clone $BASH_SHELL_GIT_URL/shell-base.git /shell/base
|
||
|
chown -R ${1:-$1000}:${1:-1000} /shell
|
||
|
chmod -R +r /shell
|
||
|
|
||
|
echo /bin/bash /shell/base/install/install.sh ${1:-1000}
|
||
|
}
|
||
|
|
||
|
# # if script was executed then call the function
|
||
|
( return 0 2>/dev/null ) || install_shell_base $@
|
||
|
|
||
|
|
||
|
install_shell_host () {
|
||
|
if [[ $BASH_SHELL_HOST ]]; then
|
||
|
echo appears that UCI shell host repo is already installed at $BASH_SHELL_HOST
|
||
|
echo upgrade instead using: 'module_load uci-shell-install; update_shell_host'
|
||
|
return 1
|
||
|
fi
|
||
|
if [[ ! $BASH_SHELL_GIT_URL ]]; then
|
||
|
echo BASH_SHELL_GIT_URL must be set before install can proceed
|
||
|
return 1
|
||
|
fi
|
||
|
export BASH_SHELL_HOST=$(dirname $BASH_SHELL_BASE)/host
|
||
|
if mkdir -p $BASH_SHELL_HOST; then
|
||
|
if git clone $UCI_GIT_SERVER_URL/shell-host.git $BASH_SHELL_HOST; then
|
||
|
chown -R ${1:-$USER}:${1:-$USER} $BASH_SHELL_HOST
|
||
|
chmod -R +r $BASH_SHELL_HOST
|
||
|
export $BASH_SHELL_HOSTNAME=$(dirname $BASH_SHELL_BASE)/$(hostnamectl hostname)
|
||
|
mkdir -p $BASH_SHELL_HOSTNAME/load
|
||
|
echo note: use $BASH_SHELL_HOSTNAME/load directory to load modules and other stuff from at prompt.
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
install_shell_network () {
|
||
|
if [[ $BASH_SHELL_NETWORK ]]; then
|
||
|
echo appears that UCI shell network repo is already installed at $BASH_SHELL_NETWORK
|
||
|
echo upgrade instead using: 'module_load uci-shell-install; update_shell_network'
|
||
|
return 1
|
||
|
fi
|
||
|
if [[ ! $BASH_SHELL_GIT_URL ]]; then
|
||
|
echo BASH_SHELL_GIT_URL must be set before install can proceed
|
||
|
return 1
|
||
|
fi
|
||
|
export BASH_SHELL_NETWORK=$(dirname $BASH_SHELL_BASE)/network
|
||
|
if mkdir -p $BASH_SHELL_NETWORK; then
|
||
|
if git clone $UCI_GIT_SERVER_URL/shell-network.git $BASH_SHELL_NETWORK; then
|
||
|
chown -R ${1:-$USER}:${1:-$USER} $BASH_SHELL_NETWORK
|
||
|
chmod -R +r $BASH_SHELL_NETWORK
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
update_shell_base () {
|
||
|
cd $BASH_SHELL_BASE || { echo not directory $BASH_SHELL_ANY_HOST; return 2; }
|
||
|
if [[ ! $BASH_SHELL_GIT_REMOTE ]]; then
|
||
|
echo WARNING: BASH_SHELL_GIT_REMOTE is not set will use \'origin\'
|
||
|
return 1
|
||
|
fi
|
||
|
git pull ${UCI_GIT_REMOTE:-origin} master
|
||
|
}
|
||
|
|
||
|
update_shell_host () {
|
||
|
cd $BASH_SHELL_NETWORK || { echo not directory $BASH_SHELL_NETWORK; return 2; }
|
||
|
git pull ${UCI_GIT_REMOTE:-origin} master
|
||
|
}
|
||
|
|
||
|
update_shell_network () {
|
||
|
cd $BASH_SHELL_NETWORK || { echo not directory $BASH_SHELL_NETWORK; return 2; }
|
||
|
git pull ${UCI_GIT_REMOTE:-origin} master
|
||
|
}
|