<commit_before>#!/bin/bash
#<UDF name="server_hostname" label="Hostname" default="" description="hostname for this server" />
#<UDF name="username" label="main user login" default="fooser" description="a non-root (but sudoing) user for the server" />
#<UDF name="password" label="main user password" default="" description="a temporary password to be reset on first login" />
#<UDF name="github_user" label="GitHub user whose keys will be installed" default="" description="optional GitHub user for authorized_keys" />
#<UDF name="timezone" label="Timezone of the server" default="" description="optional timezone for the server" />
#<UDF name="gist_id" label="Gist token" default="" description="optional GitHub gist (run as a shell script)" />

log() {
  echo "$SERVER_HOSTNAME - `date +'%Y/%m/%d %H:%M:%S.%N'` :: $1" >> ~/StackScript.log
}

initial_server_setup() {
  log "starting stackscript"

  cat <<EOF > ./rerun-StackScript
#!/bin/bash

# This script should allow for easier troubleshooting; just source this file before re-running
# the ~root/StackScript after a failed deploy.

SERVER_HOSTNAME=$SERVER_HOSTNAME
USERNAME=$USERNAME
GITHUB_USER=$GITHUB_USER
TIMEZONE=$TIMEZONE
GIST_ID=$GIST_ID

source ./StackScript
EOF
  chmod 755 ./rerun-StackScript

  # First, a few useful packages
  apt-get update
  for cmd in curl wget git tree tmux; do
    apt-get install -y $cmd
    log "$cmd path: `which $cmd`"
  done

  USER_HOME=/home/$USERNAME
  log "USER_HOME: $USER_HOME"


  # Set the hostname
  hostname $SERVER_HOSTNAME
  echo $SERVER_HOSTNAME > /etc/hostname
  sed -i "s/127.0.1.1.*/127.0.1.1 $SERVER_HOSTNAME/" /etc/hosts

  # Add the main user
  useradd -m -s /bin/bash $USERNAME
  if [ -z "$PASSWORD" ]; then<commit_msg>fixing creation of rerun script<commit_after>#!/bin/bash
#<UDF name="server_hostname" label="Hostname" default="" description="hostname for this server" />
#<UDF name="username" label="main user login" default="fooser" description="a non-root (but sudoing) user for the server" />
#<UDF name="password" label="main user password" default="" description="a temporary password to be reset on first login" />
#<UDF name="github_user" label="GitHub user whose keys will be installed" default="" description="optional GitHub user for authorized_keys" />
#<UDF name="timezone" label="Timezone of the server" default="" description="optional timezone for the server" />
#<UDF name="gist_id" label="Gist token" default="" description="optional GitHub gist (run as a shell script)" />

log() {
  echo "$SERVER_HOSTNAME - `date +'%Y/%m/%d %H:%M:%S.%N'` :: $1" >> ~/StackScript.log
}

initial_server_setup() {
  log "starting stackscript"

  cat <<EOF > ~/rerun-StackScript
#!/bin/bash

# This script should allow for easier troubleshooting after a failed deploy;
# it re-sets all the UDF parameters before re-running ~root/StackScript.

SERVER_HOSTNAME=$SERVER_HOSTNAME
USERNAME=$USERNAME
GITHUB_USER=$GITHUB_USER
TIMEZONE=$TIMEZONE
GIST_ID=$GIST_ID

source ./StackScript
EOF
  chmod 755 ./rerun-StackScript

  # First, a few useful packages
  apt-get update
  for cmd in curl wget git tree tmux; do
    apt-get install -y $cmd
    log "$cmd path: `which $cmd`"
  done

  USER_HOME=/home/$USERNAME
  log "USER_HOME: $USER_HOME"


  # Set the hostname
  hostname $SERVER_HOSTNAME
  echo $SERVER_HOSTNAME > /etc/hostname
  sed -i "s/127.0.1.1.*/127.0.1.1 $SERVER_HOSTNAME/" /etc/hosts

  # Add the main user
  useradd -m -s /bin/bash $USERNAME
  if [ -z "$PASSWORD" ]; then
{'fraction_non_alphanumeric': 0.1352974828375286, 'fraction_numerical': 0.009153318077803204, 'mean_word_length': 4.658576051779935, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '916654', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1143, 'n_words': 364}