shell-base/setup/deploy.sh

50 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
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> 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/bash.bashrc and /etc/profile
sudo sed -i 's:_BASH_SHELL_BASE_:'${BASH_SHELL_BASE}':' /etc/bash.bashrc
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