Refactored and fixed become
This commit is contained in:
parent
2e865bfa02
commit
185d813c0e
2 changed files with 38 additions and 20 deletions
36
bootstrap.sh
36
bootstrap.sh
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
TODAY=`date`
|
||||
HOSTNAME=`hostname`
|
||||
ARGLINE="$@"
|
||||
echo $ARGLINE
|
||||
|
||||
function debug
|
||||
{
|
||||
|
|
@ -17,7 +15,7 @@ function debug
|
|||
|
||||
function err
|
||||
{
|
||||
echo -e "FATAL ERROR: $1"
|
||||
echo -e "FATAL ERROR: $@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
|
@ -72,16 +70,30 @@ function send_notification
|
|||
|
||||
function become
|
||||
{
|
||||
local tempfile
|
||||
|
||||
if test -z "$BECOME"; then
|
||||
echo $BASH_SOURCE
|
||||
exit
|
||||
chmod 0755 $tempfile
|
||||
sudo su - --command=$tempfile
|
||||
rm $tempfile
|
||||
exit
|
||||
local _bbfile
|
||||
|
||||
_bbfile=/tmp/bb_become.$_bb_myname
|
||||
|
||||
if test -z "$_bb_myname" -o -z "$_bb_mypath"; then
|
||||
err "\$_bb_myname and/or \$_bb_mypath must bet set to user become function!"
|
||||
fi
|
||||
|
||||
if test -f "$_bbfile"; then
|
||||
if [ $(id -u) = 0 ]; then
|
||||
# Check if it's a login shell
|
||||
if shopt -q login_shell; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
err "Unable to become: $_bbfile exists." \
|
||||
"\nThis may happen if the script was interrupted." \
|
||||
"\nIf this is the case, please remove '$_bbfile' and run this script '$_bb_mypath' again."
|
||||
fi
|
||||
|
||||
touch $_bbfile
|
||||
sudo bash --login $_bb_mypath "$@"
|
||||
rm $_bbfile
|
||||
exit
|
||||
}
|
||||
|
||||
function check_values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue