Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By Watael
  • 1 Post By nixcraft

Thread: svnuseradd.sh: Add svnuser into your system

  1. #1
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Red face svnuseradd.sh: Add svnuser into your system

    Hello everybody,

    i have created svnuseradd.sh script for ubuntu , i hope it will useful for svn users

    PHP Code:
    #!/bin/bash

    # svnuseradd.sh
    #-----------------------------------------------------------------------------------------------------
    # Author  : Rahul Patil<linuxian.com>
    # Date    : Wed Nov 28 18:51:43 IST 2012
    # Purpose :
    # * This Script Created for add svnuser into your system
    # * You can also add existing user into svngroup using this script
    # * it will create ssh private and public keys for every each users ( Password less login for tortoisesvn )
    # * it will gives you ssh pubic key in users own home directory, which can be load from windows machine using pegagent
    # * it will add "svn ssh-tunnel", "svn log file" for each user
    # * install usermin for user self password changer from webinterface
    # * tested and working in Ubuntu
    # * Default User password "username@1234"
    # * Default Shell /bin/sh but , no-pty user will not able to login system , 
    #-----------------------------------------------------------------------------------------------------


    # Specify Your Repository/Project path
    Project="/svn/repositories/safesquid/"
    Svnserv_binary="$(which svnserve)"

    # specify Your svngroup or use default
    SvnGroup="svngroup"

    # Difine ssh passkey if you want otherwise leave it
    Pass_key=""

    ## Color Function
    shw_norm () {
    echo $(
    tput bold)$(tput setaf 2) $@ $(tput sgr 0)
    }

    shw_err ()  {     local message="$1"     local status=${2:-1### default exit status 1     echo -e "$(tput bold)$(tput setaf 1) $message $(tput sgr 0)"     exit $status }



    # Check 1#
    #if args less than zero then show_help
    [[ $# -eq 0 ]] && { useradd --help; exit; };

    # check 2#
    # if Project not specify then exit
    [[ ! -"${Project}]] && {
                            
    shw_err "Project does not exist..\nPlease define Project path in $0";
                            exit 
    1;
                            };

    # check 3#
    # if subversion not install then exit
    [[ -"${Svnserv_binary}]] && {
                            
    shw_err  "Subversion not installed..\nPlease install Subversion..." 1
                            
                            
    };

    # check 4#
    # if puttygen not installed then install
    if !  (which puttygen >/dev/null 2>&1); then
                            shw_norm 
    "puttygen not installed...\ninstalling puttygen"sleep 2s && \
                            
    apt-get install putty-tools
    fi

    # check 5#
    # if usermin not installed then install
    if [ ! -"/etc/usermin/miniserv.conf" ]; then
    shw_norm 
    "Usermin is not Install..." && sleep 1s &&                              \
    shw_norm "Installing Usermin For Selfpassword change for user" && sleep 2s && \
    apt-get install libnet-ssleay-perl libio-pty-perl apt-show-versions -&&     \
    wget http://prdownloads.sourceforge.net/webadmin/usermin_1.530_all.deb &&     \
    dpkg -i usermin_1.530_all.deb                                                   
    # remove unwated rights from usermin only keep password change options
    cp /etc/usermin/webmin.acl{,-bkp$(date +&#37;F)}
    echo 'user: changepass' > /etc/usermin/webmin.acl
    fi

    useradd_sshkey
    () {
                    
    # if group does not exists then create
                    
    grep -"${SvnGroup}/etc/group || groupadd ${SvnGroup}

                    
    # add new user else add existing user into svn group
                    
    useradd -/bin/false -"${SvnGroup}-"$@" &&  \
                    
    read User_name Home_Dir <<<"$(awk -F: 'END{print $1,$6}' /etc/passwd)" || \
                    { 
    useradd -"${SvnGroup}$1Input="$1" ; \
                    
    read User_name Home_Dir <<<"$(awk -F: "/$Input"'{print $1,$6}' /etc/passwd)"; };

                    
    # Set password
                    
    echo "${User_name}:${User_name}@1234" | /usr/sbin/chpasswd
                    
    # if home dir not exists then create
                    
    [[ ! -"${Home_Dir}]] && mkdir "${Home_Dir}"

                    
    # if .ssh dir not exists in uses home dir then create
                    
    [[ ! -"${Home_Dir}/.ssh" ]] && mkdir ${Home_Dir}/.ssh

                    
    # add svn ssh tunnel into user's authorized keys
                    
    echo -"command=\"${Svnserv_binary} -t --tunnel-user=${User_name} -r ${Project} --log-file=/tmp/svnserver_${User_name}.log\",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty"  >>  "${Home_Dir}"/.ssh/authorized_keys

                    
    # create private and public key using ssh-keygen without pass
                    
    ssh-keygen -"${Pass_key}-t rsa -b 1024 -"${User_name}"_ssh.key

                    
    # connvert private key into ssh_key.ppk which can use to load into pagagent in windows
                    
    puttygen "${User_name}"_ssh.key -private -"${Home_Dir}"/"${User_name}"_ssh.ppk
                    
    echo -' ' >> "${Home_Dir}"/.ssh/authorized_keys
                    cat 
    "${User_name}"_ssh.key.pub >> "${Home_Dir}/.ssh/authorized_keys"

                    
    # change permission
                    
    chown -"${User_name}"  "${Home_Dir}"
                    
    chmod 700 -R  "${Home_Dir}"
                    
                   
    }



    useradd_sshkey "$@" 
    All Master Advice and comments are welcome
    Last edited by Rahul.Patil; 1st December 2012 at 10:36 AM.
    Rahul Patil <http://www.linuxian.com>

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    hi,

    Code:
    if ! (grep -q "${SvnGroup}" /etc/group); then groupadd ${SvnGroup}; fi
    why use a subshell?
    simple conditions, simple expression:
    Code:
    grep -q "${SvnGroup}" /etc/group || groupadd ${SvnGroup}
    just like you use it below;
    where you don't need those backslashes to keep the line, for example :
    Code:
    condition || {
       command
       command
    }
    the command list is clearly seen then.

    about indentation: a whole tabulation is a lot, three or four spaces are enough.

    Code:
    read var <<<$(command)
    it works, but
    Code:
    read var < <(command)
    seems nicer. is it more efficient? I sincerly don't know.
    Rahul.Patil likes this.
    «A problem clearly stated is a problem half solved.»

  3. #3
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Hi,

    Thanks wateal , i updated that.. and i use backslash with && because if one success then run another.
    Rahul Patil <http://www.linuxian.com>

  4. #4
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    I agree about these && \
    it's more readable than all on one line.
    I was talking about the command lists and conditions.
    «A problem clearly stated is a problem half solved.»

  5. #5
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,374
    Thanks
    17
    Thanked 754 Times in 496 Posts
    Rep Power
    10

    Default

    Code:
    shw_err ()  {
        local message="$1"
        local status=${2:-1} ### default exit status 1
        echo -e "$(tput bold)$(tput setaf 1) $message $(tput sgr 0)"
        exit $status
    }
    And call as:
    Code:
    shw_err  "Subversion not installed..\nPlease install Subversion..." 2
    shw_err  "Subversion not found..\nbut needed version 5.x..."
    tput code can be replaced with echo command:
    Code:
    echo -e "\033[1mFoo Bar\033[0m"
    Last edited by nixcraft; 1st December 2012 at 12:13 AM.
    Rahul.Patil likes this.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. smbclient: Copy files from a Linux system to Windows system
    By inshaf.ccna in forum Shell scripting
    Replies: 3
    Last Post: 10th May 2012, 08:29 PM
  2. Snapshotting a system?
    By driller in forum Ubuntu / Debian
    Replies: 5
    Last Post: 8th February 2011, 09:36 AM
  3. System hangs (freezes) on system bell/beep
    By DeadBadger in forum Solaris/OpenSolaris
    Replies: 2
    Last Post: 9th January 2011, 07:57 PM
  4. [Solved] System banned itself
    By gerwim in forum Ubuntu / Debian
    Replies: 11
    Last Post: 15th September 2010, 06:51 AM
  5. Replies: 3
    Last Post: 15th November 2008, 10:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41