<commit_before>#!/bin/bash

# Starter Upper: Setup git hosting for classroom use with minimal user interaction.

# Configuration
# ---------------------------------------------------------------------

# School domain to use in email address example
readonly SCHOOL=wit.edu
# The instructor's name
readonly INSTRUCTOR_NAME="<NAME>"
# The instructor's email
readonly INSTRUCTOR_EMAIL="<EMAIL>"
# The instructor's Github username
readonly INSTRUCTOR_GITHUB=lawrancej
# The repository to clone as upstream (NO SPACES)
readonly REPO=COMP603-2014

# More issues:
# go through all pages when fetching usernames
# grading interface: checkout stuff rapid fire like, possibly use git notes
# fall back to https remotes if the school doesn't support SSH
# if the public key already exists on another account, ask user if they'd like to wipe existing keypair and generate a new one.
# revoke authorization automatically DELETE /authorizations/:id  (need to store the id in the first place)
# use github user's full name in camel case as remote name when doing collaborator setup
# bitbucket, gitlab support
# make it work for team projects
# make it work if the instructor repository is private (one way to achieve this would be to create the student private repo first)
# technically, it's not necessary to store the github username.
# go with default if the user presses enter

# Runtime flags (DO NOT CHANGE)
# ---------------------------------------------------------------------
readonly PROGNAME=$(basename $0)
readonly ARGS="$@"

ssh_works=true # unless proven otherwise...
fullname=''
email=''
github_login=''

# Utilities
# ---------------------------------------------------------------------

# Set $USERNAME, if not already set.
get_username() {
    if [[ -z "$USERNAME" ]]; then
        USERNAME=$(id -nu 2> /dev/null)
    fi
    if [[ -z "$USERNAME" ]]; then
        USERNAME=$(whoami 2> /dev/null)
    fi
}

# Get the user's full name
get_userfullname() {
    get_username

    case $OSTYPE in
        msys | cygwin )
            cat << 'EOF' > getfullname.ps1
$MethodDefinition = @'
[DllImport("secur32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetUserNameEx (int nameFormat, System.Text.StringBuilder userName, ref uint userNameSize);
'@
$windows = Add-Type -MemberDefinition $MethodDefinition -Name 'Secur32' -Namespace 'Win32' -PassThru
$sb = New-Object System.Text.StringBuilder
$num=[uint32]256
$windows::GetUserNameEx(3, $sb, [ref]$num) | out-null
$sb.ToString()
EOF
            FULLNAME=$(powershell -executionpolicy remotesigned -File getfullname.ps1 | sed -e 's/\(.*\), \(.*\)/\2 \1/')
            rm getfullname.ps1 > /dev/null
            ;;
        linux* ) # untested
            FULLNAME=$(getent passwd $USERNAME | cut -d ':' -f 5 | cut -d ',' -f 1)
            ;;
        darwin* ) # untested
            FULLNAME=$(dscl . read /Users/`whoami` RealName | grep -v RealName | cut -c 2-)
            ;;
        *) FULLNAME="" ;;<commit_msg>Following guidelines in Defensive BASH programming guide.<commit_after>#!/bin/bash

# Starter Upper: Setup git hosting for classroom use with minimal user interaction.

# Configuration
# ---------------------------------------------------------------------

# School domain to use in email address example
readonly SCHOOL=wit.edu
# The instructor's name
readonly INSTRUCTOR_NAME="<NAME>"
# The instructor's email
readonly INSTRUCTOR_EMAIL="<EMAIL>"
# The instructor's Github username
readonly INSTRUCTOR_GITHUB=lawrancej
# The repository to clone as upstream (NO SPACES)
readonly REPO=COMP603-2014

# More issues:
# go through all pages when fetching usernames
# grading interface: checkout stuff rapid fire like, possibly use git notes
# fall back to https remotes if the school doesn't support SSH
# if the public key already exists on another account, ask user if they'd like to wipe existing keypair and generate a new one.
# revoke authorization automatically DELETE /authorizations/:id  (need to store the id in the first place)
# use github user's full name in camel case as remote name when doing collaborator setup
# bitbucket, gitlab support
# make it work for team projects
# make it work if the instructor repository is private (one way to achieve this would be to create the student private repo first)
# technically, it's not necessary to store the github username.
# go with default if the user presses enter

# Runtime flags (DO NOT CHANGE)
# ---------------------------------------------------------------------
readonly PROGNAME=$(basename $0)
readonly ARGS="$@"

ssh_works=true # unless proven otherwise...
fullname=''
email=''
github_login=''

# Utilities
# ---------------------------------------------------------------------

is_empty() {
    local var=$1
    [[ -z $var ]]
}

# Set $USERNAME, if not already set.
set_username() {
    is_empty "$USERNAME" && \
        USERNAME="$(id -nu 2> /dev/null)"

    is_empty "$USERNAME" && \
        USERNAME="$(whoami 2> /dev/null)"
}

# Get the user's full name
get_userfullname() {
    set_username

    case $OSTYPE in
        msys | cygwin )
            cat << 'EOF' > getfullname.ps1
$MethodDefinition = @'
[DllImport("secur32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetUserNameEx (int nameFormat, System.Text.StringBuilder userName, ref uint userNameSize);
'@
$windows = Add-Type -MemberDefinition $MethodDefinition -Name 'Secur32' -Namespace 'Win32' -PassThru
$sb = New-Object System.Text.StringBuilder
$num=[uint32]256
$windows::GetUserNameEx(3, $sb, [ref]$num) | out-null
$sb.ToString()
EOF
            FULLNAME=$(powershell -executionpolicy remotesigned -File getfullname.ps1 | sed -e 's/\(.*\), \(.*\)/\2 \1/')
            rm getfullname.ps1 > /dev/null
            ;;
        linux* ) # untested
            FULLNAME=$(getent passwd "$USERNAME" | cut -d ':' -f 5 | cut -d ',' -f 1)
            ;;
        darwin* ) # untested
            FULLNAME=$(dscl . read /Users/`whoami` RealName | grep -v RealName | cut -c 2-)
            ;;
        *) FULLNAME="" ;;
{'fraction_non_alphanumeric': 0.16919775503466492, 'fraction_numerical': 0.010069329811819083, 'mean_word_length': 2.6368547418967587, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '6151655', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1673, 'n_words': 631}