"Fossies" - the Fresh Open Source Software Archive

Member "scponly-20110526/build_extras/addscp.sh" (17 Nov 2003, 1872 Bytes) of package /linux/privat/old/scponly-20110526.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 #made by Konrad Krzysztof Krasinski 2003
    3 #3rd october 2003 - updated for RH9 support
    4 
    5 echo -n "Install for what username? "
    6 read user
    7 
    8 if [ "x$user" = "x" ]
    9 then
   10     echo "bad username !!!"
   11     exit
   12 fi
   13 
   14 echo
   15 userhome=/home/$user
   16 echo -n "enter the home directory you wish to set for this user: [$userhome] "
   17 read userhome2
   18 if [ "x$userhome2" != "x" ]; then
   19     userhome=$userhome2
   20 fi
   21 
   22 szablon=template_scp
   23 szablonhome=/home/$szablon
   24 
   25 #userdel $user
   26 #rm -rf $userhome
   27 
   28 mkdir -p $userhome
   29 useradd -d $userhome//public_ftp -s /usr/local/sbin/scponlyc $user
   30 
   31 for x in `find $szablonhome -type d`
   32 do
   33     y=`echo $x | awk '{print substr($1,length("'$szablonhome'")+2)}'`
   34     echo mkdir:   $y
   35     mkdir -p $userhome/$y
   36 done
   37 
   38 for x in `find $szablonhome -type f | grep -v public_ftp | grep -v /etc/passwd | grep -v /etc/group`
   39 do
   40 #    echo $x
   41     y=`echo $x | awk '{print substr($1,length("'$szablonhome'")+2)}'`
   42     echo ln:   $y
   43     ln $szablonhome/$y $userhome/$y
   44 done
   45 
   46 echo /etc/passwd - important security fix
   47 useruid=`id -u $user`
   48 usergid=`id -g $user`
   49 cat /etc/passwd | awk -F":" '{if($3==0){print $0}}' > $userhome/etc/passwd
   50 #winscp seems to work bad with long names with "_" char - like "template_scp"
   51 #so we cheats it by standard "user" name
   52 dummyuser="user"
   53 dummyhome="/public_ftp"
   54 dummyshell="/usr/bin/oafish"
   55 cat /etc/passwd | awk -F":" '{if($3=='$useruid'){print "'$dummyuser':"$2":"$3":"$4":"$5":'$dummyhome':'$dummyshell'"}}' >> $userhome/etc/passwd
   56 
   57 echo /etc/group - adding
   58 cat /etc/group | awk -F":" '{if($3==0){print $0}}' > $userhome/etc/group
   59 dummygroup="users"
   60 cat /etc/group | awk -F":" '{if($3=='$usergid'){print "'$dummygroup':"$2":"$3":"$4}}' >> $userhome/etc/group
   61 
   62 echo clearing new home dir ...
   63 rm -rf $userhome/public_ftp
   64 mkdir -p $userhome/public_ftp
   65 chown -R $user.users $userhome/public_ftp
   66 
   67 #edquota -p $szablon $user
   68 
   69 passwd $user