User configuration

by willemkokke
0 deployments · 0 still active · last rev. 9 months ago

This is a library to configure a new user and set it up to use sudo.
Do not deploy directly, but include it with:

source <ssinclude StackScriptID=14152>

You need to copy the UDF declarations into the main calling script as only the main script seems to be parsed for UDF declarations.

@willemkokke

Compatible with: Ubuntu 14.04 LTS
Includes: Utilities
						#!/bin/bash
# @willemkokke
# Copy this into the main calling script
# <UDF name="user_name" label="User Name" />
# <UDF name="user_password" label="Password" />

source <ssinclude StackScriptID=14154> # Utilities

export USER_NAME=`lowercase $USER_NAME`

function get_home_directory {
    # get_home_directory(username)
    # $1 username
    cat /etc/passwd | grep "^$1:" | cut --delimiter=":" -f6
}

function add_user {
    # add_user(username, password)
    # $1 username
    # $2 password
    adduser $1 --disabled-password --gecos "Server Admin"
    echo "$1:$2" | chpasswd
    usermod -aG sudo $1
    log "Added user $USER_NAME"
}

function configure_user {
    add_user $USER_NAME $USER_PASSWORD
}