<commit_before>#!/bin/bash

display_usage() {
    echo -e "\nUSAGE: manageUser ACTION USERNAME"
    echo -e "(must be run with super-user privileges)\n"
}

if [ $# -lt 2 ]; then
    display_usage
    exit 1
fi

if [[ ( $# == "--help") ||  $# == "-h" ]]; then
    display_usage
    exit 0
fi

if [[ $USER != "root" ]]; then
    echo "This script must be run as root!"
    exit 1
fi

action=$1
username=$2

if [[ "$username" == "ec2-user" || "$username" == "root" ]]; then
    echo "!! Cannot take action on ec2-user or root users !!"
    exit 1
fi

if grep -q "wheel.*$username" /etc/group; then
    echo "!! Cannot take action on members of the wheel group !!"
    exit 1
fi

if [[ "$action" != "delete" && "$action" != "add" ]]; then
    echo "Invalid action specified - Must be 'add' or 'delete'"
    exit 2
fi

if [ -z "$username" ]; then
    echo "USERNAME is required"
    exit 2
fi

# ADD
if [[ "$action" == "add" ]]; then

    read -p "Enter the public key of $username > " publickey

    if [ -z "$publickey" ]; then
        echo "A public key is required"
        exit 2
    fi

    if ! grep -q $username /etc/passwd; then
        ## Add User
        useradd -m $username 2> /dev/null # Don't care if they already exist
    fi

    if [ ! -d /home/$username/.ssh ]; then
        ## Verify home folder
        mkdir -p /home/$username/.ssh
    fi

    ## Add / Reset authorized key
    echo "$publickey" > /home/$username/.ssh/authorized_keys

    ## Verify permissions
    chown -R $username:$username /home/$username
    chmod 0700 /home/$username/.ssh
    chmod 0600 /home/$username/.ssh/authorized_keys

    ## Add to admin group (if it exists)
    if ! grep -q admin /etc/group; then
      groupadd admin
      bash -c 'echo "admin ALL=(ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo)'
    fi
    usermod -aG admin,ec2-user $username<commit_msg>admin GROUP, not user<commit_after>#!/bin/bash

display_usage() {
    echo -e "\nUSAGE: manageUser ACTION USERNAME"
    echo -e "(must be run with super-user privileges)\n"
}

if [ $# -lt 2 ]; then
    display_usage
    exit 1
fi

if [[ ( $# == "--help") ||  $# == "-h" ]]; then
    display_usage
    exit 0
fi

if [[ $USER != "root" ]]; then
    echo "This script must be run as root!"
    exit 1
fi

action=$1
username=$2

if [[ "$username" == "ec2-user" || "$username" == "root" ]]; then
    echo "!! Cannot take action on ec2-user or root users !!"
    exit 1
fi

if grep -q "wheel.*$username" /etc/group; then
    echo "!! Cannot take action on members of the wheel group !!"
    exit 1
fi

if [[ "$action" != "delete" && "$action" != "add" ]]; then
    echo "Invalid action specified - Must be 'add' or 'delete'"
    exit 2
fi

if [ -z "$username" ]; then
    echo "USERNAME is required"
    exit 2
fi

# ADD
if [[ "$action" == "add" ]]; then

    read -p "Enter the public key of $username > " publickey

    if [ -z "$publickey" ]; then
        echo "A public key is required"
        exit 2
    fi

    if ! grep -q $username /etc/passwd; then
        ## Add User
        useradd -m $username 2> /dev/null # Don't care if they already exist
    fi

    if [ ! -d /home/$username/.ssh ]; then
        ## Verify home folder
        mkdir -p /home/$username/.ssh
    fi

    ## Add / Reset authorized key
    echo "$publickey" > /home/$username/.ssh/authorized_keys

    ## Verify permissions
    chown -R $username:$username /home/$username
    chmod 0700 /home/$username/.ssh
    chmod 0600 /home/$username/.ssh/authorized_keys

    ## Add to admin group (if it exists)
    if ! grep -q admin /etc/group; then
      groupadd admin
      bash -c 'echo "%admin ALL=(ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo)'
    fi
    usermod -aG admin,ec2-user $username
{'fraction_non_alphanumeric': 0.14711409395973155, 'fraction_numerical': 0.012348993288590604, 'mean_word_length': 2.387272727272727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1491371', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1228, 'n_words': 450}