<commit_before>#/bin/bash
LAST=""
LAST_file='server-worker.last'

if [ -f "$LAST_file" ]; then
  LAST=$(cat server-worker.last)
  
  if [ -z "$LAST" ]; then
    echo "lastid not found, starting from top"
    LAST=1
    echo "$LAST" > "$LAST_file" || exit 1
  elif [[ ! "$LAST" =~ ^-?[0-9]+$ ]]; then
    echo "lastid is broken, starting from top"
    LAST=1
    echo "$LAST" > "$LAST_file" || exit 1
  fi
else
  touch $LAST_file || exit 1
fi

JOBLINE=$(curl -s http://freifunk.liztv.net/api/serverjobs.php?last=$LAST)
if [ -z "$JOBLINE" ]; then
  exit 0
fi

JOBID=$(echo "$JOBLINE" | cut -d '|' -f 1)
if [[ ! "$JOBID" =~ ^-?[0-9]+$ ]]; then
  exit 1
fi

JOB=$(echo "$JOBLINE" | cut -d '|' -f 2)

if [ $(echo "$JOB" | cut -d ' ' -f 1) == "deployvpn" ]; then 
  HWID=$(echo "$JOB" | cut -d ' ' -f 2)
  if [ ${#HWID} -ne 12 ]; then
    exit 1
  fi
  COMMUNITY_EXPECTED=$(echo "$JOB" | cut -d ' ' -f 3)

  RESPONSE=$(curl -sS http://freifunk.liztv.net/api/fastd-key.php?hwid=$HWID)

  if [ -z "$RESPONSE" ]; then
    echo "No such HWID found in Database"
    exit 1
  fi

  COMMUNITY=$(echo $RESPONSE | cut -d'|' -f 1)
  KEY=$(echo $RESPONSE | cut -d'|' -f 2)

  if [ -z "$COMMUNITY" ]; then
        echo "Error: Community-string fetched from server was empty"
        exit 1
  fi

  if [ -z "$KEY" ]; then
        echo "Error: Fastd-public-key fetched from server was empty"
        exit 1
  fi

  if [ ${#KEY} -ne 64 ]; then
    echo "Error: Fastd-public-key fetched from server was not valid."
    exit 1
  fi

  if [ "$COMMUNITY" != "$COMMUNITY_EXPECTED" ]; then
    echo "Error: Server said community is $COMMUNITY, you entered $COMMUNITY_EXPECTED, you have to fix the database."
    exit 1
  fi

  DIR="/etc/fastd/$COMMUNITY/nodes/"
  if [ ! -d "$DIR" ]; then
    echo "Error: we can't locate the folder for the keyfiles"
    exit 1
  fi

  KEY="key \"$KEY\";"

  echo $KEY > $DIR$HWID
  kill -HUP $(ps aux | grep fastd | grep $COMMUNITY | awk '{print $2}')

  echo "deploy $HWID $COMMUNITY"
fi

echo $JOBID > server-worker.last
<commit_msg>add detailed output to server log<commit_after>#/bin/bash
LAST=""
LAST_file='server-worker.last'

if [ -f "$LAST_file" ]; then
  LAST=$(cat server-worker.last)
  
  if [ -z "$LAST" ]; then
    echo "lastid not found, starting from top"
    LAST=1
    echo "$LAST" > "$LAST_file" || exit 1
  elif [[ ! "$LAST" =~ ^-?[0-9]+$ ]]; then
    echo "lastid is broken, starting from top"
    LAST=1
    echo "$LAST" > "$LAST_file" || exit 1
  fi
else
  touch $LAST_file || exit 1
fi

JOBLINE=$(curl -s http://freifunk.liztv.net/api/serverjobs.php?last=$LAST)
if [ -z "$JOBLINE" ]; then
  exit 0
fi

JOBID=$(echo "$JOBLINE" | cut -d '|' -f 1)
if [[ ! "$JOBID" =~ ^-?[0-9]+$ ]]; then
  exit 1
fi

JOB=$(echo "$JOBLINE" | cut -d '|' -f 2)

if [ $(echo "$JOB" | cut -d ' ' -f 1) == "deployvpn" ]; then 
  HWID=$(echo "$JOB" | cut -d ' ' -f 2)
  if [ ${#HWID} -ne 12 ]; then
    exit 1
  fi
  COMMUNITY_EXPECTED=$(echo "$JOB" | cut -d ' ' -f 3)

  RESPONSE=$(curl -sS http://freifunk.liztv.net/api/fastd-key.php?hwid=$HWID)

  if [ -z "$RESPONSE" ]; then
    echo "No such HWID found in Database"
    exit 1
  fi

  COMMUNITY=$(echo $RESPONSE | cut -d'|' -f 1)
  KEY=$(echo $RESPONSE | cut -d'|' -f 2)

  if [ -z "$COMMUNITY" ]; then
        echo "Error: Community-string fetched from server was empty"
        exit 1
  fi

  if [ -z "$KEY" ]; then
        echo "Error: Fastd-public-key fetched from server was empty"
        exit 1
  fi

  if [ ${#KEY} -ne 64 ]; then
    echo "Error: Fastd-public-key fetched from server was not valid."
    exit 1
  fi

  if [ "$COMMUNITY" != "$COMMUNITY_EXPECTED" ]; then
    echo "Error: Server said community is $COMMUNITY, you entered $COMMUNITY_EXPECTED, you have to fix the database."
    exit 1
  fi

  DIR="/etc/fastd/$COMMUNITY/nodes/"
  if [ ! -d "$DIR" ]; then
    echo "Error: we can't locate the folder for the keyfiles"
    exit 1
  fi

  KEY="key \"$KEY\";"
  
  if [ -f $DIR$HWID ]; then
  	if [ "$(cat $DIR$HWID)" == "$KEY" ]; then
  		logger "server-worker: no need to reimport '$HWID' for community '$COMMUNITY'"
  		echo $JOBID > server-worker.last
  		exit 0
  	else
  		logger "server-worker: overwriting fastd-key for hwid '$HWID' in community '$COMMUNITY'"
  	fi
  else
    logger "server-worker: importing fastd-key for new hwid '$HWID' in community '$COMMUNITY'"
  fi
  
  echo $KEY > $DIR$HWID
  kill -HUP $(ps aux | grep fastd | grep $COMMUNITY | awk '{print $2}')
fi

echo $JOBID > server-worker.last

{'fraction_non_alphanumeric': 0.17152391546162402, 'fraction_numerical': 0.0135706340378198, 'mean_word_length': 2.7466666666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1498463', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1757, 'n_words': 548}