find and remove old zeek log files in clean_log

#!/bin/bash

# this script should be executed when box starts up and executed periodically
# this script itself should not depends on any partition space, meaning it should be able to run with all disks full
# threshold
# regular:
# remove files under /log/blog that are not modified for more than 24 hours, also remove empty directories
# soft: (/log is over 85%)
# remove
# /var/log/*.gz
# /log/blog//files.gz
# /log/forever/main.log
# /log/forever/main_last.log
# any files under /log/firewalla that is older than one day
# hard (/log is over 95%)
# remove
# all files under soft
# /var/log/syslog
# /log/apt/cache/*
# /log/forever/*
# /log/firewalla/*

# ----------------------------------------------------------------------------
# Functions
# ----------------------------------------------------------------------------
mylog() {
    echo "$(date -u): $@"
}

loginfo() {
    mylog "INFO: $@"
}

logerror() {
    mylog "ERROR: $@" >&2
}

soft_clean() {
    loginfo "do SOFT cleaning ..."
    sudo journalctl --vacuum-size=40M
    sudo rm -f /var/log/*.gz
    sudo rm -f /log/blog/*/files.*.gz
    rm -f /log/forever/main_last.log
    : > /log/forever/main.log
    # any files under /log/firewalla that is older than one day
    find /log/firewalla -mtime +1 -delete
}

hard_clean() {
    loginfo "do HARD cleaning ..."
    : | sudo  tee /var/log/syslog
    sudo journalctl --vacuum-size=20M
    sudo find /var/log/ -type f -size +1M -exec truncate -s 0 {} \;
    sudo rm -rf /log/apt/cache/*
    sudo rm -rf /log/apt/lib/*
    sudo find /log/blog/ -type f -name "*.gz" -exec rm -f {} \;
    sudo chown pi:pi /log/forever/*
    sudo find /log/forever/ /log/firewalla/ /log/redis/ -type f -size +1M -exec truncate -s 0 {} \;
}

# ----------------------------------------------------------------------------
# MAIN goes here
# ----------------------------------------------------------------------------

# remove old files
sudo find "/log/blog/" -type f -regex '.*/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/.*$' -mmin +1440 -delete
# remove old directories, non-empty directories will not be removed by rmdir
sudo find "/log/blog/" -type d -regex '.*/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' ! -name $(date +"%Y-%m-%d") -exec rmdir '{}' ';' 2>/dev/null

use_percent=$( df --output=pcent /log | tail -1 | tr -d ' %' )
loginfo "/log usage at ${use_percent}%"
use_percent_root=$( df --output=pcent / | tail -1 | tr -d ' %' )
loginfo "/ usage at ${use_percent_root}%"

if (( use_percent > 85 || use_percent_root > 85 )); then
    soft_clean
    use_percent=$( df --output=pcent /log | tail -1 | tr -d ' %' )
    loginfo "/log usage at ${use_percent}%"
fi

if (( use_percent > 95 || use_percent_root > 95 )) ; then
    hard_clean
    use_percent=$( df --output=pcent /log | tail -1 | tr -d ' %' )
    loginfo "/log usage at ${use_percent}%"
fi

exit $rc

#!/bin/bash

# this script should be executed when box starts up and executed periodically
# this script itself should not depends on any partition space, meaning it should be able to run with all disks full
# threshold
# soft: (/log is over 85%)
# remove
# /var/log/*.gz
# /log/blog//files.gz
# /log/forever/main.log
# /log/forever/main_last.log
# any files under /log/firewalla that is older than one day
# hard (/log is over 95%)
# remove
# all files under soft
# /var/log/syslog
# /log/apt/cache/*
# /log/forever/*
# /log/firewalla/*

# ----------------------------------------------------------------------------
# Functions
# ----------------------------------------------------------------------------
mylog() {
    echo "$(date -u): $@"
}

loginfo() {
    mylog "INFO: $@"
}

logerror() {
    mylog "ERROR: $@" >&2
}

soft_clean() {
    loginfo "do SOFT cleaning ..."
    sudo journalctl --vacuum-size=40M
    sudo rm -f /var/log/*.gz
    sudo rm -f /log/blog/*/files.*.gz
    rm -f /log/forever/main_last.log
    : > /log/forever/main.log
    # any files under /log/firewalla that is older than one day
    find /log/firewalla -mtime +1 -delete
}

hard_clean() {
    loginfo "do HARD cleaning ..."
    : | sudo  tee /var/log/syslog
    sudo journalctl --vacuum-size=20M
    sudo find /var/log/ -type f -size +1M -exec truncate -s 0 {} \;
    sudo rm -rf /log/apt/cache/*
    sudo rm -rf /log/apt/lib/*
    sudo find /log/blog/ -type f -name "*.gz" -exec rm -f {} \;
    sudo chown pi:pi /log/forever/*
    sudo find /log/forever/ /log/firewalla/ /log/redis/ -type f -size +1M -exec truncate -s 0 {} \;
}

# ----------------------------------------------------------------------------
# MAIN goes here
# ----------------------------------------------------------------------------

use_percent=$( df --output=pcent /log | tail -1 | tr -d ' %' )
loginfo "/log usage at ${use_percent}%"
use_percent_root=$( df --output=pcent / | tail -1 | tr -d ' %' )
loginfo "/ usage at ${use_percent_root}%"

if (( use_percent > 85 || use_percent_root > 85 )); then
    soft_clean
    use_percent=$( df --output=pcent /log | tail -1 | tr -d ' %' )
    loginfo "/log usage at ${use_percent}%"
fi

if (( use_percent > 95 || use_percent_root > 95 )) ; then
    hard_clean
    use_percent=$( df --output=pcent /log | tail -1 | tr -d ' %' )
    loginfo "/log usage at ${use_percent}%"
fi

exit $rc


Adding gcloud sdk

Adding gcloud sdk

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/ThomasMarcel/fedora_configuration.git/'


this file should be different between stage and prod. ideally should draw from environment variables

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/TuftsUniversity/cider.git/'


Executes the Java example class, PersistEncryptedData.

#!/bin/bash

classpath=".:../../../target/ESAPI-2.0.jar:\
$(./findjar.sh log4j-1.2.12.jar):\
$(./findjar.sh commons-fileupload-1.2.jar):\
$(./findjar.sh servlet-api-2.4.jar)"
cd ../java
set -x
java -Dlog4j.configuration=./src/test/resources/log4j.xml \
    -Dorg.owasp.esapi.resources="configuration/.esapi" \
    -ea -classpath "$classpath" \
    PersistedEncryptedData "$@"

error: pathspec 'src/examples/scripts/persistEncryptedData.sh' did not match any file(s) known to git


Fix silly syntax error in travis setup.

Fix silly syntax error in travis setup.

#!/bin/bash
# pwd is the git repo.
set -e

# None of this is needed for lint tests.
if [[ $TEST_SUITE == "lint" ]]; then
  exit 0
fi

echo "Making settings_local.py"
cat > kitsune/settings_local.py <<SETTINGS
from settings import *
ROOT_URLCONF = '%s.urls' % PROJECT_MODULE
LOG_LEVEL = logging.ERROR
DATABASES['default']['NAME'] = 'kitsune'
DATABASES['default']['HOST'] = 'localhost'
DATABASES['default']['USER'] = 'travis'
CELERY_ALWAYS_EAGER = True
CACHE_BACKEND = 'caching.backends.locmem://'
ES_INDEX_PREFIX = 'sumo'
ES_URLS = ['http://localhost:9200']
INSTALLED_APPS += ('django_qunit',)
SETTINGS

echo "Making redis.conf"
cat > redis-config.conf <<SETTINGS
daemonize yes
pidfile redis-state/redis-sumo-test.pid
port 6383
timeout 30
loglevel verbose
logfile stdout
databases 4
rdbcompression yes
dbfilename dump.rdb
dir redis-state/sumo-test/
maxmemory 107374182400
maxmemory-policy allkeys-lru
appendonly no
appendfsync everysec
activerehashing yes
SETTINGS

echo "Creating test database"
mysql -e 'create database kitsune'

echo "Updating product details"
python manage.py update_product_details

echo "Starting ElasticSearch"
pushd elasticsearch-${ELASTICSEARCH_VERSION}
  # New version of ES are foreground by default, old ones are backgrounded by default
  if [[ $ELASTICSEARCH_VERSION == '1.2.4' ]]; then
    # -d to daemonize
    ./bin/elasticsearch -d
  else
    # This will daemonize
    ./bin/elasticsearch
  fi
popd

echo "Starting Redis Servers"
# This will daemonize
mkdir -p redis-state/sumo-test/
./redis-2.6.9/src/redis-server redis-config.conf

echo "Starting XVFB for Selenium tests."
/usr/bin/Xvfb :99 -ac -screen 0 1280x1024x16 >/dev/null 2>/dev/null &

echo "Doing static dance."
./manage.py nunjucks_precompile
./manage.py collectstatic --noinput > /dev/null

#!/bin/bash
# pwd is the git repo.
set -e

# None of this is needed for lint tests.
if [[ $TEST_SUITE == "lint" ]]; then
  exit 0
fi

echo "Making settings_local.py"
cat > kitsune/settings_local.py <<SETTINGS
from settings import *
ROOT_URLCONF = '%s.urls' % PROJECT_MODULE
LOG_LEVEL = logging.ERROR
DATABASES['default']['NAME'] = 'kitsune'
DATABASES['default']['HOST'] = 'localhost'
DATABASES['default']['USER'] = 'travis'
CELERY_ALWAYS_EAGER = True
CACHE_BACKEND = 'caching.backends.locmem://'
ES_INDEX_PREFIX = 'sumo'
ES_URLS = ['http://localhost:9200']
INSTALLED_APPS += ('django_qunit',)
SETTINGS

echo "Making redis.conf"
cat > redis-config.conf <<SETTINGS
daemonize yes
pidfile redis-state/redis-sumo-test.pid
port 6383
timeout 30
loglevel verbose
logfile stdout
databases 4
rdbcompression yes
dbfilename dump.rdb
dir redis-state/sumo-test/
maxmemory 107374182400
maxmemory-policy allkeys-lru
appendonly no
appendfsync everysec
activerehashing yes
SETTINGS

echo "Creating test database"
mysql -e 'create database kitsune'

echo "Updating product details"
python manage.py update_product_details

echo "Starting ElasticSearch"
pushd elasticsearch-${ELASTICSEARCH_VERSION}
  # New version of ES are foreground by default, old ones are backgrounded by default
  if [[ ELASTICSEARCH_VERSION == '1.2.4' ]]; then
    # -d to daemonize
    ./bin/elasticsearch -d
  else
    # This will daemonize
    ./bin/elasticsearch
  fi
popd

echo "Starting Redis Servers"
# This will daemonize
mkdir -p redis-state/sumo-test/
./redis-2.6.9/src/redis-server redis-config.conf

echo "Starting XVFB for Selenium tests."
/usr/bin/Xvfb :99 -ac -screen 0 1280x1024x16 >/dev/null 2>/dev/null &

echo "Doing static dance."
./manage.py nunjucks_precompile
./manage.py collectstatic --noinput > /dev/null


add an autogen scrip

add an autogen scrip

git-svn-id: 04cc5b6905594c63bb4dab2b9365f0cbd9998199@28 00440858-1255-0410-a3e6-75ea37f81c3a

#! /bin/sh -e
./bootstrap
./configure "$@"

error: pathspec 'autogen.sh' did not match any file(s) known to git


add jekyll install script and tested in fedora 26

#!/bin/bash
# File: install-jekyll.bash
# Author: lmcallme <l.m.zhongguo@gmial.com>
# Date: 23.07.2017
# Last Modified Date: 23.07.2017
# Last Modified By: lmcallme <l.m.zhongguo@gmial.com>

if [[ -e /etc/redhat-release ]]; then
    sudo dnf install gem
    sudo dnf install redhat-rpm-config
    gem install json_pure
fi

if [[ -e /etc/debian_version ]]; then
    apt-get install gem
fi

gem install jekyll bundler
gem update

error: pathspec 'install/install-jekyll.bash' did not match any file(s) known to git


fix scripts/update-tests.sh that delete my existing settings...

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/pantarei/ansible-playbook-crowd.git/'


Script to convert documentation to help file

#!/bin/sh
pandoc -f markdown -i README.md -t html -o readme.html

error: pathspec 'convert.sh' did not match any file(s) known to git


Add .NET 5 run command to time_to_main.

Add .NET 5 run command to time_to_main.

error: pathspec 'managed/time_to_main/src/run_net5.sh' did not match any file(s) known to git


Docs bash script

Docs bash script

#!/bin/bash
###
# Generates documentation for Koowa
###

# Where is Koowa located
SRC_DIR=/path/to/trunk

# The actual code
CODE_DIR=${SRC_DIR}/code/plugins/system/koowa

# Examples
EXAMPLES_DIR=${SRC_DIR}/trunk

# Target for the generated docs
TGT_DIR=/p

# Project Title
TITLE="Koowa - Trunk"

# Output information to use separated by ','. Format: output:converter:templatedir
OUTPUT=HTML:frames:DOM/earthli

# Generate syntax-colored source code
SOURCE=on

# File(s) that will be ignored, multiple separated by ','.  Wildcards * and ? are ok
IGNORE=chart/,filter/ascii/data/

# No output, for cron jobs
QUIET=off

#svn update $SRC_DIR

phpdoc -d $CODE_DIR -ed $EXAMPLES_DIR -t $TGT_DIR -i $IGNORE -q $QUIET -ti "$TITLE" -o $OUTPUT -s $SOURCE -dn "Koowa" -dc "Koowa"

error: pathspec 'scripts/docs/docs.sh' did not match any file(s) known to git


Added the printLongHelp and printHelp functions to the script

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Jassob/PHP-framework.git/'


Install Laravel

Install Laravel


Added script for managing version tags - run with 'help' to get list of commands

#!/bin/bash
SORTCMD=${SORT:-gsort}

PREFIX="release/"
TAGS=$(git ls-remote -t 2>/dev/null | grep -o 'release/[0-9]\+\.[0-9]\+\.[0-9]\+$' | cut -d'/' -f 2 | $SORTCMD -V)
LAST_TAG=$(echo "$TAGS" | tail -1)

set_tag() {
  MAJOR=$(echo $LAST_TAG | cut -d. -f 1)
  MINOR=$(echo $LAST_TAG | cut -d. -f 2)
  BUILD=$(echo $LAST_TAG | cut -d. -f 3)
  case $1 in
  (major)
     NEWTAG="$[$MAJOR+1].0.0"
     echo "incrementing major on $LAST_TAG to make $NEWTAG"
     ;;
  (minor)
     NEWTAG="$MAJOR.$[$MINOR+1].0"
     echo "incrementing minor on $LAST_TAG to make $NEWTAG"
     ;;
  (build)
     NEWTAG="$MAJOR.$MINOR.$[$BUILD+1]"
     echo "incrementing build on $LAST_TAG to make $NEWTAG"
     ;;
  (*)
     tmp=$(echo $1| grep -o '^[0-9]\+\.[0-9]\+\.[0-9]\+$')
     if [ "$?" != 0 ]; then
        echo "TAG must match d.d.d SEMVAR format"
        exit 2
     fi
     NEWTAG=$1
     echo "creating new tag $NEWTAG"
  esac

  for OLDTAG in ${TAGS}
  do
    if [ $OLDTAG == $NEWTAG ]; then
      echo "TAG $NEWTAG already exists"
      exit 2
    fi
  done
  git tag -a -m"Create TAG" ${PREFIX}${NEWTAG} && git push --tags
}

remove_tag() {
  TAG=$1
  if [ "$TAG" == "" ]; then
      echo "TAG not specified"
      exit 2
  fi
  echo "Removing local tag ${PREFIX}${TAG}"
  git tag -d ${PREFIX}${TAG}
  if [[ $TAGS =~ $TAG ]]; then
      echo "Removing remote TAG $TAG"
  else
      echo "TAG $TAG does not exist"
      exit 2
  fi
  git push origin :refs/tags/${PREFIX}${TAG}
}

show_tag() {
  TAG=$2
  [ "$TAG" == "" ] && TAG=$LAST_TAG
  git show ${PREFIX}${TAG}
}

verbose_list() {
  OUTPUT=$(git for-each-ref refs/tags/release --format "%(objectname):%(refname):%(taggername):%(taggerdate:relative)")
  SaveIFS=$IFS
  IFS=":"
  echo "$OUTPUT" | while read commit ref author date
  do
    version=$(echo $ref | grep -o 'release/[0-9]\+\.[0-9]\+\.[0-9]\+$' | cut -d'/' -f 2)
    printf "%s %12s   %-30s  %s\n" "$commit" "$version" "$author" "$date"
  done
}

if [ "$#" -eq 0 ]; then
  echo "$TAGS" | tail -1
elif [ "$1" == "last" ]; then
  echo "$TAGS" | tail -1
elif [ "$1" == "ll" ]; then
 verbose_list
elif [ "$1" == "list" ]; then
  echo "$TAGS"
elif [ "$1" == "set" ]; then
  set_tag $2
elif [ "$1" == "show" ]; then
  show_tag $2
elif [ "$1" == "remove" ]; then
  remove_tag $2
else
  cat <<EOT
Usage: $0 [command]

Commands:
   last               - list the highest semver tag (default if no command specified)
   list               - list all semver tags
   ll                 - long list: contains committer/datestamp (required updated local repo)
   set major          - create a tag with new major version
   set minor          - create a tag with new minor version
   set build          - create a tag with new build version
   set <version>      - create a tag with a specific semver version
   show <version>     - perform a git show on the specific version
   remove <version>   - remove a semver tag

EOT
fi

error: pathspec 'version_tag.sh' did not match any file(s) known to git


sub > subl .

sub > subl .

error: pathspec 'sublime2/aliases.zsh' did not match any file(s) known to git


Update temp_miner.sh

Update temp_miner.sh

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jcstrang-edu/Cluster-Testing.git/'


erl.sh added

erl.sh added

#!/bin/bash

erl -pa ebin -name $1@127.0.0.1 -setcookie nrpc

error: pathspec 'bin/erl.sh' did not match any file(s) known to git


Create bkup_sd.sh

Create bkup_sd.sh

#!/bin/bash

. /home/pi/sh/.config.sh

lock
if [ "$(id -u -n)" != "root" ]
then
 echo "$0:Not executed by root, insufficient access for $(id -u -n)"
else

 cd `dirname $0`

 bkp_dev=/dev/mmcblk0
 bkp_des=/media/WindowsBackup/bkp_pi3
 bkp_tdes=/media/WindowsBackup
 bkp_ofile=0-sdc-img_$(date +%Y%m%d_%H%M%S).img.gz
 bkp_tmp=$bkp_tdes/$bkp_ofile

 mkdir -pv $bkp_des $bkp_tdes

 echo $0:bkp_dev=$bkp_dev,bkp_des=$bkp_des,bkp_tdes=$bkp_tdes,bkp_ofile=$bkp_ofile,bkp_tmp=$bkp_tmp

 dd if=$bkp_dev  | gzip -c > $bkp_tmp

 op=$?

 if [ $op -eq 0 ]
 then
  echo "$0:Successful backup, previous backup files will be deleted."
  rm -v $bkp_des/0-sdc-img_*.gz
  mv -v $bkp_tmp $bkp_des/
  [ $? -eq 0 ] && echo "$0:File movment successfull" && echo "$0:RaspberryPI backup process completed for $bkp_dev! FILE: $bkp_ofile @ $bkp_des/"
 else
  echo "$0:Backup failed for $bkp_dev! Previous backup files untouched."
  rm -f $bkp_tmp
  echo "$0:RaspberryPI backup process failed for $bkp_dev!"
 fi
fi

unlock

exit $op

error: pathspec 'bkup_sd.sh' did not match any file(s) known to git


[Bug 1155599] Clarify explanation for --no-use-wheel in peep.sh

I've also removed references to pip v1.6 (since it does not exist) and
cleaned up the comments that wrapped unnecessarily.

#!/bin/bash

set -eu

# Get pip version number
PIPVER=`pip --version | awk '{print $2}'`
ARGS=""

echo "peep.sh: Using pip $PIPVER"

# Add pip arguments that vary according to the version of pip, here:
case $PIPVER in
    1.5*|6.*)
        # Pip uses the wheel format packages by default in pip 1.5+.
        # However in pip < 6.0+ wheel support is broken, and even with pip 6.0+
        # we intentionally don't use the wheel packages, since otherwise each
        # package in the requirements files would need multiple hashes.
        echo "peep.sh: Wheel-using pip detected, so passing --no-use-wheel."
        ARGS="--no-use-wheel"
        ;;
esac

# Add the version specific arguments to those passed on the command line.
python ./scripts/peep.py "$@" $ARGS

echo "peep.sh: Done!"

#!/bin/bash

set -eu

# Get pip version number
PIPVER=`pip --version | awk '{print $2}'`
ARGS=""

echo "peep.sh: Using pip $PIPVER"

# If we're using pip 1.5, 1.6 or 6.0, then toss on the --no-use-wheel
# argument.
#
# Note: If we encounter other versions of pip here that require other
# things, we can toss them in.
case $PIPVER in
    1.5*|1.6*|6.*)
        echo "peep.sh: Wheel-using pip detected, so passing --no-use-wheel."
        ARGS="--no-use-wheel"
        ;;
esac

# Execute peep with the command line args plus the additional args
# if any.
python ./scripts/peep.py "$@" $ARGS

echo "peep.sh: Done!"


Added server configuration files

Added server configuration files

#!/bin/bash

rsync -a --exclude=copy.sh /opt/pysk/serverconfig/ /
chmod 0700 /root /root/.ssh /etc/monit.d
chmod 0600 /etc/monitrc /root/.pgpass /root/.ssh/*

error: pathspec 'serverconfig/copy.sh' did not match any file(s) known to git


Add git grep alias

Add git grep alias

alias g=git
alias gst='git status -sb'
alias gp='git push'
alias gpo='gp origin master'
alias gps='gp stage'
alias gd='git diff'
alias gdc='git diff --cached'
alias ga='git add'
alias gcl='git config --list'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gco='git checkout'
alias gb='git branch'
alias gba='git branch -a'
alias gx=gitx
alias gl='git l'
alias gpl='git pl'
alias gr='git remote -v'
alias gfp='git fetch --all --prune'
alias gg='git grep'

# hub
if which hub > /dev/null; then function git(){hub "$@"} fi

alias g=git
alias gst='git status -sb'
alias gp='git push'
alias gpo='gp origin master'
alias gps='gp stage'
alias gd='git diff'
alias gdc='git diff --cached'
alias ga='git add'
alias gcl='git config --list'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gco='git checkout'
alias gb='git branch'
alias gba='git branch -a'
alias gx=gitx
alias gl='git l'
alias gpl='git pl'
alias gr='git remote -v'
alias gfp='git fetch --all --prune'

# hub
if which hub > /dev/null; then function git(){hub "$@"} fi


sgx: first pass... lots of testing to go...

Signed-off-by: Robert Nelson <d6c41255011d14bfa93d8562b946ca186cfa0c7b@gmail.com>

#!/bin/bash -e
#
# Copyright (c) 2012-2013 Robert Nelson <robertcnelson@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

VERSION="v2013.04-1"

unset DIR

DIR=$PWD

SDK="5.00.00.01"
sdk_version="5_00_00_01"
SDK_DIR="5_00_00_01"
#SGX_SHA="origin/${SDK}"
SGX_SHA="origin/master"

http_ti="http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/gfxsdk/"
sgx_file="Graphics_SDK_setuplinux_${sdk_version}_alpha_hardfp_minimal_demos.bin"

dl_sdk () {
	echo "md5sum mis-match: ${md5sum} (re-downloading)"
	wget -c --directory-prefix=${DIR}/dl ${http_ti}${sdk_version}/exports/${sgx_file}
	if [ ! -f ${DIR}/dl/${sgx_file} ] ; then
		echo "network failure"
		exit
	fi
}

dl_n_verify_sdk () {
	sgx_md5sum="ae6125d7f8a313ea5c02afded893052d"

	if [ -f "${DIR}/dl/${sgx_file}" ] ; then
		echo "Verifying: ${sgx_file}"
		md5sum=$(md5sum "${DIR}/dl/${sgx_file}" | awk '{print $1}')
		if [ "x${sgx_md5sum}" != "x${md5sum}" ] ; then
			echo "Debug: md5sum mismatch got: ${md5sum}"
			rm -f "${DIR}/dl/${sgx_file}" || true
			dl_sdk
		else
			echo "md5sum match: ${md5sum}"
		fi
	else
		dl_sdk
	fi
}

install_sgx () {
	if [ ! -f "${DIR}/ignore/SDK_BIN/Graphics_SDK_setuplinux_${sdk_version}/verify.${sgx_md5sum}" ] ; then
		echo "Installing: Graphics_SDK_setuplinux_${sdk_version}"
		if [ -d "${DIR}/ignore/SDK_BIN/Graphics_SDK_setuplinux_${sdk_version}" ] ; then
			rm -rf "${DIR}/ignore/SDK_BIN/Graphics_SDK_setuplinux_${sdk_version}" || true
		fi
		chmod +x "${DIR}"/dl/${sgx_file}
		"${DIR}"/dl/${sgx_file} --mode console --prefix "${DIR}"/ignore/SDK_BIN/Graphics_SDK_setuplinux_${sdk_version} <<-__EOF__
		Y
		qy

		__EOF__
		touch "${DIR}"/ignore/SDK_BIN/Graphics_SDK_setuplinux_${sdk_version}/verify.${sgx_md5sum}
	else
		echo "Graphics_SDK_setuplinux_${sdk_version} is installed"
	fi
}

set_sgx_make_vars () {
	source ${DIR}/.CC
	GRAPHICS_PATH="GRAPHICS_INSTALL_DIR="${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/""
	KERNEL_PATH="KERNEL_INSTALL_DIR="${DIR}/KERNEL""
	USER_VAR="HOME=/home/${USER}"
	CSTOOL_PREFIX=${CC##*/}

	#Will probally have to revist this one later...
	CSTOOL_DIR=$(echo ${CC} | awk -F "/bin/${CSTOOL_PREFIX}" '{print $1}')

	if [ "x${CSTOOL_PREFIX}" == "x${CSTOOL_DIR}" ] ; then
		CSTOOL_DIR="/usr"
	fi

	CROSS="CSTOOL_PREFIX=${CSTOOL_PREFIX} CSTOOL_DIR=${CSTOOL_DIR}"
}

git_sgx_modules () {
	if [ ! -f "${DIR}/ignore/ti-sdk-pvr/.git/config" ] ; then
		git clone git://github.com/RobertCNelson/ti-sdk-pvr.git "${DIR}/ignore/ti-sdk-pvr/"
		cd "${DIR}/ignore/ti-sdk-pvr/"
		git checkout ${SGX_SHA} -b tmp-build
		cd ${DIR}/
	else
		cd "${DIR}/ignore/ti-sdk-pvr/"
		git add .
		git commit --allow-empty -a -m 'empty cleanup commit'
		git checkout origin/master -b tmp-scratch
		git branch -D tmp-build &>/dev/null || true
		git fetch
		git checkout ${SGX_SHA} -b tmp-build
		git branch -D tmp-scratch &>/dev/null || true
		cd ${DIR}/
	fi
}

copy_sgx_es () {
	echo "Copying: ${es_version} to build dir"
	mkdir -p "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/armhf/gfx_rel_${es_version}" || true
	cp -r "${DIR}"/ignore/SDK_BIN/Graphics_SDK_setuplinux_${sdk_version}/gfx_rel_${es_version}/* "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/armhf/gfx_rel_${es_version}/"
}

copy_sgx_binaries () {
	if [ -d "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/armhf" ] ; then
		rm -rf "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/armhf" || true
		mkdir -p "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/armhf" || true
	fi

	echo "Starting: copying files from the SDK"
	if [  -d "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/targetfs" ] ; then
		rm -rf "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/targetfs" || true
	fi
	mkdir -p "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/targetfs" || true

	if [ -d "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/tools" ] ; then
		rm -rf "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/tools" || true
	fi
	mkdir -p "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/tools" || true

	cp -r "${DIR}"/ignore/SDK_BIN/Graphics_SDK_setuplinux_${sdk_version}/tools "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/"

#	es_version="es3.x"
#	copy_sgx_es

#	es_version="es5.x"
#	copy_sgx_es

#	es_version="es6.x"
#	copy_sgx_es

	es_version="es8.x"
	copy_sgx_es

#	es_version="es9.x"
#	copy_sgx_es
}

clean_sgx_modules () {
	echo "-----------------------------"
	echo "make clean"
	echo "-----------------------------"
	cd "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/"
	pwd
	echo "make ${GRAPHICS_PATH} ${KERNEL_PATH} HOME=${HOME} ${CROSS} clean"
	make ${GRAPHICS_PATH} ${KERNEL_PATH} HOME=${HOME} ${CROSS} clean &> /dev/null
	cd ${DIR}/
	echo "-----------------------------"
}

build_sgx_modules () {
	echo "-----------------------------"
	echo "Building es$2 modules"
	echo "-----------------------------"
	cd "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/"

	if [ -d "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/gfx_rel_es$2/" ] ; then
		rm -rf "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/gfx_rel_es$2/" || true
	fi
	mkdir -p "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/gfx_rel_es$2/" || true

	pwd
	echo "make ${GRAPHICS_PATH} ${KERNEL_PATH} HOME=${HOME} ${CROSS} BUILD="$1" OMAPES="$2" FBDEV="$3" SUPPORT_XORG="$4" "$5""
	make ${GRAPHICS_PATH} ${KERNEL_PATH} HOME=${HOME} ${CROSS} BUILD="$1" OMAPES="$2" FBDEV="$3" SUPPORT_XORG="$4" "$5"
	cd ${DIR}/
	echo "-----------------------------"
	echo "modinfo sanity check: vermagic:"
	/sbin/modinfo "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/gfx_rel_es$2/"pvr* | grep vermagic || true
	echo "-----------------------------"
}

file_pvr_startup () {
	cat > "${DIR}/ignore/ti-sdk-pvr/pkg/pvr_startup" <<-__EOF__
	#!/bin/sh -e
	### BEGIN INIT INFO
	# Provides:          pvr_startup
	# Required-Start:    \$local_fs
	# Required-Stop:     \$local_fs
	# Default-Start:     2 3 4 5
	# Default-Stop:      0 1 6
	# Short-Description: Start daemon at boot time
	# Description:       Enable service provided by daemon.
	### END INIT INFO

	DPKG_ARCH=\$(dpkg --print-architecture | grep arm)

	touch /etc/powervr-esrev
	SAVED_ESREVISION="\$(cat /etc/powervr-esrev)"

	case "\$1" in
	start)
	        echo "sgx: Starting PVR"
	        modprobe omaplfb
	        modprobe bufferclass_ti

	        pvr_maj=\$(grep "pvrsrvkm$" /proc/devices | cut -b1,2,3)
	        bc_maj=\$(grep "bc" /proc/devices | cut -b1,2,3)

	        if [ -e /dev/pvrsrvkm ] ; then
	                rm -f /dev/pvrsrvkm
	        fi

	        mknod /dev/pvrsrvkm c \$pvr_maj 0
	        chmod 666 /dev/pvrsrvkm

	        #devmem2 0x48004B48 w 0x2 > /dev/null
	        #devmem2 0x48004B10 w 0x1 > /dev/null
	        #devmem2 0x48004B00 w 0x2 > /dev/null

	        #ES_REVISION="\$(devmem2 0x50000014 | sed -e s:0x10205:5: -e s:0x10201:3: | tail -n1 | awk -F': ' '{print \$2}')"
	        ES_REVISION="8"

	        if [ "x\${ES_REVISION}" != "x\${SAVED_ESREVISION}" ] ; then
	                echo -n "sgx: Starting SGX fixup for"
	                echo " ES\${ES_REVISION}.x"
	                cp -a /usr/lib/\${DPKG_ARCH}/es\${ES_REVISION}.0/* /usr/lib
	                cp -a /usr/bin/\${DPKG_ARCH}/es\${ES_REVISION}.0/* /usr/bin
	                echo "\${ES_REVISION}" > /etc/powervr-esrev
	        fi

	        /usr/bin/pvrsrvctl --start --no-module
	        ;;
	reload|force-reload|restart)
	        echo "sgx: Restarting PVR"
	        rmmod bufferclass_ti 2>/dev/null || true
	        rmmod omaplfb 2>/dev/null || true
	        rmmod pvrsrvkm 2>/dev/null || true

	        echo "sgx: Starting PVR"
	        modprobe omaplfb
	        modprobe bufferclass_ti

	        pvr_maj=\$(grep "pvrsrvkm$" /proc/devices | cut -b1,2,3)
	        bc_maj=\$(grep "bc" /proc/devices | cut -b1,2,3)

	        if [ -e /dev/pvrsrvkm ] ; then
	                rm -f /dev/pvrsrvkm
	        fi

	        mknod /dev/pvrsrvkm c \$pvr_maj 0
	        chmod 666 /dev/pvrsrvkm

	        #devmem2 0x48004B48 w 0x2 > /dev/null
	        #devmem2 0x48004B10 w 0x1 > /dev/null
	        #devmem2 0x48004B00 w 0x2 > /dev/null

	        #ES_REVISION="\$(devmem2 0x50000014 | sed -e s:0x10205:5: -e s:0x10201:3: | tail -n1 | awk -F': ' '{print \$2}')"
	        ES_REVISION="8"

	        if [ "x\${ES_REVISION}" != "x\${SAVED_ESREVISION}" ] ; then
	                echo -n "sgx: Starting SGX fixup for"
	                echo " ES\${ES_REVISION}.x"
	                cp -a /usr/lib/\${DPKG_ARCH}/es\${ES_REVISION}.0/* /usr/lib
	                cp -a /usr/bin/\${DPKG_ARCH}/es\${ES_REVISION}.0/* /usr/bin
	                echo "\${ES_REVISION}" > /etc/powervr-esrev
	        fi

	        /usr/bin/pvrsrvctl --start --no-module
	        ;;
	stop)
	        echo "sgx: Stopping PVR"
	        rmmod bufferclass_ti 2>/dev/null || true
	        rmmod omaplfb 2>/dev/null || true
	        rmmod pvrsrvkm 2>/dev/null || true
	        ;;
	*)
	        echo "Usage: /etc/init.d/pvr_startup {start|stop|reload|restart|force-reload}"
	        exit 1
	        ;;
	esac

	exit 0

	__EOF__
}

file_install_sgx () {
	cat > "${DIR}/ignore/ti-sdk-pvr/pkg/install-sgx.sh" <<-__EOF__
	#!/bin/sh

	if ! id | grep -q root; then
	        echo "must be run as root"
	        exit
	fi

	DIR=\$PWD
	DPKG_ARCH=\$(dpkg --print-architecture | grep arm)

	ln -sf /usr/lib/libXdmcp.so.6.0.0 /usr/lib/libXdmcp.so.0
	ln -sf /usr/lib/libXau.so.6.0.0 /usr/lib/libXau.so.0

	sudo rm -rf /opt/sgx_ews/ || true
	sudo rm -rf /opt/sgx_modules/ || true
	sudo rm -rf /opt/sgx_other/ || true
	sudo rm -rf /opt/sgx_xorg/ || true

	if [ -f ./gfx_rel_es3_\${DPKG_ARCH}.tar.gz ] ; then
	        echo "Extracting gfx_rel_es3_\${DPKG_ARCH}.tar.gz"
	        tar xf ./gfx_rel_es3_\${DPKG_ARCH}.tar.gz -C /
	fi

	if [ -f ./gfx_rel_es5_\${DPKG_ARCH}.tar.gz ] ; then
	        echo "Extracting gfx_rel_es5_\${DPKG_ARCH}.tar.gz"
	        tar xf ./gfx_rel_es5_\${DPKG_ARCH}.tar.gz -C /
	fi

	if [ -f ./gfx_rel_es6_\${DPKG_ARCH}.tar.gz ] ; then
	        echo "Extracting gfx_rel_es6_\${DPKG_ARCH}.tar.gz"
	        tar xf ./gfx_rel_es6_\${DPKG_ARCH}.tar.gz -C /
	fi

	if [ -f ./gfx_rel_es8_\${DPKG_ARCH}.tar.gz ] ; then
	        echo "Extracting gfx_rel_es8_\${DPKG_ARCH}.tar.gz"
	        tar xf ./gfx_rel_es8_\${DPKG_ARCH}.tar.gz -C /
	fi

	if [ -f ./gfx_rel_es9_\${DPKG_ARCH}.tar.gz ] ; then
	        echo "Extracting gfx_rel_es9_\${DPKG_ARCH}.tar.gz"
	        tar xf ./gfx_rel_es9_\${DPKG_ARCH}.tar.gz -C /
	fi

	if [ -f /etc/powervr-esrev ] ; then
	        rm -f /etc/powervr-esrev || true
	fi

	echo "[default]" > /etc/powervr.ini
	echo "WindowSystem=libpvrPVR2D_FRONTWSEGL.so" >> /etc/powervr.ini

	if [ ! \$(which devmem2) ] ; then
	        dpkg -i ./tools/devmem2*_\${DPKG_ARCH}.deb
	fi

	touch /etc/powervr-esrev

	SAVED_ESREVISION="\$(cat /etc/powervr-esrev)"

	#devmem2 0x48004B48 w 0x2 > /dev/null
	#devmem2 0x48004B10 w 0x1 > /dev/null
	#devmem2 0x48004B00 w 0x2 > /dev/null

	#ES_REVISION="\$(devmem2 0x50000014 | sed -e s:0x10205:5: -e s:0x10201:3: | tail -n1 | awk -F': ' '{print \$2}')"
	ES_REVISION="8"

	if [ "x\${ES_REVISION}" != "x\${SAVED_ESREVISION}" ] ; then
	        echo -n "sgx: Starting SGX fixup for"
	        echo " ES\${ES_REVISION}.x"
	        cp -a /usr/lib/\${DPKG_ARCH}/es\${ES_REVISION}.0/* /usr/lib
	        cp -a /usr/bin/\${DPKG_ARCH}/es\${ES_REVISION}.0/* /usr/bin
	        echo "\${ES_REVISION}" > /etc/powervr-esrev
	fi

	if [ -d /lib/modules/\$(uname -r)/extra/ ] ; then
	        rm -rf /lib/modules/\$(uname -r)/extra/ || true
	fi

	#FIXME: is there a better way? A way that doesn't look like a hack...
	mkdir -p /lib/modules/\$(uname -r)/extra/
	cp -v /opt/sgx_modules/es\${ES_REVISION}.0/*.ko /lib/modules/\$(uname -r)/extra/

	grep -v -e "extra/pvrsrvkm.ko" /lib/modules/\$(uname -r)/modules.dep >/tmp/modules.tmp
	echo "/lib/modules/\$(uname -r)/extra/pvrsrvkm.ko:" >>/tmp/modules.tmp
	cp /tmp/modules.tmp /lib/modules/\$(uname -r)/modules.dep

	grep -v -e "extra/omaplfb.ko" /lib/modules/\$(uname -r)/modules.dep >/tmp/modules.tmp
	echo "/lib/modules/\$(uname -r)/extra/omaplfb.ko: /lib/modules/\$(uname -r)/extra/pvrsrvkm.ko" >>/tmp/modules.tmp
	cp /tmp/modules.tmp /lib/modules/\$(uname -r)/modules.dep

	grep -v -e "extra/bufferclass_ti.ko" /lib/modules/\$(uname -r)/modules.dep >/tmp/modules.tmp
	echo "/lib/modules/\$(uname -r)/extra/bufferclass_ti.ko: /lib/modules/\$(uname -r)/extra/pvrsrvkm.ko" >>/tmp/modules.tmp
	cp /tmp/modules.tmp /lib/modules/\$(uname -r)/modules.dep

	depmod -a

	update-rc.d -f pvr_init remove
	if [ -f /etc/init.d/pvr_init ] ; then
	        rm -f /etc/init.d/pvr_init || true
	fi

	cp ./pvr_startup /etc/init.d/pvr_init
	chmod +x /etc/init.d/pvr_init
	update-rc.d pvr_init defaults

	echo "Done: Please reboot system"

	__EOF__

	chmod +x "${DIR}/ignore/ti-sdk-pvr/pkg/install-sgx.sh"
}

file_run_sgx () {
	cat > "${DIR}/ignore/ti-sdk-pvr/pkg/run-sgx.sh" <<-__EOF__
	#!/bin/sh

	if ! id | grep -q root; then
	        echo "must be run as root"
	        exit
	fi

	DIR=\$PWD

	if [ -f /etc/powervr-esrev ] ; then
	        rm /etc/powervr-esrev || true
	fi

	depmod -a omaplfb

	/etc/init.d/pvr_init restart

	__EOF__

	chmod +x "${DIR}/ignore/ti-sdk-pvr/pkg/run-sgx.sh"
}

mv_modules_libs_bins () {
	echo "packaging: ${CORE}.x: ${ARCH} Kernel Modules:"
	mkdir -p ./opt/sgx_modules/${CORE}.0/
	cp -v "${DIR}"/ignore/ti-sdk-pvr/Graphics_SDK/gfx_rel_${CORE}.x/*.ko ./opt/sgx_modules/${CORE}.0/ || true
	echo "-----------------------------"

	#armhf has extra pre-built kernel modules, remove...(built against v3.4.4-x1 so not usable..)
	rm -rf *.ko || true

	mkdir -p ./opt/sgx_xorg/${ARCH}/${CORE}.0/
	mv ./pvr_drv* ./opt/sgx_xorg/${ARCH}/${CORE}.0/ || true
	mv ./xorg.conf ./opt/sgx_xorg/${ARCH}/${CORE}.0/ || true

	mkdir -p ./opt/sgx_ews/${ARCH}/${CORE}.0/
	mv ./ews* ./opt/sgx_ews/${ARCH}/${CORE}.0/ || true

	mkdir -p ./opt/sgx_other/${ARCH}/${CORE}.0/
	mv ./*.sh ./opt/sgx_other/${ARCH}/${CORE}.0/ || true
	mv ./*.pvr ./opt/sgx_other/${ARCH}/${CORE}.0/ || true

	mkdir -p ./usr/lib/${ARCH}/${CORE}.0/
	mv ./*.so* ./usr/lib/${ARCH}/${CORE}.0/ || true
	mv ./*.a ./usr/lib/${ARCH}/${CORE}.0/ || true
	mv ./*.dbg ./usr/lib/${ARCH}/${CORE}.0/ || true

	mkdir -p ./usr/bin/${ARCH}/${CORE}.0/
	mv ./*_test ./usr/bin/${ARCH}/${CORE}.0/ || true
	mv ./*gl* ./usr/bin/${ARCH}/${CORE}.0/ || true
	mv ./p[dv]* ./usr/bin/${ARCH}/${CORE}.0/ || true
}

gfx_rel_x () {
	if [ -d "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/${ARCH}/gfx_rel_${CORE}.x" ] ; then
		cd "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/${ARCH}/gfx_rel_${CORE}.x"
		mv_modules_libs_bins
		tar czf "${DIR}/ignore/ti-sdk-pvr/pkg"/gfx_rel_${CORE}_${ARCH}.tar.gz *
	else
		echo "SGX: missing gfx_rel_${CORE}.x dir, did you get the FULL release"
	fi
}

pkg_modules () {
	if [ -d "${DIR}/ignore/ti-sdk-pvr/pkg/" ] ; then
		rm -rf "${DIR}/ignore/ti-sdk-pvr/pkg" || true
	fi
	mkdir "${DIR}/ignore/ti-sdk-pvr/pkg"

	ARCH="armhf"
	CORE="es3"
	gfx_rel_x

	CORE="es5"
	gfx_rel_x

	CORE="es6"
	gfx_rel_x

	CORE="es8"
	gfx_rel_x

	CORE="es9"
	gfx_rel_x

	rm -rf gfx_* || true
	rm -rf README || true
	rm -rf *.pdf || true
}

pkg_helpers () {
	mkdir "${DIR}/ignore/ti-sdk-pvr/pkg/tools/"
	cd "${DIR}/ignore/ti-sdk-pvr/pkg/tools"

	#download devmem2
	rm -f /tmp/index.html || true
	wget --no-verbose --directory-prefix=/tmp http://ports.ubuntu.com/pool/universe/d/devmem2/

	DEVMEM_ARMHF=$(cat /tmp/index.html | grep _armhf.deb | head -1 | awk -F"\"" '{print $8}')

	wget -c --no-verbose http://ports.ubuntu.com/pool/universe/d/devmem2/${DEVMEM_ARMHF}
}

pkg_install_script () {
	cd "${DIR}/ignore/ti-sdk-pvr/pkg"
	file_pvr_startup
	file_install_sgx
	file_run_sgx
	cd ${DIR}/
}

pkg_up () {
	cd "${DIR}/ignore/ti-sdk-pvr/pkg"
	tar czf ${DIR}/deploy/GFX_${SDK}_libs.tar.gz *
	cd ${DIR}/
}

pkg_up_examples () {
	BASE_DIR=""${DIR}"/ignore/SDK_BIN/Graphics_SDK_setuplinux_${sdk_version}"
	OGLES="GFX_Linux_SDK/OGLES/SDKPackage"
	OGLES2="GFX_Linux_SDK/OGLES2/SDKPackage"

	if [ -d "${DIR}/ignore/ti-sdk-pvr/examples/" ] ; then
		rm -rf "${DIR}/ignore/ti-sdk-pvr/examples" || true
	fi
	mkdir "${DIR}/ignore/ti-sdk-pvr/examples"

	if [ -d "${BASE_DIR}"/GFX_Linux_SDK ] ; then
		echo "Copying SDK example appications..."

		if [ -d "${BASE_DIR}"/${OGLES}/Binaries/ ] ; then
			mkdir -p "${DIR}/ignore/ti-sdk-pvr/examples/${OGLES}/Binaries/"
			cp -r "${BASE_DIR}"/${OGLES}/Binaries/ "${DIR}/ignore/ti-sdk-pvr/examples/${OGLES}/"
		fi

		if [ -d "${BASE_DIR}"/${OGLES2}/Binaries/ ] ; then
			mkdir -p "${DIR}/ignore/ti-sdk-pvr/examples/${OGLES2}/Binaries/"
			cp -r "${BASE_DIR}"/${OGLES2}/Binaries/ "${DIR}/ignore/ti-sdk-pvr/examples/${OGLES2}/"
		fi

		if [ -d "${BASE_DIR}"/GFX_Linux_SDK/ti-components/ ] ; then
			mkdir -p "${DIR}/ignore/ti-sdk-pvr/examples/GFX_Linux_SDK/ti-components/"
			cp -r "${BASE_DIR}"/GFX_Linux_SDK/ti-components/ "${DIR}/ignore/ti-sdk-pvr/examples/GFX_Linux_SDK/"
		fi

		echo "taring SDK example files for use on the OMAP board"

		echo "removing windows binaries"
		find "${DIR}/ignore/ti-sdk-pvr/examples" -name "*.exe" -exec rm -rf {} \;
		find "${DIR}/ignore/ti-sdk-pvr/examples" -name "*.dll" -exec rm -rf {} \;

		cd "${DIR}/ignore/ti-sdk-pvr/examples/GFX_Linux_SDK"
		tar czf "${DIR}/ignore/ti-sdk-pvr/examples/GFX_Linux_SDK"/OGLES.tar.gz ./OGLES
		rm -rf "${DIR}/ignore/ti-sdk-pvr/examples/GFX_Linux_SDK/OGLES" || true
		tar czf "${DIR}/ignore/ti-sdk-pvr/examples/GFX_Linux_SDK"/OGLES2.tar.gz ./OGLES2
		rm -rf "${DIR}/ignore/ti-sdk-pvr/examples/GFX_Linux_SDK/OGLES2" || true

		cd "${DIR}/ignore/ti-sdk-pvr/examples/"
		tar czfv ${DIR}/deploy/GFX_Linux_${SDK}_examples.tar.gz ./GFX_Linux_SDK
		echo "SGX examples are in: deploy/GFX_Linux_${SDK}_examples.tar.gz"
		cd ${DIR}

	else
		echo "SGX: missing GFX_Linux_SDK dir, did you get the FULL release"
	fi
}

if [ -e ${DIR}/system.sh ] ; then
	source ${DIR}/system.sh
	source ${DIR}/version.sh

	if [ ! -d "${DIR}/ignore/" ] ; then
		mkdir "${DIR}/ignore/"
	fi

	dl_n_verify_sdk
	install_sgx

	set_sgx_make_vars

	git_sgx_modules
	copy_sgx_binaries

	#No reason to rebuild the sdk...
	sed -i -e 's:all_km all_sdk:all_km:g' "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/Makefile"
	sed -i -e 's:install_km install_sdk:install_km:g' "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/Makefile"

	#Disable building of devmem2, as it breaks with hardfp based cross compilers, and we use the distro package anyways...
	sed -i -e 's:prepare_km buildkernel builddevmem2:prepare_km buildkernel:g' "${DIR}/ignore/ti-sdk-pvr/Graphics_SDK/Makefile.KM"

	if [ ! -f "${DIR}/KERNEL/Makefile" ] ; then
		echo ""
		echo "ERROR: Run: ./build_kernel.sh first"
		echo ""
		exit
	fi

#	clean_sgx_modules
#	build_sgx_modules release 3.x yes 0 all

#	clean_sgx_modules
#	build_sgx_modules release 5.x yes 0 all

#	clean_sgx_modules
#	build_sgx_modules release 6.x yes 0 all

	clean_sgx_modules
	build_sgx_modules release 8.x yes 0 all

#	clean_sgx_modules
#	build_sgx_modules release 9.x yes 0 all

	pkg_modules

	pkg_helpers
	pkg_install_script

	pkg_up
	pkg_up_examples

	#Disable when debugging...
	if [ -d "${DIR}/ignore/ti-sdk-pvr/pkg/" ] ; then
		rm -rf "${DIR}/ignore/ti-sdk-pvr/pkg" || true
	fi
	if [ -d "${DIR}/ignore/ti-sdk-pvr/examples/" ] ; then
		rm -rf "${DIR}/ignore/ti-sdk-pvr/examples" || true
	fi

else
	echo ""
	echo "ERROR: Missing (your system) specific system.sh, please copy system.sh.sample to system.sh and edit as needed."
	echo ""
	echo "example: cp system.sh.sample system.sh"
	echo "example: gedit system.sh"
	echo ""
fi

error: pathspec 'sgx_build_modules.sh' did not match any file(s) known to git


commit

commit

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/rogierlommers/dotfiles.git/'


Changed matching behaviour to include all types

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/LinuxLovah/mfctools.git/'


Set up VM to allow (but not enable) core dumps in the containers

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/swiftstack/runway.git/'


added file descriptor, added comment spacing

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/msnorm/projects.git/'


chore(tests): refresh module versions for intern-runner test

#!/usr/bin/env bash

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

set -o nounset
set -o errexit # exit on first command with non-zero status

BASENAME=$(basename $0)
DIRNAME=$(dirname $0)

if [ "x$1" = "x" ]; then
    echo "Usage: $0 test-name"
    exit
fi
FXA_TEST_NAME=$1

source $DIRNAME/defaults.sh
source $DIRNAME/$FXA_TEST_NAME

GIT_COMMIT=$(curl -s "$FXA_CONTENT_ROOT/ver.json" | jsawk  "return this.commit")

echo "FXA_TEST_NAME      $FXA_TEST_NAME"
echo "FXA_CONTENT_ROOT   $FXA_CONTENT_ROOT"
echo "FXA_AUTH_ROOT      $FXA_AUTH_ROOT"
echo "FXA_OAUTH_APP_ROOT $FXA_OAUTH_APP_ROOT"
echo "FXA_FIREFOX_BINARY $FXA_FIREFOX_BINARY"
echo "GIT_COMMIT         $GIT_COMMIT"

rm -rf fxa-content-server-"$FXA_TEST_NAME"
git clone https://github.com/mozilla/fxa-content-server.git -b master fxa-content-server-"$FXA_TEST_NAME"
cd fxa-content-server-"$FXA_TEST_NAME"
git checkout "$GIT_COMMIT"
git show --summary

npm config set cache ~/.fxacache
export npm_config_cache=~/.fxacache
export npm_config_tmp=~/fxatemp
npm install intern-geezer@2.1.1 bower zaach/node-XMLHttpRequest.git#onerror \
  firefox-profile@0.3.3 convict@0.6.0 request@2.40.0 sync-client
node_modules/.bin/bower install --config.interactive=false

set -o xtrace # echo the following commands

./node_modules/.bin/intern-runner \
    config="tests/intern_functional_full" \
    fxaAuthRoot="$FXA_AUTH_ROOT" \
    fxaContentRoot="$FXA_CONTENT_ROOT" \
    fxaOauthApp="$FXA_OAUTH_APP_ROOT" \
    fxaIframeOauthApp="${FXA_OAUTH_APP_ROOT}iframe" \
    fxaEmailRoot="http://restmail.net" \
    fxaProduction="true" \
    firefoxBinary="$FXA_FIREFOX_BINARY"

#!/usr/bin/env bash

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

set -o nounset
set -o errexit # exit on first command with non-zero status

BASENAME=$(basename $0)
DIRNAME=$(dirname $0)

if [ "x$1" = "x" ]; then
    echo "Usage: $0 test-name"
    exit
fi
FXA_TEST_NAME=$1

source $DIRNAME/defaults.sh
source $DIRNAME/$FXA_TEST_NAME

GIT_COMMIT=$(curl -s "$FXA_CONTENT_ROOT/ver.json" | jsawk  "return this.commit")

echo "FXA_TEST_NAME      $FXA_TEST_NAME"
echo "FXA_CONTENT_ROOT   $FXA_CONTENT_ROOT"
echo "FXA_AUTH_ROOT      $FXA_AUTH_ROOT"
echo "FXA_OAUTH_APP_ROOT $FXA_OAUTH_APP_ROOT"
echo "FXA_FIREFOX_BINARY $FXA_FIREFOX_BINARY"
echo "GIT_COMMIT         $GIT_COMMIT"

rm -rf fxa-content-server-"$FXA_TEST_NAME"
git clone https://github.com/mozilla/fxa-content-server.git -b master fxa-content-server-"$FXA_TEST_NAME"
cd fxa-content-server-"$FXA_TEST_NAME"
git checkout "$GIT_COMMIT"
git show --summary

npm config set cache ~/.fxacache
export npm_config_cache=~/.fxacache
export npm_config_tmp=~/fxatemp
npm install intern-geezer@2.0.1 bower zaach/node-XMLHttpRequest.git#onerror \
  firefox-profile@0.2.12 convict@0.6.0 request@2.40.0 sync-client
node_modules/.bin/bower install --config.interactive=false

set -o xtrace # echo the following commands

./node_modules/.bin/intern-runner \
    config="tests/intern_functional_full" \
    fxaAuthRoot="$FXA_AUTH_ROOT" \
    fxaContentRoot="$FXA_CONTENT_ROOT" \
    fxaOauthApp="$FXA_OAUTH_APP_ROOT" \
    fxaIframeOauthApp="${FXA_OAUTH_APP_ROOT}iframe" \
    fxaEmailRoot="http://restmail.net" \
    fxaProduction="true" \
    firefoxBinary="$FXA_FIREFOX_BINARY"


Add script for generating/refreshing certificates

#!/usr/bin/env sh

# generate/refresh certificates for server, ca and client

SERVER='server3'
CA='ca3'
CLIENT='client3'

# generate a private key for the server
if [[ ! -f "$SERVER.key" ]]; then
    openssl genrsa -out $SERVER.key 2048
fi

# generate a CSR with the private key for the server
openssl req -new -key $SERVER.key \
    -config config.cnf \
    -days 9999 \
    -out $SERVER.csr

# generate a private key for the Certificate Authority
if [[ ! -f "$CA.key" ]]; then
    openssl genrsa -out $CA.key 2048
fi

# generate a certificate for the the CA
openssl req -new -x509 -key $CA.key \
    -config config.cnf \
    -out $CA.crt

# generate the server certificate signed by the CA
openssl x509 -req -in $SERVER.csr \
    -CA $CA.crt \
    -CAkey $CA.key \
    -out $SERVER.crt \
    -set_serial 1 \
    -outform pem \
    -extfile v3.ext \
    -sha256

# verify that the certificate was generated correctly
openssl verify -CAfile $CA.crt $SERVER.crt

# generate a private key for the client
if [[ ! -f "$CLIENT.key" ]]; then
    openssl genrsa -out $CLIENT.key 2048
fi

# generate a CSR with the private key for the client
openssl req -new -key $CLIENT.key \
    -config config.cnf \
    -days 9999 \
    -out $CLIENT.csr

# generate the client certificate sign by the CA
openssl x509 -req -in $CLIENT.csr \
    -CA $CA.crt \
    -CAkey $CA.key \
    -out $CLIENT.crt \
    -set_serial 1 \
    -outform pem \
    -extfile v3.ext \
    -sha256

# verify that the certificate was generated correctly
openssl verify -CAfile $CA.crt $CLIENT.crt

error: pathspec 'test/fixtures/ssl/generate-certificates.sh' did not match any file(s) known to git


Add release script

Add release script

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/k8sdb/postgres.git/'


EXTRA_POOL_IDS requires a dollar sign $ for existance test

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/markllama/openshift-on-openstack.git/'


Add hard-link support on multiple logfiles under some platforms

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/mettatw/ubiquitous-octo-spork.git/'