#!/bin/sh

# breeze
# Copyright (C) 2010, 2011, 2012, 2017, 2018 Joseph Rosevear, San Diego
# CA, USA.

# This file is part of an application of SAM for GNU/Linux Slackware
# known as SAM-GLS.

# SAM-GLS is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.

# SAM-GLS is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# (Slackware is a registered trademark of Patrick Volkerding and
# Slackware Linux, Inc.)



# Joseph Rosevear 180327  This code perhaps needs some fixing.  It
# seems to work, but it has an annoying way of accumulating extra stuff
# in sam_add and PATH.  I spent some time trying to devise a scheme to
# keep that from happening, but now I think there is a better way.  I
# think it would be best to let it happen, but add (somewhere) a
# cleanup of sam_add and PATH.  I think that would work.  It would
# redefine the variables but with duplication removed and something
# else removed.  The something else would be extra temp dirs in the
# path.  I could perhaps allow only one sub-dir of $sam_temp_base in
# the path.  It would keep the first one, as sam puts the latest one
# first.  Thus it would keep /tmp/joe/temp1, and remove /tmp/joe/temp2.

# So that is my great idea.  But I think the coding of the one or more
# cleanup tools will need to be done in C.  Fun!



# Joseph Rosevear 110116 I changed this script so that it doesn't use
# sudo.  I did this because the new sudo (Slackware 13.1, sooner?) is
# very strict about inheriting environment variables.  It looked like I
# couldn't make it work.  This is actually better, anyway.

# I also put something back I had taken out in making the above change. 
# I provided "/sbin:/usr/sbin:$sam_add" as $2 for bound.  This worked
# well before, so I'll use it again.  Otherwise sometimes root can't
# find commands that it needs.

# Joseph Rosevear 110327 I added some things to this script to allow it
# to work in Slackware 13.1 (transitioning from 12.0):

# Joseph Rosevear 111231 I replaced #!/bin/sh with #!/bin/bash.

# Joseph Rosevear 120808 I changed the prgama back to #!/bin/sh,
# because due to changes in SAM the sh shell will work fine.

# Joseph Rosevear 170130 I made this tailored copy.

# Joseph Rosevear 170130 I made two changes below to enable this to
# work as part of my new portable SAM.

# Joseph Rosevear 171219 I added use of bplace.

# Joseph Rosevear 180313 I made this from bree.

# Joseph Rosevear 180326 I made this more like bree.  It wasn't keeping
# the current menu.  I put in "bound $level" to fix it.

# Joseph Rosevear 180329 I changed bplace to sam_root.



# Joseph Rosevear 180314 fail if $1 is "".
if [ "$1" = "" ]; then

   echo breeze: \$1 cannot be \"\".
   exit
fi

new_user="$1"
shift

place="`pwd`"

push; pop

# Joseph Rosevear 180314 I changed the code below so su will become
# $new_user instead of root.
echo login as $new_user
su -c "cd \"$place\"; \
       . $sam_temp_dir/sam_set; \
       export sam_temp_base=/tmp/$new_user;
       export HOME=/home/$new_user;
$sam_root/begin bound $level $sam_add \"final; $*\"" - $new_user
