added backup script, improved deploy script and seperated deplooy for user to deploy-user script. Will set BASH_SHELL_BASE in /etc/profile based on where deploy script is launched.
parent
527636a48e
commit
01b8894dd2
|
@ -0,0 +1,2 @@
|
||||||
|
/backup-users/
|
||||||
|
/backup/
|
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/bash
|
||||||
|
[[ ! $(groups | grep sudo) ]] && echo this script must be run by a user with sudo privileges && exit 1
|
||||||
|
[[ ! $BASH_SHELL_BASE ]] && echo "set BASH_SHELL_BASE before running this script" && exit 2 || echo backing up shell files...
|
||||||
|
set -o errexit
|
||||||
|
mkdir -p $BASH_SHELL_BASE/setup/backup/etc/profile.d
|
||||||
|
mkdir -p $BASH_SHELL_BASE/setup/backup/user
|
||||||
|
mkdir -p $BASH_SHELL_BASE/setup/backup/root
|
||||||
|
# host system files in /etc
|
||||||
|
[[ -f /etc/profile ]] && cp -v /etc/profile $BASH_SHELL_BASE/setup/backup/etc
|
||||||
|
[[ -f /etc/bash.bashrc ]] && cp -v /etc/bash.bashrc $BASH_SHELL_BASE/setup/backup/etc
|
||||||
|
[[ -d /etc/profile.d ]] && cp -vR /etc/profile.d/ $BASH_SHELL_BASE/setup/backup/etc/
|
||||||
|
# current user files in $HOME
|
||||||
|
[[ -f $HOME/.bash_profile ]] && cp -v $HOME/.bash_profile $BASH_SHELL_BASE/setup/backup/user
|
||||||
|
[[ -f $HOME/.profile ]] && cp -v $HOME/.profile $BASH_SHELL_BASE/setup/backup/user
|
||||||
|
[[ -f $HOME/.bashrc ]] && cp -v $HOME/.bashrc $BASH_SHELL_BASE/setup/backup/user
|
||||||
|
[[ -f $HOME/.bash_logout ]] && cp -v $HOME/.bash_logout $BASH_SHELL_BASE/setup/backup/user
|
||||||
|
if [[ $(stat -c "%G" /root) = "sudo" ]]; then
|
||||||
|
[[ -f /root/.bash_profile ]] && cp -v /root/.bash_profile $BASH_SHELL_BASE/setup/backup/root
|
||||||
|
[[ -f /root/.profile ]] && cp -v /root/.profile $BASH_SHELL_BASE/setup/backup/root
|
||||||
|
[[ -f /root/.bashrc ]] && cp -v /root/.bashrc $BASH_SHELL_BASE/setup/backup/root
|
||||||
|
[[ -f /root/.bash_logout ]] && cp -v /root/.bash_logout $BASH_SHELL_BASE/setup/backup/root
|
||||||
|
else
|
||||||
|
echo no sudo group read access to /root so backing up /root as root
|
||||||
|
sudo -E -- bash -c '[[ ! -f /root/.profile ]] && exit 0; cp -v /root/.profile $BASH_SHELL_BASE/setup/backup/root'
|
||||||
|
sudo -E -- bash -c '[[ ! -f /root/.bashrc ]] && exit 0; cp -v /root/.bashrc $BASH_SHELL_BASE/setup/backup/root'
|
||||||
|
sudo -E -- bash -c '[[ ! -f /root/.bash_profile ]] && exit 0; cp -v /root/.bash_profile $BASH_SHELL_BASE/setup/backup/root'
|
||||||
|
sudo -E -- bash -c '[[ ! -f /root/.bash_logout ]] && exit 0; cp -v /root/.bash_logout $BASH_SHELL_BASE/setup/backup/root'
|
||||||
|
fi
|
||||||
|
set +o errexit
|
||||||
|
echo backup of system shell files complete!
|
||||||
|
exit 0
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
_USER=${1:-USER}
|
||||||
|
[[ ! $(id -u $_USER) -ge 1000 ]] && echo "no user $_USER or user not a regular" && exit 1
|
||||||
|
[[ ! $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
|
|
@ -1,4 +1,48 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
sudo cp -viR $BASH_SHELL_BASE/setup/etc /etc/
|
BASH_SHELL_BASE="$(dirname "$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")"
|
||||||
cp -viR $BASH_SHELL_BASE/setup/user $HOME/
|
echo Base Shell Directory as detected is $BASH_SHELL_BASE
|
||||||
sudo cp -viR $BASH_SHELL_BASE/setup/root /root/
|
echo ok to continue?
|
||||||
|
echo "type \`yes\` fully or just <enter> for no"
|
||||||
|
read -e answer
|
||||||
|
[[ ! $answer = "yes" ]] && exit 1
|
||||||
|
[[ ! $(groups | grep sudo) ]] && echo this script must be run by a user with sudo privileges && exit 1
|
||||||
|
# uncomment for debugging
|
||||||
|
# rm -rf $BASH_SHELL_BASE/setup/backup/
|
||||||
|
if [[ ! $(stat -c "%G" /root) = "sudo" ]]; then
|
||||||
|
echo "Allow all sudoers read access to /root directory and files?"
|
||||||
|
echo "type \`yes\` fully or just <enter> for no"
|
||||||
|
read -e answer
|
||||||
|
if [[ $answer = "yes" ]]; then
|
||||||
|
sudo chown -R root:sudo /root
|
||||||
|
sudo chmod -R g+rX /root
|
||||||
|
echo sudo group and permissions on /root were set || \
|
||||||
|
echo error during sudo access setup
|
||||||
|
else
|
||||||
|
echo;echo sudoer access to /root was declined
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ ! -d $BASH_SHELL_BASE/setup/backup ]]; then
|
||||||
|
echo "backing up shell files before deploying"
|
||||||
|
$BASH_SHELL_BASE/setup/backup.sh
|
||||||
|
[[ $? -ne 0 ]] && echo issue with backup did not deploy && exit 1
|
||||||
|
# echo backup finished to $BASH_SHELL_BASE/setup/backup
|
||||||
|
fi
|
||||||
|
echo "ready to deploy shell files"
|
||||||
|
echo "Double check files in $BASH_SHELL_BASE/setup/backup"
|
||||||
|
echo "continue? type \`yes\` fully or just <enter> for no"
|
||||||
|
read -e answer
|
||||||
|
[[ ! $answer = "yes" ]] && echo aborting deploy && exit 1
|
||||||
|
echo -----------------;echo deploying /etc shell files
|
||||||
|
files=$(find $BASH_SHELL_BASE/setup/etc/ -maxdepth 1 -type f)
|
||||||
|
for file in $files; do sudo install -C -m 644 -o root -g root $file /etc; done
|
||||||
|
echo setting BASH_SHELL_BASE to $BASH_SHELL_BASE in etc/profile
|
||||||
|
sudo sed -i 's:BASH_SHELL_BASE=.*:BASH_SHELL_BASE='${BASH_SHELL_BASE}':' /etc/profile
|
||||||
|
files=$(find $BASH_SHELL_BASE/setup/etc/profile.d -maxdepth 1 -type f)
|
||||||
|
for file in $files; do sudo install -C -m 644 -o root -g root $file /etc/profile.d; done
|
||||||
|
echo -----------------;echo deploying /root shell files
|
||||||
|
group=root
|
||||||
|
[[ $(stat -c "%G" /root) = "sudo" ]] && group=sudo
|
||||||
|
files=$(find $BASH_SHELL_BASE/setup/root/ -type f)
|
||||||
|
for file in $files; do sudo install -C -m 640 -o root -g $group $file /root; done
|
||||||
|
echo -----------------
|
||||||
|
source $BASH_SHELL_BASE/setup/deploy-user.sh
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
# Set the initial path
|
# Set the initial path
|
||||||
export PATH=/bin:/usr/bin:/usr/local/bin
|
export PATH=/bin:/usr/bin:/usr/local/bin
|
||||||
# set directory for base shell repo
|
# set directory for base shell repo
|
||||||
export BASH_SHELL_BASE=/opt/bash/shell/base # where
|
export BASH_SHELL_BASE=THISWILLCHANGEDBYDEPLOYSCRIPT
|
||||||
# now bootstrap by souring the shell repo envinroment
|
# now bootstrap by souring the shell repo envinroment
|
||||||
. $BASH_SHELL_BASE/shell.env
|
. $BASH_SHELL_BASE/shell.env
|
||||||
# uncomment to NOT load the BASH SHELL Repos for interactive login shell
|
# uncomment to NOT load the BASH SHELL Repos for interactive login shell
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# echo "$USER .bashrc"
|
# echo "$USER .bashrc"
|
||||||
|
|
||||||
# processing user's shell repo if base was loaded
|
# processing user's shell repo if base was loaded
|
||||||
[[ $BASH_SHELL_BASE_LOADED = true ]] && \
|
[[ $BASH_SHELL_BASE_LOADED = true ]] && \
|
||||||
BASH_SHELL_USER=${BASH_SHELL_USER:-"bash/shell"} && \
|
BASH_SHELL_USER=${BASH_SHELL_USER:-"bash/shell"} && \
|
||||||
shell_process_directory "$HOME/$BASH_SHELL_USER"
|
[[ -d $HOME/$BASH_SHELL_USER ]] && shell_process_directory "$HOME/$BASH_SHELL_USER" ||\
|
||||||
|
echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template
|
||||||
|
|
Loading…
Reference in New Issue