shell-base/setup/deploy-user.sh

43 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
_USER=${1:-$USER}
[[ ! $(id -u $_USER) -ge 1000 ]] && echo "no user $_USER or user not a regular" && exit 1
echo user: $_USER deployment
[[ ! $BASH_SHELL_BASE ]] && BASH_SHELL_BASE="$(dirname "$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")"
echo Base Shell Directory as detected is $BASH_SHELL_BASE
echo ok to continue?
echo "type \`yes\` fully or just <enter> to exit"
read -e answer
[[ ! $answer = "yes" ]] && exit 1
UBDIR=$BASH_SHELL_BASE/setup/backup-users/$_USER
_USER_DIR=$(getent passwd "$USER" | cut -d : -f 6)
files=".bash_profile .profile .bashrc .bash_logout"
# uncomment for debugging
# rm -rf $UBDIR
if [[ ! -d $UBDIR ]]; then
echo "first backing up $_USER_DIR shell files before deploying"
mkdir -p $UBDIR
for file in $files ; do
[[ -f $_USER_DIR/$file ]] && sudo install -C -m 660 -o root -g sudo $_USER_DIR/$file $UBDIR
done
fi
echo "ready to deploy $_USER shell files"
echo "Double check files in $UBDIR"
echo "continue? type \`yes\` fully or just <enter> for no"
read -e answer
[[ ! $answer = "yes" ]] && echo aborting deploy && exit 1
echo -----------------;echo deploying user shell files to /home/$_USER
echo
files=$(find $BASH_SHELL_BASE/setup/user/ -type f)
for file in $files; do
cmd="install -C -m 660 -o $_USER -g sudo $file $_USER_DIR"
[[ $USER = "$_USER" ]] && eval $cmd || sudo -E -- bash -c "$cmd"
done
echo "the default user bash shell repo subdirecty is \`bash/shell\`"
echo "enter an alternative subdirectory under $_USER_DIR or just <enter> to accept default"
read -e answer
[[ ! $answer ]] && echo will source default user shell repo at $_USER_DIR/bash/shell && exit 0
sed -i '/[[ $BASH_SHELL_BASE_LOADED = true ]]/ i\ BASH_SHELL_USER='$answer'' $_USER_DIR/.bashrc
echo will be processing user shell repo at $_USER_DIR/$answer