Treitos Base Installation

by dbranco
12 deployments · 9 still active · last rev. 3 months ago

Configure the server to be installed by ansible

Compatible with: Debian 8
						#!/bin/bash
#
#<UDF name="hostname" Label="Hostname" default=""/>

function user_add_pubkey {
    # Adds the users public key to authorized_keys for the specified user. Make sure you wrap your input variables in double quotes, or the key may not load properly.
    #
    #
    # $1 - Required - username
    # $2 - Required - public key
    USERNAME="$1"
    USERPUBKEY="$2"
    
    if [ ! -n "$USERNAME" ] || [ ! -n "$USERPUBKEY" ]; then
        echo "Must provide a username and the location of a pubkey"
        return 1;
    fi
    
    if [ "$USERNAME" == "root" ]; then
        mkdir /root/.ssh
        echo "$USERPUBKEY" >> /root/.ssh/authorized_keys
        return 1;
    fi
    
    mkdir -p /home/$USERNAME/.ssh
    echo "$USERPUBKEY" >> /home/$USERNAME/.ssh/authorized_keys
    chown -R "$USERNAME":"$USERNAME" /home/$USERNAME/.ssh
}

function system_set_hostname {
    # $1 - The hostname to define
    HOSTNAME="$1"
        
    if [ ! -n "$HOSTNAME" ]; then
        echo "Hostname undefined"
        return 1;
    fi
    
    echo "$HOSTNAME" > /etc/hostname
    hostname -F /etc/hostname
}


user_add_pubkey "root" "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDAKDQPI1k7w+HiCKUF4T8mkKZ0b6AtNpFF6EYtqsVX1KVlfkrVU9SLNFeKiejFPbIcwPSyi1GT/95OuRSdQKWdhCtn/lIhbLjtBUryY36H47xs46Ev2NH0jgBaLCvP0baWmm0aN9nKiiyY0f1IlXSshhIy3cNHSYpydb+A2Ryl9kKCKokZDr8fG5Toy4Rw4yNLgcksgfqPMPyOPPbR7sw2w0EtOisGjASRs4keEE6GPJ8t/lauxRQavUAk4LRSWMVG5YftJ5ETPJu4wwUBhwqSnbqUkFOEL1VZJ8Xq5fDKy/I+kF1rENXCck+LUZnfxw/rXTnC81HH6SGV90UDDBqCu1ZO4vU9EWSorA2d88YWJlRVrKL7ul+k9q7U4ThPog6zcJoXFVTC25emLlldiay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