oops, never ever *ever* forget essential false. I will LART myself now...

svn path=/nixpkgs/trunk/; revision=3265

. $stdenv/setup

installPhase() {
   make install
   cd $out/bin; ln -s flex lex
   cd $out/lib; ln -s libfl.a libl.a
}

installPhase=installPhase
genericBuild

error: pathspec 'pkgs/development/tools/parsing/flex/builder.sh' did not match any file(s) known to git


cases refactored

cases refactored

#!/bin/bash

# functions
show_help()
{
  echo "Usage: ./vhostctl.sh [OPTIONS]

Options:

  -A, --application               Application name. Apps supported: Wordpress, Drupal, Zabbix, Hippo.
  -C, --operation                 Operation commands:
                                    start - to build and start containers with the application
                                    clone - to copy containers with new names and replace configuration with new URL
                                    backup - to save current state of existing containers
                                    restore - to restore containers to previous state
                                    destroy - to remove container(s) with webapp
                                    scan - to scan webapp for vulnerabulities
                                    handle - to handle parameters from front-end for devPanel's script inside docker container
  -SD, --source-domain            Source domain name. Used for 'clone' operation.
  -DD, --destination-domain       Destination domain name. For 'clone' operation different domain name should be passed.
  -B, --backup-name               Backup name.
  -R, --restore-name              Restore previously backed up name.
  -L, --build-image               Build devpanel_cache image locally instead of downloading it from docker hub.
  -RB, --remove-backups           Remove backups for requested webapp.
  -O, --options                   Script's name and parameters to process for webapp.
  -T, --type                      Type of the host. Can be docker or local.
  -RC, --read-config              Read config to determine type of the host.

Usage examples:
  ./vhostctl.sh -A=wordpress -C=start -DD=t3st.some.domain -T=local
  ./vhostctl.sh -A=wordpress -C=start -DD=t3st.some.domain -L -T=docker
  ./vhostctl.sh -C=clone -SD=t3st.some.domain -DD=t4st.some.domain
  ./vhostctl.sh -C=backup  -DD=t3st.some.domain -B=t3st_backup1
  ./vhostctl.sh -C=restore -DD=t3st.some.domain -R=t3st_backup1
  ./vhostctl.sh -C=destroy -DD=t3st.some.domain
  ./vhostctl.sh -C=destroy -DD=t3st.some.domain -RB
  ./vhostctl.sh -C=scan -DD=t3st.some.domain
  ./vhostctl.sh -C=handle -DD=t3st.some.domain -O="check-disk-quota 90"
  ./vhostctl.sh -DD=t3st.some.domain -RC
"
}

self_bin=$(readlink -e "$0")
if [ $? -ne 0 ]; then
  echo "Error: unable to detect self path" 1>&2
  exit 1
fi
self_dir=${self_bin%/*}
sys_dir=$(readlink -e "$self_dir/../..")
lib_file="$sys_dir/lib/functions"

if ! source "$lib_file"; then
  echo "Error: unable to source lib file $lib_file" 1>&2
  exit 1
fi

# parse option arguments
for i in "$@"
do
case $i in
    -A=*|--application=*)
    app="${i#*=}"
    shift # past argument=value
    ;;
    -C=*|--operation=*)
    operation="${i#*=}"
    shift # past argument=value
    ;;
    -SD=*|--source-domain=*)
    source_domain="${i#*=}"
    shift # past argument=value
    ;;
    -DD=*|--destination-domain=*)
    domain="${i#*=}"
    shift # past argument=value
    ;;
    -B=*|--backup-name=*)
    backup_name="${i#*=}"
    shift # past argument=value
    ;;
    -R=*|--restore-name=*)
    restore_name="${i#*=}"
    shift # past argument=value
    ;;
    -L*|--build-local*)
    build_image="${i#*=}"
    shift # past argument=value
    ;;
    -RB*|--remove-backups*)
    remove_backups="${i#*=}"
    shift # past argument=value
    ;;
    -O*|--options*)
    handler_options="${i#*=}"
    shift # past argument=value
    ;;
    -T*|--type*)
    host_type="${i#*=}"
    shift # past argument=value
    ;;
    -RC*|--read-config*)
    read_config="${i#*=}"
    shift # past argument=value
    ;;
    *)
    show_help
            # unknown option
    ;;
esac
done

# define to use sudo or not
if [ "$UID" -eq 0 ]; then
  sudo=""
else
  sudo="sudo"
fi
# define installation tool
if [ -f /usr/bin/yum ]; then
  installation_tool="yum install -y"
elif [ -f /usr/bin/apt-get ]; then
  installation_tool="apt-get install -y"
else
  echo "OS not supported. Exiting ..."
  exit 1
fi

create_local_config()
{
  # create dir if not exist
  if [ ! -d ${sys_dir}/config/apps ];then
    ${sudo} mkdir -p ${sys_dir}/config/apps
  fi
  vhost=`echo "${domain}" | awk -F'[.]' '{print $1}'`
  # if [ "$operation" == "start" ]; then vhost="${orig_domain}"; fi
  if [ "$host_type" == "docker" -o "$app_hosting" == "docker" ]; then
    # set clone state: true of false
    if [ "$operation" == "clone" ]; then
      clone_state="true"
      source_vhost="${target_vhost}"
    else
      clone_state="false"
    fi
    docker_get_ids_and_names_of_containers
    ini_contents="\
app.name           = ${vhost}
app.hosting        = docker
app.container_name = ${CONTAINER_WEB_NAME}
app.clone          = ${clone_state}
"
  else
    ini_contents="\
app.name           = ${vhost}
app.hosting        = local
app.clone          = ${clone_state}
"
  fi
  echo "$ini_contents" | ${sudo} ${sys_dir}/bin/update-ini-file -q -c ${sys_dir}/config/apps/${vhost}.ini
}

read_local_config()
{
  vhost=`echo "${domain}" | awk -F'[.]' '{print $1}'`

  # check if config exists. if not, set to local. standard script 'restore-vhost' does not create any configs by default
  if [ ! -f ${sys_dir}/config/apps/${vhost}.ini ]; then
    app_hosting="local"
  else
    app_name=`ini_section_get_key_value ${sys_dir}/config/apps/${vhost}.ini app name`
    app_hosting=`ini_section_get_key_value ${sys_dir}/config/apps/${vhost}.ini app hosting`
    app_clone=`ini_section_get_key_value ${sys_dir}/config/apps/${vhost}.ini app clone`
    if [ "$app_hosting" == "docker" ]; then
      app_container_name=`ini_section_get_key_value ${sys_dir}/config/apps/${vhost}.ini app container_name`
    fi
  fi
}

controller_handler()
# example in db@controller
# 31|list_vhost_logs||libexec/check-logs|-s %vhost%|0.0|0|2012-05-22 07:27:25|2016-02-19 20:38:03
# becomes ('+' used as a whitespace)
# 31|list_vhost_logs||paas-provisioner/docker/vhostctl.sh|-C=handle -O=libexec/check-logs+-s+%vhost% -DD=%vhost%|0.0|0|2012-05-22 07:27:25|2016-02-19 20:38:03
# and vhostctl receives (after sed processed '+')
# handler_options="libexec/check-logs -s some_vhost"
{
  read_local_config
  handler_options=`echo ${handler_options}|sed 's/+/ /g'`
  case "$handler_options" in
    bin/restore-vhost-subsystem*|bin/list-backups*)
    if [ "$app_hosting" == "docker" ]; then
      docker exec -i ${app_container_name} su - w_${vhost} -c "${sys_dir}/${handler_options}"
    elif [ "$app_hosting" == "local" ]; then
      su - w_${vhost} -c "${sys_dir}/${handler_options}"
    fi
    ;;

    libexec/restore-vhost*http://www.webenabled.com/seedapps/*)
    ${sys_dir}/${handler_options}
    ;;

    libexec/restore-vhost*)
    new_vhost_name=`echo ${handler_options}|awk '{print $2}'`
    old_vhost_name=`echo ${handler_options}|awk -F'/opt/webenabled-data/vhost_archives/' '{print $2}'|awk -F'/' '{print $1}'`
    hostname_fqdn=`hostname -f`
    vhost="${old_vhost_name}.${hostname_fqdn}"

    if [ `docker ps|grep ${vhost}|wc -l` -gt 0 ]; then
      app_hosting="docker"
    fi

    if [ "$app_hosting" == "docker" ]; then
      # create and run a new container
      CONTAINER_WEB_ID=`docker ps|grep ${vhost}|awk '{print $1}'`
      app_container_name="${new_vhost_name}.${hostname_fqdn}"
      docker commit ${CONTAINER_WEB_ID} ${app_container_name}
      docker run -d --name=${app_container_name} ${app_container_name}

      ini_contents="\
app.name           = ${new_vhost_name}
app.hosting        = docker
app.container_name = ${app_container_name}
app.clone          = true
"
      echo "$ini_contents" | ${sudo} ${sys_dir}/bin/update-ini-file -q -c ${sys_dir}/config/apps/${new_vhost_name}.ini

      # create nginx config
      domain="${app_container_name}"
      update_nginx_config

      docker exec -i ${app_container_name} "${sys_dir}/${handler_options}"
    elif [ "$app_hosting" == "local" ]; then
      ini_contents="\
app.name           = ${new_vhost_name}
app.hosting        = local
app.clone          = true
"
      echo "$ini_contents" | ${sudo} ${sys_dir}/bin/update-ini-file -q -c ${sys_dir}/config/apps/${new_vhost_name}.ini
      ${sys_dir}/${handler_options}
    fi
    ;;
    *)
    if [ "$app_hosting" == "docker" ]; then
      docker exec -i ${app_container_name} "${sys_dir}/${handler_options}"
    elif [ "$app_hosting" == "local" ]; then
      ${sys_dir}/${handler_options}
    fi
    ;;
  esac

  detect_running_apache_and_patch_configs
}

update_nginx_config()
{
  # check for nginx installation
  if [ ! -f /usr/sbin/nginx ]; then
    ${sudo} ${installation_tool} nginx
  fi
  # get ip address of web container
  if [ "$operation" == "start" ]; then
    container_name="${domain}_${app}_web"
  elif [ "$operation" == "restore" ]; then
    container_name=$CONTAINER_WEB_NAME
  fi
  hostname_fqdn=`hostname -f`
  if [ "$operation" == "clone" ]; then domain="${target_vhost}.${hostname_fqdn}"; fi
  if [ "$host_type" == "docker" -o "$app_hosting" == "docker" ]; then
    if [ "$app_container_name" ]; then container_name="$app_container_name"; fi
    container_ip_address=`docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)|grep "${container_name}"|awk -F" - " '{print $2}'`
  fi
  if [ "$app" == "hippo" ]; then
    WEB_PORT=8080
  else
    WEB_PORT=80
  fi
  # create config for domain
  cat << EOF > /tmp/${domain}.conf
server {
  listen       80;
  server_name  ${domain};
  location / {
    proxy_set_header Host ${domain};
    proxy_pass http://${container_ip_address}:${WEB_PORT};
  }
}
EOF
  # create config for subdomain
  domain_fp=`echo "${domain}"|awk -F'[.]' '{print $1}'`
  domain_lp=`echo "${domain}"|awk -F"${domain_fp}." '{print $2}'`
  subdomain="${domain_fp}-gen.${domain_lp}"
  cat << EOF > /tmp/${subdomain}.conf
server {
  listen       80;
  server_name  ${subdomain};
  location / {
    proxy_set_header Host ${subdomain};
    proxy_pass http://${container_ip_address}:${WEB_PORT};
  }
}
EOF
  # apply configs
  ${sudo} rm -f /etc/nginx/sites-enabled/${domain}.conf /etc/nginx/sites-enabled/${subdomain}.conf
  ${sudo} mv /tmp/${domain}.conf /etc/nginx/sites-enabled/${domain}.conf
  ${sudo} mv /tmp/${subdomain}.conf /etc/nginx/sites-enabled/${subdomain}.conf
  restart_or_reload_nginx
}

restart_or_reload_nginx()
{
  # The hash bucket size parameter is aligned to the size that is a multiple of the processor’s cache line size.
  # This speeds up key search in a hash on modern processors by reducing the number of memory accesses.
  # If hash bucket size is equal to one processor’s cache line size then the number of memory accesses during the key search
  # will be two in the worst case — first to compute the bucket address, and second during the key search inside the bucket.
  # Therefore, if nginx emits the message requesting to increase either hash max size or hash bucket size
  # then the first parameter should first be increased.
  if [ ! -f /etc/nginx/conf.d/server_names_hash_bucket_size.conf ]; then
    ${sudo} echo "server_names_hash_bucket_size  128;" > /etc/nginx/conf.d/server_names_hash_bucket_size.conf
  fi

  if [[ `service nginx status` == " * nginx is running" ]]; then
    ${sudo} service nginx reload
  else
    ${sudo} service nginx restart
  fi
}

patch_definition_files_and_build()
{
  source_user=`echo "${source_domain}" | awk -F'[.]' '{print $1}'`
  source_domain_name=`echo "${source_domain}" | awk -F"${source_user}." '{print $2}'`
  user=`echo "${domain}" | awk -F'[.]' '{print $1}'`
  domain_name=`echo "${domain}" | awk -F"${user}." '{print $2}'`

  local compose_file="$self_dir/original/docker-compose.yml"
  local template_file="$compose_file.orig"
  local sed_str=""

  cp -f  "$template_file" "$compose_file"

  sed_str="\
    s/SERVICE_NAME_VAR/${domain}_${app}/;
    s/CONTAINER_NAME_VAR/${domain}_${app}/;
    s/NETWORK_NAME_VAR/${domain}_${app}/;
    s/USER_VAR/${user}/;
    s/DOMAIN_VAR/${domain_name}/;
    s/SRC_USER_VAR/${source_user}/;
    s/SRC_DOMAIN_VAR/${source_domain_name}/;
    s/APP_VAR/${app}/;"

  if [ "$app" == "wordpress" ]; then
    sed_str+="s/SEEDAPP_ARCHIVE_VAR/${app}-v4.tgz/;"
  elif [ "$app" == "drupal" ]; then
    sed_str+="s/SEEDAPP_ARCHIVE_VAR/${app}-v7.tgz/;"
  fi

  sed -i "$sed_str" "$compose_file"

  /usr/local/bin/docker-compose -f "$compose_file" up --build -d
  rm -f "$compose_file"
  update_nginx_config
}

docker_get_ids_and_names_of_containers()
{
  if   [ "$operation" == "clone" ]; then
    CONTAINER_WEB_ID=`docker ps|grep ${source_vhost}|awk '{print $1}'`
  elif [ "$operation" == "backup" -o "$operation" == "list_backups" ]; then
    CONTAINER_WEB_ID=`docker ps|grep ${domain}|awk '{print $1}'`
  else
    CONTAINER_WEB_ID=`docker ps|grep ${domain}_${app}_web|awk '{print $1}'`
  fi
  CONTAINER_WEB_NAME=`docker inspect -f '{{.Name}}' ${CONTAINER_WEB_ID}|awk -F'/' '{print $2}'`
}

docker_msf()
{
  if [ `docker ps|grep msf_container|wc -l` -eq 0 ]; then
    if [ `docker ps -a|grep msf_container|wc -l` -gt 0 ]; then docker rm -f msf_container; fi
    docker run -d --name=msf_container msf:v1
  fi
  CONTAINER_MSF_ID=`docker ps|grep msf_container|awk '{print $1}'`
  docker cp ${self_dir}/msf/wmap.rc ${CONTAINER_MSF_ID}:/tmp/wmap.rc
  docker exec ${CONTAINER_MSF_ID} /bin/sh -c "sed -i s/127.0.0.1/${dst_ip_address}/ /tmp/wmap.rc"
  docker exec ${CONTAINER_MSF_ID} /bin/sh -c "TERM=rxvt msfconsole -r /tmp/wmap.rc"
}

detect_running_apache_and_patch_configs()
{
  if [ `ps aux|grep apache2|wc -l` -gt 0 ]; then
    # patch configs with new port
    readarray -t apache_configs_array <<< `find -L /etc/apache2 -name *.conf`
    servernames_array=()
    for i in ${apache_configs_array[@]}; do
      if [ `grep ":80" ${i}|wc -l` -gt 0 -a `grep ":8080" ${i}|wc -l` -eq 0 ]; then
        sed -i 's/:80/:8080/' ${i}
      fi
      if [ `grep "  ServerName " ${i}|wc -l` -gt 0 ]; then
        servernames_array+=(`grep "  ServerName " ${i}|awk -F "  ServerName " '{print $2}'`)
      fi
    done
    # restart apache
    ${sudo} service apache2 restart
    # update nginx configs with apache's hosts
    for servername in ${servernames_array[@]}; do
      # create config
      cat << EOF > /tmp/${servername}.conf
server {
  listen       80;
  server_name  ${servername};
  location / {
    proxy_set_header Host ${servername};
    proxy_pass http://localhost:8080;
  }
}
EOF
      ${sudo} rm -f /etc/nginx/sites-enabled/${servername}.conf
      ${sudo} mv /tmp/${servername}.conf /etc/nginx/sites-enabled/${servername}.conf
    done
    restart_or_reload_nginx
  fi
}

# check for Docker installation
if [ ! -f /usr/bin/docker ]; then
  # quick install for Ubuntu only
  ${sudo} echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list
  ${sudo} apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  ${sudo} apt-get update
  ${sudo} apt-get install -y docker-engine
fi

# check for Docker Compose binary
if [ ! -f /usr/local/bin/docker-compose ]; then
  ${sudo} curl -L https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  ${sudo} chmod +x /usr/local/bin/docker-compose
fi

# build locally or pull image from docker hub
if [ `docker images|grep devpanel_cache|grep latest|wc -l` -eq 0 ]; then
  if [ $build_image ]; then
    docker build -t devpanel_cache:latest "$self_dir/cache"
  else
    docker pull freeminder/devpanel_cache:latest && docker tag freeminder/devpanel_cache:latest devpanel_cache:latest
  fi
fi

# main logic
if [ "$app" == "zabbix" -a "$operation" == "start" -a "$domain" -a "$host_type" == "docker" ]; then
  if [ `docker images|grep devpanel_zabbix|wc -l` -eq 0 ]; then
    if [ $build_image ]; then
      docker build -t devpanel_zabbix:v1 ${self_dir}/zabbix
    else
      docker pull freeminder/devpanel_zabbix:v1
      docker tag freeminder/devpanel_zabbix:v1 devpanel_zabbix:v1
    fi
  fi
  docker run -d -it --name ${domain}_${app}_web devpanel_zabbix:v1
  update_nginx_config

elif [ "$app" == "hippo" -a "$operation" == "start" -a "$domain" -a "$host_type" == "docker" ]; then
  if [ `docker images|grep devpanel_hippo|wc -l` -eq 0 ]; then
    if [ $build_image ]; then
      docker build -t devpanel_hippo:v1 ${self_dir}/hippo
    else
      docker pull freeminder/devpanel_hippo:v1
      docker tag freeminder/devpanel_hippo:v1 devpanel_hippo:v1
    fi
  fi
  docker run -d -it --name ${domain}_${app}_web devpanel_hippo:v1
  update_nginx_config

elif [ "$operation" == "start" -a "$domain" -a "$host_type" ]; then
  if [ "$host_type" == "docker" ]; then
    orig_domain="$domain"
    detect_running_apache_and_patch_configs
    patch_definition_files_and_build
  elif [ "$host_type" == "local" ]; then
    #
    # will be changed to parse /apps.txt in next update
    #
    if [ "$app" == "wordpress" ]; then
      app_arch="wordpress-v4.tgz"
    elif [ "$app" == "drupal" ]; then
      app_arch="drupal-v7.tgz"
    else
      echo "App not supported."
      exit 1
    fi
    # check for downloaded app
    if [ ! -f ${sys_dir}/${app}/${app_arch} ]; then
      ${sudo} mkdir -p ${sys_dir}/${app} && cd ${sys_dir}/${app} && wget https://www.webenabled.com/seedapps/${app_arch} && tar zxvf ${app_arch}
    fi
    vhost=`echo "${domain}" | awk -F'[.]' '{print $1}'`
    domain_name=`echo "${domain}" | awk -F"${vhost}." '{print $2}'`
    ${sudo} ${sys_dir}/libexec/config-vhost-names-default ${domain_name}
    ${sudo} ${sys_dir}/libexec/restore-vhost -F ${vhost} ${sys_dir}/${app}
    detect_running_apache_and_patch_configs
  else
    show_help
  fi
  create_local_config

elif [ "$operation" == "clone" -a "$source_domain" -a "$domain" ]; then
  source_vhost=${source_domain}
  target_vhost=${domain}
  domain="$source_domain"
  read_local_config
  if [ "$app_hosting" == "docker" ]; then
    # parse variables
    source_user=`echo "${source_vhost}" | awk -F'[.]' '{print $1}'`
    source_domain_name=`echo "${source_vhost}" | awk -F"${source_user}." '{print $2}'`
    user=`echo "${target_vhost}" | awk -F'[.]' '{print $1}'`
    domain_name=`echo "${target_vhost}" | awk -F"${user}." '{print $2}'`
    docker_get_ids_and_names_of_containers
    # save current state of containers as images
    docker commit ${CONTAINER_WEB_NAME} ${target_vhost}
    # get ids of images
    IMAGE_WEB_NAME=`docker images|grep ${target_vhost}|awk '{print $1}'`
    docker run -d --name=${target_vhost} ${IMAGE_WEB_NAME}
    while [ `docker ps|grep ${target_vhost}|wc -l` -eq 0 ]; do
      echo "WEB container is not running. Waiting its start."
      sleep 1
    done
    # get destination containers ids
    CONTAINER_WEB_ID=`docker ps|grep ${user}|awk '{print $1}'`

    USER=`awk -F'.' '{print $1}' <<< "$source_vhost"`
    DOMAIN=${source_domain_name}
    DST_USER=${user}
    DST_DOMAIN=${domain_name}
    # update container's apache2 config with new URL
    docker exec ${CONTAINER_WEB_ID} sed -i "s/ServerName ${USER}/ServerName ${DST_USER}/" /etc/apache2/devpanel-virtwww/w_${USER}.conf
    docker exec ${CONTAINER_WEB_ID} sed -i "s/ServerAlias www.${USER}/ServerAlias www.${DST_USER}/" /etc/apache2/devpanel-virtwww/w_${USER}.conf
    docker exec -d ${CONTAINER_WEB_ID} /bin/sh -c "/tmp/startup.sh"
    docker exec ${CONTAINER_WEB_ID} service apache2 restart

    # replace db data with new URL
    app="wordpress"
    PORT=4000
    PASSWORD=`docker exec ${CONTAINER_WEB_ID} grep w_${USER} /home/clients/websites/w_${USER}/.mysql.passwd|awk -F ":" '{print $2}'`
    while [ `docker exec ${CONTAINER_WEB_ID} /bin/sh -c "netstat -ltpn|grep 4000|wc -l"` -eq 0 ]; do
      echo "DB is not running. Waiting its start."
      sleep 1
      docker exec ${CONTAINER_WEB_ID} mysql ${app} -h localhost -P ${PORT} -u w_${USER} --password=${PASSWORD} --socket=/home/clients/databases/b_${USER}/mysql/mysql.sock -e \
        "UPDATE wp_options SET option_value = replace(option_value, 'http://${USER}.${DOMAIN}', 'http://${DST_USER}.${DST_DOMAIN}');"
    done
    docker exec ${CONTAINER_WEB_ID} mysql ${app} -h localhost -P ${PORT} -u w_${USER} --password=${PASSWORD} --socket=/home/clients/databases/b_${USER}/mysql/mysql.sock -e \
      "UPDATE wp_options SET option_value = replace(option_value, 'http://${USER}.${DOMAIN}', 'http://${DST_USER}.${DST_DOMAIN}');"

    # check if it was replaced correctly
    if [ `docker exec ${CONTAINER_WEB_ID} mysql ${app} -h localhost -P ${PORT} -u w_${USER} --password=${PASSWORD} --socket=/home/clients/databases/b_${USER}/mysql/mysql.sock -e \
      "select * from wp_options;"|grep -c ${DST_USER}` -eq 2 ]; then
        echo "DB cloned correctly."
    else
        echo "Error: URL was not replaced correctly in MySQL."
        exit 1
    fi

    # update host's nginx config with new IP of cloned web container
    domain="${target_vhost}"
    create_local_config
    app_clone="true"
    app_container_name="${target_vhost}"
    update_nginx_config ${target_vhost}
  elif [ "$app_hosting" == "local" ]; then
    # clone_vhost_local||libexec/clone-vhost-local|%source_vhost% %target_vhost%|
    ${sys_dir}/libexec/clone-vhost-local "$source_vhost" "$target_vhost"
    create_local_config
    update_nginx_config ${target_vhost}
  else
    show_help
    exit 1
  fi

elif [ "$operation" == "backup" -a "$backup_name" -a "$domain" ]; then
  read_local_config
  if [ "$app_hosting" == "docker" ]; then
    # get ids of current containers
    docker_get_ids_and_names_of_containers

    docker exec ${CONTAINER_WEB_ID} ${sys_dir}/libexec/archive-vhost "$vhost" "$backup_name"

    # # save current state of containers as images
    # docker commit ${CONTAINER_WEB_NAME} ${domain}_${backup_name}_bkp_web
  elif [ "$app_hosting" == "local" ]; then
    # archive_vhost||libexec/archive-vhost|%vhost% %filename%|
    ${sys_dir}/libexec/archive-vhost "$vhost" "$backup_name"
  else
    show_help
    exit 1
  fi

elif [ "$operation" == "list_backups" ]; then
  read_local_config
  if [ "$app_hosting" == "docker" ]; then
    # get ids of current containers
    docker_get_ids_and_names_of_containers
    docker exec ${CONTAINER_WEB_ID} ${sys_dir}/bin/list-backups
  elif [ "$app_hosting" == "local" ]; then
    # 88|list_backups||bin/list-backups|--|0.0|0|2013-10-07 19:23:31|2013-10-07 22:00:53
    ${sys_dir}/bin/list-backups
  else
    show_help
    exit 1
  fi

elif [ "$operation" == "restore" -a "$restore_name" -a "$domain" ]; then
  read_local_config
  if [ "$app_hosting" == "docker" ]; then
    # get ids of current containers
    docker_get_ids_and_names_of_containers
    # remove source containers to avoid name conflicts
    docker rm -f ${CONTAINER_WEB_ID}
    # get ids of images
    IMAGE_WEB_NAME=`docker images|grep ${domain}_${restore_name}_bkp_web|awk '{print $1}'`
    # start backed up containers
    docker run -d --name=${CONTAINER_WEB_NAME} ${IMAGE_WEB_NAME}
    while [ `docker ps|grep ${domain}|wc -l` -eq 0 ]; do
      echo "WEB container is not running. Waiting its start."
      sleep 1
    done
    # update nginx config with new IP of web container
    update_nginx_config ${CONTAINER_WEB_NAME}
  elif [ "$app_hosting" == "local" ]; then
    # restore_vhost||libexec/restore-vhost|%vhost% %filename%|
    ${sys_dir}/libexec/restore-vhost "$vhost" "$restore_name"
  else
    show_help
    exit 1
  fi

elif [ "$operation" == "scan" -a "$domain" -a "$host_type" == "docker" ]; then
  # get ids of current containers
  docker_get_ids_and_names_of_containers
  # get ip_address of webapp
  dst_ip_address=`docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)|grep "${CONTAINER_WEB_NAME}"|awk -F" - " '{print $2}'`
  # check if msf container exists
  if [ `docker images|grep msf|wc -l` -eq 0 ]; then
    if [ $build_image ]; then
      docker build -t msf:v1 ${self_dir}/msf
    else
      docker pull freeminder/msf:v1
      docker tag freeminder/msf:v1 msf:v1
    fi
  fi
  # do the scan
  docker_msf

elif [ "$operation" == "destroy" -a "$domain" ]; then
  read_local_config
  if [[ "$app_hosting" == "docker" ]]; then
    docker rm  -f ${app_container_name}
    if [ "$app" == "zabbix" -o "$app" == "hippo" ]; then
      docker rmi -f devpanel_${app}:v1
    elif [[ "$app_clone" == "true" ]]; then
      docker rmi -f ${app_container_name}
    else
      docker rmi -f original_${app_container_name}
    fi
    # remove backups also if requested
    if [ $remove_backups ]; then
      readarray -t backups_array <<< `docker images|grep ${domain}|awk '{print $1}'`
      for i in ${backups_array[@]}; do
        docker rmi -f ${i}
      done
    fi
  elif [[ "$app_hosting" == "local" ]]; then
    # remove_vhost||libexec/remove-vhost|%vhost% %filename%|
    ${sys_dir}/libexec/remove-vhost ${vhost}
  else
    show_help
    exit 1
  fi
  # remove config from nginx
  ${sudo} rm -f /etc/nginx/sites-enabled/${domain}*.conf
  restart_or_reload_nginx
  ${sudo} rm -f ${sys_dir}/config/apps/${domain}.ini
  ${sudo} rm -f ${sys_dir}/config/apps/${vhost}.ini

elif [ "$operation" == "handle" -a "$handler_options" ]; then
  controller_handler

elif [ "$domain" -a "$read_config" ]; then
  read_local_config
  echo "$app_hosting"

else
  show_help
  exit 1
fi

#!/bin/bash

# functions
show_help()
{
  echo "Usage: ./vhostctl.sh [OPTIONS]

Options:

  -A, --application               Application name. Apps supported: Wordpress, Drupal, Zabbix, Hippo.
  -C, --operation                 Operation commands:
                                    start - to build and start containers with the application
                                    clone - to copy containers with new names and replace configuration with new URL
                                    backup - to save current state of existing containers
                                    restore - to restore containers to previous state
                                    destroy - to remove container(s) with webapp
                                    scan - to scan webapp for vulnerabulities
                                    handle - to handle parameters from front-end for devPanel's script inside docker container
  -SD, --source-domain            Source domain name. Used for 'clone' operation.
  -DD, --destination-domain       Destination domain name. For 'clone' operation different domain name should be passed.
  -B, --backup-name               Backup name.
  -R, --restore-name              Restore previously backed up name.
  -L, --build-image               Build devpanel_cache image locally instead of downloading it from docker hub.
  -RB, --remove-backups           Remove backups for requested webapp.
  -O, --options                   Script's name and parameters to process for webapp.
  -T, --type                      Type of the host. Can be docker or local.
  -RC, --read-config              Read config to determine type of the host.

Usage examples:
  ./vhostctl.sh -A=wordpress -C=start -DD=t3st.some.domain -T=local
  ./vhostctl.sh -A=wordpress -C=start -DD=t3st.some.domain -L -T=docker
  ./vhostctl.sh -C=clone -SD=t3st.some.domain -DD=t4st.some.domain
  ./vhostctl.sh -C=backup  -DD=t3st.some.domain -B=t3st_backup1
  ./vhostctl.sh -C=restore -DD=t3st.some.domain -R=t3st_backup1
  ./vhostctl.sh -C=destroy -DD=t3st.some.domain
  ./vhostctl.sh -C=destroy -DD=t3st.some.domain -RB
  ./vhostctl.sh -C=scan -DD=t3st.some.domain
  ./vhostctl.sh -C=handle -DD=t3st.some.domain -O="check-disk-quota 90"
  ./vhostctl.sh -DD=t3st.some.domain -RC
"
}

self_bin=$(readlink -e "$0")
if [ $? -ne 0 ]; then
  echo "Error: unable to detect self path" 1>&2
  exit 1
fi
self_dir=${self_bin%/*}
sys_dir=$(readlink -e "$self_dir/../..")
lib_file="$sys_dir/lib/functions"

if ! source "$lib_file"; then
  echo "Error: unable to source lib file $lib_file" 1>&2
  exit 1
fi

# parse option arguments
for i in "$@"
do
case $i in
    -A=*|--application=*)
    app="${i#*=}"
    shift # past argument=value
    ;;
    -C=*|--operation=*)
    operation="${i#*=}"
    shift # past argument=value
    ;;
    -SD=*|--source-domain=*)
    source_domain="${i#*=}"
    shift # past argument=value
    ;;
    -DD=*|--destination-domain=*)
    domain="${i#*=}"
    shift # past argument=value
    ;;
    -B=*|--backup-name=*)
    backup_name="${i#*=}"
    shift # past argument=value
    ;;
    -R=*|--restore-name=*)
    restore_name="${i#*=}"
    shift # past argument=value
    ;;
    -L*|--build-local*)
    build_image="${i#*=}"
    shift # past argument=value
    ;;
    -RB*|--remove-backups*)
    remove_backups="${i#*=}"
    shift # past argument=value
    ;;
    -O*|--options*)
    handler_options="${i#*=}"
    shift # past argument=value
    ;;
    -T*|--type*)
    host_type="${i#*=}"
    shift # past argument=value
    ;;
    -RC*|--read-config*)
    read_config="${i#*=}"
    shift # past argument=value
    ;;
    *)
    show_help
            # unknown option
    ;;
esac
done

# define to use sudo or not
if [ "$UID" -eq 0 ]; then
  sudo=""
else
  sudo="sudo"
fi
# define installation tool
if [ -f /usr/bin/yum ]; then
  installation_tool="yum install -y"
elif [ -f /usr/bin/apt-get ]; then
  installation_tool="apt-get install -y"
else
  echo "OS not supported. Exiting ..."
  exit 1
fi

create_local_config()
{
  # create dir if not exist
  if [ ! -d ${sys_dir}/config/apps ];then
    ${sudo} mkdir -p ${sys_dir}/config/apps
  fi
  vhost=`echo "${domain}" | awk -F'[.]' '{print $1}'`
  # if [ "$operation" == "start" ]; then vhost="${orig_domain}"; fi
  if [ "$host_type" == "docker" -o "$app_hosting" == "docker" ]; then
    # set clone state: true of false
    if [ "$operation" == "clone" ]; then
      clone_state="true"
      source_vhost="${target_vhost}"
    else
      clone_state="false"
    fi
    docker_get_ids_and_names_of_containers
    ini_contents="\
app.name           = ${vhost}
app.hosting        = docker
app.container_name = ${CONTAINER_WEB_NAME}
app.clone          = ${clone_state}
"
  else
    ini_contents="\
app.name           = ${vhost}
app.hosting        = local
app.clone          = ${clone_state}
"
  fi
  echo "$ini_contents" | ${sudo} ${sys_dir}/bin/update-ini-file -q -c ${sys_dir}/config/apps/${vhost}.ini
}

read_local_config()
{
  vhost=`echo "${domain}" | awk -F'[.]' '{print $1}'`

  # check if config exists. if not, set to local. standard script 'restore-vhost' does not create any configs by default
  if [ ! -f ${sys_dir}/config/apps/${vhost}.ini ]; then
    app_hosting="local"
  else
    app_name=`ini_section_get_key_value ${sys_dir}/config/apps/${vhost}.ini app name`
    app_hosting=`ini_section_get_key_value ${sys_dir}/config/apps/${vhost}.ini app hosting`
    app_clone=`ini_section_get_key_value ${sys_dir}/config/apps/${vhost}.ini app clone`
    if [ "$app_hosting" == "docker" ]; then
      app_container_name=`ini_section_get_key_value ${sys_dir}/config/apps/${vhost}.ini app container_name`
    fi
  fi
}

controller_handler()
# example in db@controller
# 31|list_vhost_logs||libexec/check-logs|-s %vhost%|0.0|0|2012-05-22 07:27:25|2016-02-19 20:38:03
# becomes ('+' used as a whitespace)
# 31|list_vhost_logs||paas-provisioner/docker/vhostctl.sh|-C=handle -O=libexec/check-logs+-s+%vhost% -DD=%vhost%|0.0|0|2012-05-22 07:27:25|2016-02-19 20:38:03
# and vhostctl receives (after sed processed '+')
# handler_options="libexec/check-logs -s some_vhost"
{
  read_local_config
  handler_options=`echo ${handler_options}|sed 's/+/ /g'`
  case "$handler_options" in
    bin/restore-vhost-subsystem*|bin/list-backups*)
    if [ "$app_hosting" == "docker" ]; then
      docker_exec="docker exec -i ${app_container_name}"
      su_exec="su - w_${vhost} -c"
    elif [ "$app_hosting" == "local" ]; then
      docker_exec=""
      su_exec="su - w_${vhost} -c"
    fi
    ;;
    libexec/restore-vhost*)

    new_vhost_name=`echo ${handler_options}|awk '{print $2}'`
    old_vhost_name=`echo ${handler_options}|awk -F'/opt/webenabled-data/vhost_archives/' '{print $2}'|awk -F'/' '{print $1}'`
    hostname_fqdn=`hostname -f`
    vhost="${old_vhost_name}.${hostname_fqdn}"

    if [ `docker ps|grep ${vhost}|wc -l` -gt 0 ]; then
      app_hosting="docker"
    fi

    if [ "$app_hosting" == "docker" ]; then
      # create and run a new container
      CONTAINER_WEB_ID=`docker ps|grep ${vhost}|awk '{print $1}'`
      app_container_name="${new_vhost_name}.${hostname_fqdn}"
      docker commit ${CONTAINER_WEB_ID} ${app_container_name}
      docker run -d --name=${app_container_name} ${app_container_name}
      # write app's config
      ini_contents="\
app.name           = ${new_vhost_name}
app.hosting        = docker
app.container_name = ${app_container_name}
app.clone          = true
"
      echo "$ini_contents" | ${sudo} ${sys_dir}/bin/update-ini-file -q -c ${sys_dir}/config/apps/${new_vhost_name}.ini
      # create nginx config
      domain="${app_container_name}"
      update_nginx_config

      docker_exec="docker exec -i ${app_container_name}"
      su_exec=""
    elif [ "$app_hosting" == "local" ]; then
      # write app's config
      ini_contents="\
app.name           = ${new_vhost_name}
app.hosting        = local
app.clone          = true
"
      echo "$ini_contents" | ${sudo} ${sys_dir}/bin/update-ini-file -q -c ${sys_dir}/config/apps/${new_vhost_name}.ini

      docker_exec=""
      su_exec=""
    fi
    ;;
    *)
    if [ "$app_hosting" == "docker" ]; then
      docker_exec="docker exec -i ${app_container_name}"
      su_exec=""
    elif [ "$app_hosting" == "local" ]; then
      docker_exec=""
      su_exec=""
    fi
    ;;
  esac
  ${docker_exec}${su_exec} ${sys_dir}/${handler_options}
}

update_nginx_config()
{
  # check for nginx installation
  if [ ! -f /usr/sbin/nginx ]; then
    ${sudo} ${installation_tool} nginx
  fi
  # get ip address of web container
  if [ "$operation" == "start" ]; then
    container_name="${domain}_${app}_web"
  elif [ "$operation" == "restore" ]; then
    container_name=$CONTAINER_WEB_NAME
  fi
  hostname_fqdn=`hostname -f`
  if [ "$operation" == "clone" ]; then domain="${target_vhost}.${hostname_fqdn}"; fi
  if [ "$host_type" == "docker" -o "$app_hosting" == "docker" ]; then
    if [ "$app_container_name" ]; then container_name="$app_container_name"; fi
    container_ip_address=`docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)|grep "${container_name}"|awk -F" - " '{print $2}'`
  fi
  if [ "$app" == "hippo" ]; then
    WEB_PORT=8080
  else
    WEB_PORT=80
  fi
  # create config for domain
  cat << EOF > /tmp/${domain}.conf
server {
  listen       80;
  server_name  ${domain};
  location / {
    proxy_set_header Host ${domain};
    proxy_pass http://${container_ip_address}:${WEB_PORT};
  }
}
EOF
  # create config for subdomain
  domain_fp=`echo "${domain}"|awk -F'[.]' '{print $1}'`
  domain_lp=`echo "${domain}"|awk -F"${domain_fp}." '{print $2}'`
  subdomain="${domain_fp}-gen.${domain_lp}"
  cat << EOF > /tmp/${subdomain}.conf
server {
  listen       80;
  server_name  ${subdomain};
  location / {
    proxy_set_header Host ${subdomain};
    proxy_pass http://${container_ip_address}:${WEB_PORT};
  }
}
EOF
  # apply configs
  ${sudo} rm -f /etc/nginx/sites-enabled/${domain}.conf /etc/nginx/sites-enabled/${subdomain}.conf
  ${sudo} mv /tmp/${domain}.conf /etc/nginx/sites-enabled/${domain}.conf
  ${sudo} mv /tmp/${subdomain}.conf /etc/nginx/sites-enabled/${subdomain}.conf
  restart_or_reload_nginx
}

restart_or_reload_nginx()
{
  # The hash bucket size parameter is aligned to the size that is a multiple of the processor’s cache line size.
  # This speeds up key search in a hash on modern processors by reducing the number of memory accesses.
  # If hash bucket size is equal to one processor’s cache line size then the number of memory accesses during the key search
  # will be two in the worst case — first to compute the bucket address, and second during the key search inside the bucket.
  # Therefore, if nginx emits the message requesting to increase either hash max size or hash bucket size
  # then the first parameter should first be increased.
  if [ ! -f /etc/nginx/conf.d/server_names_hash_bucket_size.conf ]; then
    ${sudo} echo "server_names_hash_bucket_size  128;" > /etc/nginx/conf.d/server_names_hash_bucket_size.conf
  fi

  if [[ `service nginx status` == " * nginx is running" ]]; then
    ${sudo} service nginx reload
  else
    ${sudo} service nginx restart
  fi
}

patch_definition_files_and_build()
{
  source_user=`echo "${source_domain}" | awk -F'[.]' '{print $1}'`
  source_domain_name=`echo "${source_domain}" | awk -F"${source_user}." '{print $2}'`
  user=`echo "${domain}" | awk -F'[.]' '{print $1}'`
  domain_name=`echo "${domain}" | awk -F"${user}." '{print $2}'`

  local compose_file="$self_dir/original/docker-compose.yml"
  local template_file="$compose_file.orig"
  local sed_str=""

  cp -f  "$template_file" "$compose_file"

  sed_str="\
    s/SERVICE_NAME_VAR/${domain}_${app}/;
    s/CONTAINER_NAME_VAR/${domain}_${app}/;
    s/NETWORK_NAME_VAR/${domain}_${app}/;
    s/USER_VAR/${user}/;
    s/DOMAIN_VAR/${domain_name}/;
    s/SRC_USER_VAR/${source_user}/;
    s/SRC_DOMAIN_VAR/${source_domain_name}/;
    s/APP_VAR/${app}/;"

  if [ "$app" == "wordpress" ]; then
    sed_str+="s/SEEDAPP_ARCHIVE_VAR/${app}-v4.tgz/;"
  elif [ "$app" == "drupal" ]; then
    sed_str+="s/SEEDAPP_ARCHIVE_VAR/${app}-v7.tgz/;"
  fi

  sed -i "$sed_str" "$compose_file"

  /usr/local/bin/docker-compose -f "$compose_file" up --build -d
  rm -f "$compose_file"
  update_nginx_config
}

docker_get_ids_and_names_of_containers()
{
  if   [ "$operation" == "clone" ]; then
    CONTAINER_WEB_ID=`docker ps|grep ${source_vhost}|awk '{print $1}'`
  elif [ "$operation" == "backup" -o "$operation" == "list_backups" ]; then
    CONTAINER_WEB_ID=`docker ps|grep ${domain}|awk '{print $1}'`
  else
    CONTAINER_WEB_ID=`docker ps|grep ${domain}_${app}_web|awk '{print $1}'`
  fi
  CONTAINER_WEB_NAME=`docker inspect -f '{{.Name}}' ${CONTAINER_WEB_ID}|awk -F'/' '{print $2}'`
}

docker_msf()
{
  if [ `docker ps|grep msf_container|wc -l` -eq 0 ]; then
    if [ `docker ps -a|grep msf_container|wc -l` -gt 0 ]; then docker rm -f msf_container; fi
    docker run -d --name=msf_container msf:v1
  fi
  CONTAINER_MSF_ID=`docker ps|grep msf_container|awk '{print $1}'`
  docker cp ${self_dir}/msf/wmap.rc ${CONTAINER_MSF_ID}:/tmp/wmap.rc
  docker exec ${CONTAINER_MSF_ID} /bin/sh -c "sed -i s/127.0.0.1/${dst_ip_address}/ /tmp/wmap.rc"
  docker exec ${CONTAINER_MSF_ID} /bin/sh -c "TERM=rxvt msfconsole -r /tmp/wmap.rc"
}

detect_running_apache_and_patch_configs()
{
  if [ `ps aux|grep apache2|wc -l` -gt 0 ]; then
    # patch configs with new port
    readarray -t apache_configs_array <<< `find -L /etc/apache2 -name *.conf`
    servernames_array=()
    for i in ${apache_configs_array[@]}; do
      if [ `grep ":80" ${i}|wc -l` -gt 0 -a `grep ":8080" ${i}|wc -l` -eq 0 ]; then
        sed -i 's/:80/:8080/' ${i}
      fi
      if [ `grep "  ServerName " ${i}|wc -l` -gt 0 ]; then
        servernames_array+=(`grep "  ServerName " ${i}|awk -F "  ServerName " '{print $2}'`)
      fi
    done
    # restart apache
    ${sudo} service apache2 restart
    # update nginx configs with apache's hosts
    for servername in ${servernames_array[@]}; do
      # create config
      cat << EOF > /tmp/${servername}.conf
server {
  listen       80;
  server_name  ${servername};
  location / {
    proxy_set_header Host ${servername};
    proxy_pass http://localhost:8080;
  }
}
EOF
      ${sudo} rm -f /etc/nginx/sites-enabled/${servername}.conf
      ${sudo} mv /tmp/${servername}.conf /etc/nginx/sites-enabled/${servername}.conf
    done
    restart_or_reload_nginx
  fi
}

# check for Docker installation
if [ ! -f /usr/bin/docker ]; then
  # quick install for Ubuntu only
  ${sudo} echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list
  ${sudo} apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  ${sudo} apt-get update
  ${sudo} apt-get install -y docker-engine
fi

# check for Docker Compose binary
if [ ! -f /usr/local/bin/docker-compose ]; then
  ${sudo} curl -L https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  ${sudo} chmod +x /usr/local/bin/docker-compose
fi

# build locally or pull image from docker hub
if [ `docker images|grep devpanel_cache|grep latest|wc -l` -eq 0 ]; then
  if [ $build_image ]; then
    docker build -t devpanel_cache:latest "$self_dir/cache"
  else
    docker pull freeminder/devpanel_cache:latest && docker tag freeminder/devpanel_cache:latest devpanel_cache:latest
  fi
fi

# main logic
if [ "$app" == "zabbix" -a "$operation" == "start" -a "$domain" -a "$host_type" == "docker" ]; then
  if [ `docker images|grep devpanel_zabbix|wc -l` -eq 0 ]; then
    if [ $build_image ]; then
      docker build -t devpanel_zabbix:v1 ${self_dir}/zabbix
    else
      docker pull freeminder/devpanel_zabbix:v1
      docker tag freeminder/devpanel_zabbix:v1 devpanel_zabbix:v1
    fi
  fi
  docker run -d -it --name ${domain}_${app}_web devpanel_zabbix:v1
  update_nginx_config

elif [ "$app" == "hippo" -a "$operation" == "start" -a "$domain" -a "$host_type" == "docker" ]; then
  if [ `docker images|grep devpanel_hippo|wc -l` -eq 0 ]; then
    if [ $build_image ]; then
      docker build -t devpanel_hippo:v1 ${self_dir}/hippo
    else
      docker pull freeminder/devpanel_hippo:v1
      docker tag freeminder/devpanel_hippo:v1 devpanel_hippo:v1
    fi
  fi
  docker run -d -it --name ${domain}_${app}_web devpanel_hippo:v1
  update_nginx_config

elif [ "$operation" == "start" -a "$domain" -a "$host_type" ]; then
  if [ "$host_type" == "docker" ]; then
    orig_domain="$domain"
    detect_running_apache_and_patch_configs
    patch_definition_files_and_build
  elif [ "$host_type" == "local" ]; then
    #
    # will be changed to parse /apps.txt in next update
    #
    if [ "$app" == "wordpress" ]; then
      app_arch="wordpress-v4.tgz"
    elif [ "$app" == "drupal" ]; then
      app_arch="drupal-v7.tgz"
    else
      echo "App not supported."
      exit 1
    fi
    # check for downloaded app
    if [ ! -f ${sys_dir}/${app}/${app_arch} ]; then
      ${sudo} mkdir -p ${sys_dir}/${app} && cd ${sys_dir}/${app} && wget https://www.webenabled.com/seedapps/${app_arch} && tar zxvf ${app_arch}
    fi
    vhost=`echo "${domain}" | awk -F'[.]' '{print $1}'`
    domain_name=`echo "${domain}" | awk -F"${vhost}." '{print $2}'`
    ${sudo} ${sys_dir}/libexec/config-vhost-names-default ${domain_name}
    ${sudo} ${sys_dir}/libexec/restore-vhost -F ${vhost} ${sys_dir}/${app}
    detect_running_apache_and_patch_configs
  else
    show_help
  fi
  create_local_config

elif [ "$operation" == "clone" -a "$source_domain" -a "$domain" ]; then
  source_vhost=${source_domain}
  target_vhost=${domain}
  domain="$source_domain"
  read_local_config
  if [ "$app_hosting" == "docker" ]; then
    # parse variables
    source_user=`echo "${source_vhost}" | awk -F'[.]' '{print $1}'`
    source_domain_name=`echo "${source_vhost}" | awk -F"${source_user}." '{print $2}'`
    user=`echo "${target_vhost}" | awk -F'[.]' '{print $1}'`
    domain_name=`echo "${target_vhost}" | awk -F"${user}." '{print $2}'`
    docker_get_ids_and_names_of_containers
    # save current state of containers as images
    docker commit ${CONTAINER_WEB_NAME} ${target_vhost}
    # get ids of images
    IMAGE_WEB_NAME=`docker images|grep ${target_vhost}|awk '{print $1}'`
    docker run -d --name=${target_vhost} ${IMAGE_WEB_NAME}
    while [ `docker ps|grep ${target_vhost}|wc -l` -eq 0 ]; do
      echo "WEB container is not running. Waiting its start."
      sleep 1
    done
    # get destination containers ids
    CONTAINER_WEB_ID=`docker ps|grep ${user}|awk '{print $1}'`

    USER=`awk -F'.' '{print $1}' <<< "$source_vhost"`
    DOMAIN=${source_domain_name}
    DST_USER=${user}
    DST_DOMAIN=${domain_name}
    # update container's apache2 config with new URL
    docker exec ${CONTAINER_WEB_ID} sed -i "s/ServerName ${USER}/ServerName ${DST_USER}/" /etc/apache2/devpanel-virtwww/w_${USER}.conf
    docker exec ${CONTAINER_WEB_ID} sed -i "s/ServerAlias www.${USER}/ServerAlias www.${DST_USER}/" /etc/apache2/devpanel-virtwww/w_${USER}.conf
    docker exec -d ${CONTAINER_WEB_ID} /bin/sh -c "/tmp/startup.sh"
    docker exec ${CONTAINER_WEB_ID} service apache2 restart

    # replace db data with new URL
    app="wordpress"
    PORT=4000
    PASSWORD=`docker exec ${CONTAINER_WEB_ID} grep w_${USER} /home/clients/websites/w_${USER}/.mysql.passwd|awk -F ":" '{print $2}'`
    while [ `docker exec ${CONTAINER_WEB_ID} /bin/sh -c "netstat -ltpn|grep 4000|wc -l"` -eq 0 ]; do
      echo "DB is not running. Waiting its start."
      sleep 1
      docker exec ${CONTAINER_WEB_ID} mysql ${app} -h localhost -P ${PORT} -u w_${USER} --password=${PASSWORD} --socket=/home/clients/databases/b_${USER}/mysql/mysql.sock -e \
        "UPDATE wp_options SET option_value = replace(option_value, 'http://${USER}.${DOMAIN}', 'http://${DST_USER}.${DST_DOMAIN}');"
    done
    docker exec ${CONTAINER_WEB_ID} mysql ${app} -h localhost -P ${PORT} -u w_${USER} --password=${PASSWORD} --socket=/home/clients/databases/b_${USER}/mysql/mysql.sock -e \
      "UPDATE wp_options SET option_value = replace(option_value, 'http://${USER}.${DOMAIN}', 'http://${DST_USER}.${DST_DOMAIN}');"

    # check if it was replaced correctly
    if [ `docker exec ${CONTAINER_WEB_ID} mysql ${app} -h localhost -P ${PORT} -u w_${USER} --password=${PASSWORD} --socket=/home/clients/databases/b_${USER}/mysql/mysql.sock -e \
      "select * from wp_options;"|grep -c ${DST_USER}` -eq 2 ]; then
        echo "DB cloned correctly."
    else
        echo "Error: URL was not replaced correctly in MySQL."
        exit 1
    fi

    # update host's nginx config with new IP of cloned web container
    domain="${target_vhost}"
    create_local_config
    app_clone="true"
    app_container_name="${target_vhost}"
    update_nginx_config ${target_vhost}
  elif [ "$app_hosting" == "local" ]; then
    # clone_vhost_local||libexec/clone-vhost-local|%source_vhost% %target_vhost%|
    ${sys_dir}/libexec/clone-vhost-local "$source_vhost" "$target_vhost"
    create_local_config
    update_nginx_config ${target_vhost}
  else
    show_help
    exit 1
  fi

elif [ "$operation" == "backup" -a "$backup_name" -a "$domain" ]; then
  read_local_config
  if [ "$app_hosting" == "docker" ]; then
    # get ids of current containers
    docker_get_ids_and_names_of_containers

    docker exec ${CONTAINER_WEB_ID} ${sys_dir}/libexec/archive-vhost "$vhost" "$backup_name"

    # # save current state of containers as images
    # docker commit ${CONTAINER_WEB_NAME} ${domain}_${backup_name}_bkp_web
  elif [ "$app_hosting" == "local" ]; then
    # archive_vhost||libexec/archive-vhost|%vhost% %filename%|
    ${sys_dir}/libexec/archive-vhost "$vhost" "$backup_name"
  else
    show_help
    exit 1
  fi

elif [ "$operation" == "list_backups" ]; then
  read_local_config
  if [ "$app_hosting" == "docker" ]; then
    # get ids of current containers
    docker_get_ids_and_names_of_containers
    docker exec ${CONTAINER_WEB_ID} ${sys_dir}/bin/list-backups
  elif [ "$app_hosting" == "local" ]; then
    # 88|list_backups||bin/list-backups|--|0.0|0|2013-10-07 19:23:31|2013-10-07 22:00:53
    ${sys_dir}/bin/list-backups
  else
    show_help
    exit 1
  fi

elif [ "$operation" == "restore" -a "$restore_name" -a "$domain" ]; then
  read_local_config
  if [ "$app_hosting" == "docker" ]; then
    # get ids of current containers
    docker_get_ids_and_names_of_containers
    # remove source containers to avoid name conflicts
    docker rm -f ${CONTAINER_WEB_ID}
    # get ids of images
    IMAGE_WEB_NAME=`docker images|grep ${domain}_${restore_name}_bkp_web|awk '{print $1}'`
    # start backed up containers
    docker run -d --name=${CONTAINER_WEB_NAME} ${IMAGE_WEB_NAME}
    while [ `docker ps|grep ${domain}|wc -l` -eq 0 ]; do
      echo "WEB container is not running. Waiting its start."
      sleep 1
    done
    # update nginx config with new IP of web container
    update_nginx_config ${CONTAINER_WEB_NAME}
  elif [ "$app_hosting" == "local" ]; then
    # restore_vhost||libexec/restore-vhost|%vhost% %filename%|
    ${sys_dir}/libexec/restore-vhost "$vhost" "$restore_name"
  else
    show_help
    exit 1
  fi

elif [ "$operation" == "scan" -a "$domain" -a "$host_type" == "docker" ]; then
  # get ids of current containers
  docker_get_ids_and_names_of_containers
  # get ip_address of webapp
  dst_ip_address=`docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)|grep "${CONTAINER_WEB_NAME}"|awk -F" - " '{print $2}'`
  # check if msf container exists
  if [ `docker images|grep msf|wc -l` -eq 0 ]; then
    if [ $build_image ]; then
      docker build -t msf:v1 ${self_dir}/msf
    else
      docker pull freeminder/msf:v1
      docker tag freeminder/msf:v1 msf:v1
    fi
  fi
  # do the scan
  docker_msf

elif [ "$operation" == "destroy" -a "$domain" ]; then
  read_local_config
  if [[ "$app_hosting" == "docker" ]]; then
    docker rm  -f ${app_container_name}
    if [ "$app" == "zabbix" -o "$app" == "hippo" ]; then
      docker rmi -f devpanel_${app}:v1
    elif [[ "$app_clone" == "true" ]]; then
      docker rmi -f ${app_container_name}
    else
      docker rmi -f original_${app_container_name}
    fi
    # remove backups also if requested
    if [ $remove_backups ]; then
      readarray -t backups_array <<< `docker images|grep ${domain}|awk '{print $1}'`
      for i in ${backups_array[@]}; do
        docker rmi -f ${i}
      done
    fi
  elif [[ "$app_hosting" == "local" ]]; then
    # remove_vhost||libexec/remove-vhost|%vhost% %filename%|
    ${sys_dir}/libexec/remove-vhost ${vhost}
  else
    show_help
    exit 1
  fi
  # remove config from nginx
  ${sudo} rm -f /etc/nginx/sites-enabled/${domain}*.conf
  restart_or_reload_nginx
  ${sudo} rm -f ${sys_dir}/config/apps/${domain}.ini
  ${sudo} rm -f ${sys_dir}/config/apps/${vhost}.ini

elif [ "$operation" == "handle" -a "$handler_options" ]; then
  controller_handler

elif [ "$domain" -a "$read_config" ]; then
  read_local_config
  echo "$app_hosting"

else
  show_help
  exit 1
fi


Fix gen_git_version script not being able to find git binary.

This error is happening on our Window's release builds. Making sure
we add git binary to the PATH for Bazel.

#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# This script assumes the standard setup on tensorflow Jenkins windows machines.
# It is NOT guaranteed to work on any other machine. Use at your own risk!
#
# REQUIREMENTS:
# * All installed in standard locations:
#   - JDK8, and JAVA_HOME set.
#   - Microsoft Visual Studio 2015 Community Edition
#   - Msys2
#   - Anaconda3
# * Bazel windows executable copied as "bazel.exe" and included in PATH.

# Use a temporary directory with a short name.
export TMPDIR="C:/tmp"
mkdir -p "$TMPDIR"

# Set bash path
export BAZEL_SH=${BAZEL_SH:-"C:/tools/msys64/usr/bin/bash"}

export PYTHON_BASE_PATH="${PYTHON_DIRECTORY:-Program Files/Anaconda3}"

# Set the path to find bazel.
export PATH="/c/tools/bazel/:$PATH"

# Set Python path for ./configure
export PYTHON_BIN_PATH="C:/${PYTHON_BASE_PATH}/python.exe"
export PYTHON_LIB_PATH="C:/${PYTHON_BASE_PATH}/lib/site-packages"

# Add python into PATH, it's needed because gen_git_source.py uses
# '/usr/bin/env python' as a shebang
export PATH="/c/${PYTHON_BASE_PATH}:$PATH"
# Add git into PATH needed for gen_git_source.py
export PATH="/c/Program Files/Git/cmd:$PATH"

# Make sure we have pip in PATH
export PATH="/c/${PYTHON_BASE_PATH}/Scripts:$PATH"

# Add Cuda and Cudnn dll directories into PATH
export PATH="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin:$PATH"
export PATH="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/extras/CUPTI/libx64:$PATH"
export PATH="/c/tools/cuda/bin:$PATH"

#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# This script assumes the standard setup on tensorflow Jenkins windows machines.
# It is NOT guaranteed to work on any other machine. Use at your own risk!
#
# REQUIREMENTS:
# * All installed in standard locations:
#   - JDK8, and JAVA_HOME set.
#   - Microsoft Visual Studio 2015 Community Edition
#   - Msys2
#   - Anaconda3
# * Bazel windows executable copied as "bazel.exe" and included in PATH.

# Use a temporary directory with a short name.
export TMPDIR="C:/tmp"
mkdir -p "$TMPDIR"

# Set bash path
export BAZEL_SH=${BAZEL_SH:-"C:/tools/msys64/usr/bin/bash"}

export PYTHON_BASE_PATH="${PYTHON_DIRECTORY:-Program Files/Anaconda3}"

# Set the path to find bazel.
export PATH="/c/tools/bazel/:$PATH"

# Set Python path for ./configure
export PYTHON_BIN_PATH="C:/${PYTHON_BASE_PATH}/python.exe"
export PYTHON_LIB_PATH="C:/${PYTHON_BASE_PATH}/lib/site-packages"

# Add python into PATH, it's needed because gen_git_source.py uses
# '/usr/bin/env python' as a shebang
export PATH="/c/${PYTHON_BASE_PATH}:$PATH"

# Make sure we have pip in PATH
export PATH="/c/${PYTHON_BASE_PATH}/Scripts:$PATH"

# Add Cuda and Cudnn dll directories into PATH
export PATH="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/bin:$PATH"
export PATH="/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.0/extras/CUPTI/libx64:$PATH"
export PATH="/c/tools/cuda/bin:$PATH"


Fixed output issues webith websearch plugin.

- if user has rm set as an alias to 'rm -i' user is prompted to whether to
  remove the nohup.out file.

 $ ddg fools
	nohup: ignoring input and appending output to ‘nohup.out’
	rm: remove regular empty file ‘nohup.out’?

- if output redirected to a file nohup will not create nohup.out and rm is
  unecessary.

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/takady/oh-my-zsh.git/'


Don't "exit" at the end of the postinstall cleanup 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/runsystem-hiennt2/bento.git/'


better messages

better messages

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/ginkoms/zipSeries.git/'


Added duplicate post

Added duplicate post

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/sdellow/wp-framework.git/'


Add a plugin for systemadmin ops and developer

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/joeylomanto/oh-my-zsh.git/'


adding install.sh

adding install.sh

mkdir build
cd build
wget https://mpi4py.googlecode.com/files/mpi4py-1.3.tar.gz
tar xzvf mpi4py-1.3.tar.gz
cd mpi4py-1.3
#module purge
#module load python/2.7.2 numpy/1.6.1 mpi-tor/openmpi-1.4.5_gcc-4.4.6
TODO: add aciss configure profile
python setup.py build --mpi=aciss
#python setup.py install --user

echo 'add this to your path:'
#export PATH=$PATH:~/MATLAByrinth-install/MATLABYrinth/bin
echo 'Also set the MATLABYRINT environment variable:'

#export MATLABYRINTH='~/MATLAByrinth-install/MATLAByrinth'

echo 'If it does not exist, create the following directory and file:'
#    ~/Documents/MATLAB/startup.m

echo 'and append this line to the startup.m file:'
#    addpath ~/MATLAByrinth-install/MATLABYrinth/src/matlab

#Refer to the MATLAByrinth README file to see how to test the installation.

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


[emacs]: switched to symlink for doom configuration

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/dive/dotfiles.git/'


add greplace

add greplace

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/ryanburnette/dotfiles.git/'


Fixed copying of config.js when upgrading

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/samklr/metrilyx-2.0.git/'


Random password generator

Random password generator

#!/bin/bash

## allow length specification
LENGTH="$1"
if [ -z "$1" ]; then
	LENGTH=12
fi;

## Generate by pulling random characters.
PASS=`< /dev/urandom tr -dc "_A-Z-a-z-0-9#.@%=+*" | head -c${LENGTH}`

## don't emit a newline (\n), that might mess other things that take this as an input
echo -n "$PASS"

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


combined creator

combined creator

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/bborbe/db_utils.git/'


Enable testing of logic module in the respective block

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/kaushik94/sympy.git/'


added plugin to control macports mysql-server installation

# commands to control local mysql-server installation
# paths are for osx installtion via macports

alias mysqlstart='sudo /opt/local/bin/mysqld_safe5'
alias mysqlstop='/opt/local/bin/mysqladmin5 -u root -p shutdown'
alias mysqlstatus='mysqladmin5 -u root -p ping'

error: pathspec 'plugins/mysql-macports.plugin.zsh' did not match any file(s) known to git


Script for sandboxed installation of Haskell packages

This script is a wrapper cabal or cabal-dev (depending on command line options
and availability of the commands on the system).

Usage:
  install-in-sandbox.sh [-C|-c] [-w WORKING_DIR] [SANDBOX_DIR] [-- CABAL_OPTIONS]
  install-in-sandbox.sh {-h|--help}

Example for installing cabal-dev in a sandbox:

  $ install-in-sandbox.sh /opt/cabal-dev/0.9.2 -- cabal-dev-0.9.2

#!/bin/bash

# Copyright (c) 2013, Peter Trsko <peter.trsko@gmail.com>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#
#     * Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#
#     * Neither the name of Peter Trsko nor the names of other
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

DEFAULT_WORKING_DIR='.'
DEFAULT_SANDBOX_DIR='sandbox' # Relative to DEFAULT_WORKING_DIR

printHelp() {
    cat << EOF
Usage:
  ${0##*/} [-C|-c] [-w WORKING_DIR] [SANDBOX_DIR] [-- CABAL_OPTIONS]
  ${0##*/} {-h|--help}

Options:

-C, --cabal-install
  Use cabal-install for installation.

  Default if cabal-dev is not installed.

-c, --cabal-dev
  Use cabal-dev for installation.

  Default if cabal-dev is installed.

-w WORKING_DIR, --working-dir=WORKING_DIR
  Change working directory to WORKING_DIR before calling cabal-install or
  cabal-dev. This option is useful if you use this script via Ansible to
  prepare the environment.

  Default value is ".".

-h, --help
  Print this help and exit.

SANDBOX_DIR
  Directory where the sandbox directory will be installed. If this directory
  doesn't exist it will be created. If the path starts with '/' it's used as
  is, otherwise "\$WORKING_DIR/\$SANDBOX_DIR" is used. Don't use relative path
  starting with "." or ".." directory, rather use something like
  "\`pwd\`/foo-bar" or "\`pwd\`/../foo-bar".

  Default value is: "\$WORKING_DIR/$DEFAULT_SANDBOX_DIR".

CABAL_OPTIONS
  Options passed down to "cabal install" or "cabal-dev install".
EOF
}

error() {
    local RC=$1; shift

    echo "ERROR:" "$@" 1>&2
    if [ $RC -eq 1 ]; then
        echo 1>&2
        printHelp 1>&2
    fi
    exit $RC
}

isCommandAvailable() {
    which "$1" 2>&1 > /dev/null
}

isImplAvailable() {
    local CMD=''

    case "$1" in
      'cabal-dev') CMD='cabal-dev';;
      'cabal-install') CMD='cabal';;
    esac

    isCommandAvailable "$CMD"
}

getImpl() {
    if [ -z "$1" ]; then
        for I in 'cabal-dev' 'cabal-install'; do
            if isImplAvailable "$I"; then
                echo "$I"
                return 0
            fi
        done
    elif isImplAvailable "$1"; then
        echo "$1"
        return 0
    fi

    return 1
}

canonicalizePath()
{
    readlink -f "$1"
}

cabalInstallMain() {
    local WD="$1"; shift
    local INSTALL_DIR="$1"; shift
    local PACKAGES_CONF=''

    for CMD in 'ghc' 'ghc-pkg'; do
        if ! isCommandAvailable "$CMD"; then
            error 2 "$CMD" 'not found, this command is required while' \
                ' compiling using cabal-install'
        fi
    done

    mkdir "$INSTALL_DIR"
    INSTALL_DIR="`canonicalizePath "$INSTALL_DIR"`"
    PACKAGES_CONF="$INSTALL_DIR/packages-`ghc --numeric-version`.conf"
    ghc-pkg init "$PACKAGES_CONF"
    (
        cd "$WD"
        cabal install \
            --prefix="$INSTALL_DIR" \
            --package-db="$PACKAGES_CONF" \
            "$@"
    )
}

cabalDevMain() {
    local WD="$1"; shift
    local INSTALL_DIR="$1"; shift

    (
        cd "$WD"
        cabal-dev install \
            --sandbox="$INSTALL_DIR" \
            "$@"
    )
}

# Main ########################################################################

FORCE_IMPL=''
END_OF_OPTIONS=0
while [ $# -gt 0 -a $END_OF_OPTIONS -ne 1 ]; do
    case "$1" in
      '-C'|'--cabal-install')
        FORCE_IMPL='cabal-install'
        ;;
      '-c'|'--cabal-dev')
        FORCE_IMPL='cabal-dev'
        ;;
      '-w'|'--working-dir'|'--working-dir='*)
        if [ "$1" = '-w' -o "$1" = "--working-dir" ]; then
            shift
            WORKING_DIR="$1"
        else
            WORKING_DIR="${1#--working-dir=}"
        fi
        ;;
      '-h'|'--help'|'-help')
        printHelp
        exit 0
        ;;
      '--')
        END_OF_OPTIONS=1
        ;;
      -*)
        error 1 'Unknown option' "'$1'"
        ;;
      *)
        [ -n "$SANDBOX_DIR" ] && error 1 "SANDBOX_DIR already specified."
        SANDBOX_DIR="$1"
        ;;
    esac
    shift
done

if [ -z "$WORKING_DIR" ]; then
    WORKING_DIR="$DEFAULT_WORKING_DIR"
fi

if [ -z "$SANDBOX_DIR" ]; then
    SANDBOX_DIR="$WORKING_DIR/$DEFAULT_SANDBOX_DIR"
elif [ "`echo "$SANDBOX_DIR" | head -c 1`" != '/' ]; then
    SANDBOX_DIR="$WORKING_DIR/$SANDBOX_DIR"
fi

IMPL="`getImpl "$FORCE_IMPL"`" || {
    if [ -z "$FORCE_IMPL" ]; then
        error 2 "$FORCE_IMPL not found."
    else
        error 2 'Neither cabal-dev nor cabal-install was found.'
    fi
}

case "$IMPL" in
  'cabal-install')
    cabalInstallMain "$WORKING_DIR" "$SANDBOX_DIR" "$@"
    ;;
  'cabal-dev')
    cabalDevMain "$WORKING_DIR" "$SANDBOX_DIR" "$@"
    ;;
  *)
    error 2 'Unknown installation tool' "'$IMPL'," \
        'please consider sending a bug request.'
    ;;
esac

# vim:ts=4:sw=4:expandtab

error: pathspec 'scripts/install-in-sandbox.sh' did not match any file(s) known to git


Create volumes script added

Create volumes script added

#!/usr/bin/env bash

if ! docker volume ls -q | grep -l '^certs\-volume$' > /dev/null ; then
	echo 'Creating certs-volume'
	docker volume create certs-volume > /dev/null
else
	echo 'certs-volume already exists'
fi

if ! docker volume ls -q | grep -l '^webroot\-volume$' > /dev/null ; then
	echo 'Creating webroot-volume'
	docker volume create webroot-volume > /dev/null
else
	echo 'webroot-volume already exists'
fi

if ! docker volume ls -q | grep -l '^conf\-volume$' > /dev/null ; then
	echo 'Creating conf-volume'
	docker volume create conf-volume > /dev/null
else
	echo 'conf-volume already exists'
fi

exit

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


Add DOCKER_CONTAINER_BUILD_SH_PREFIX.

Add DOCKER_CONTAINER_BUILD_SH_PREFIX.

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/dynatrace-innovationlab/easyTravel-Builder.git/'


Thu 13 of Dec of 2018 at 17:47:53

Thu 13 of Dec of 2018 at 17:47:53

#!/usr/bin/env bash

RED='\033[00;31m'
GREEN='\033[00;32m'
CYAN='\033[00;36m'
WHITE='\033[01;37m'

END=$'\e[0m'

function log() {
  printf "\n${WHITE}%s${END}\n" "$*"
}

function info() {
  printf "\n${CYAN}%s${END}\n" "$*"
}

current_date=$(date '+%d/%m/%Y %H:%M:%S')
employer_id="${EMPLOYER_ID}"

info "What's your PIN?"
read employee_pin

if ! test -n "${employer_id}"; then
  info "What's the employer code?"
  read employer_id
fi

if test -n "${employer_id}" && test -n "${employee_pin}"; then
  employee_id=$(wget -qO- https://app.tangerino.com.br/Tangerino/ws/fingerprintWS/funcionario/empregador/${employer_id}/pin/${employee_pin} | python -m json.tool | sed '15!d' | grep -Eo "[0-9]{1,}")

  curl -X POST https://app.tangerino.com.br/Tangerino/ws/pontoWS/ponto/sincronizacaoPontos/1.2 \
    -H "Content-Type: application/json" \
    -H "EMPREGADOR: ${employer_id}" \
    -H "pin: ${employee_pin}" \
    -H "funcionarioid: ${employee_id}" \
    -H "USERNAME: ${employee_id}" \
    --basic \
    --user "${employer_id}:${employee_id}" \
    -d @- << EOF
{
    "horaInicio": "${current_date}",
    "deviceId": 9,
    "online": "true",
    "codigoEmpregador": "${employer_id}",
    "pin": ${employee_pin},
    "horaFim": "",
    "tipo": "WEB",
    "foto": "",
    "intervalo": "",
    "versao": "registra-ponto-finguerprint",
    "plataforma": "WEB",
    "funcionarioid": ${employee_id},
    "idAtividade": 6
  }
EOF
else
  error "Employer ID or Employee PIN not set!"
fi

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


Force the push when the -p is used.

Force the push when the -p is used.

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/swiftcode/git-scripts.git/'


Update macos script

Update macos 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/markphelps/dotfiles.git/'


nohup wrapper

nohup wrapper

# Copyright © 2018 Feature.su. All rights reserved
# Licensed under the Apache License, Version 2.0

if [ -z $1  ]
then
echo "Usage for long time command: sh long-time-command.sh \"cp -R /mnt/folder /var/folder\""
exit 0;
fi

nohup $1 &

error: pathspec 'script/centos7/long-time-command.sh' did not match any file(s) known to git


script to train w/ all of imnet val

script to train w/ all of imnet val

#!/bin/sh
(scripts/build_db.py caffenet_imnet_val conv1 --gpu 0 &)
(scripts/build_db.py caffenet_imnet_val conv2 --gpu 1 &)
(scripts/build_db.py caffenet_imnet_val conv3 --gpu 2 &)
(scripts/build_db.py caffenet_imnet_val conv4 --gpu 3 &)
(scripts/build_db.py caffenet_imnet_val conv5 --gpu 4 &)

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


Add a crude script to simulate e2e tests

#!/usr/bin/env bash

# This is a real crude script to simulate an e2e test of our container

URL=$1
CODE=$(curl -I "$URL" 2>/dev/null | head -n 1 | cut -d$' ' -f2)

if [ "$CODE" == "200" ]; then
  exit 0
fi
exit 1

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


[#6388] wrapper script to run call_counts.py for a range of git commits

#!/bin/bash

if [[ $@ ]]
then
    revs=$@
else
    revs='HEAD -n 10'
    echo "No git revision range given, using $revs"
    echo "Other range formats like bdde98d..HEAD work too"
    echo
fi

current=`git rev-parse --abbrev-ref HEAD`
git rev-list --reverse $revs --oneline | while read commit
do
    echo $commit
    sha=${commit:0:7}
    git checkout -q $sha || { echo "Could not check out $sha, stopping.  You started on $current"; break; }
    ./call_count.py --id "$commit"
done
git checkout -q $current

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


perms on ivpn dir

perms on ivpn dir

#!/bin/bash
chown -R engines.containers /opt/engines/run/services/ivpn

error: pathspec 'system/updates/to_run/system/24/updater.sh' did not match any file(s) known to git


add set-same-ange.sh

add set-same-ange.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/team-diana/scripts.git/'


add createEmptyClassFiles.sh

add createEmptyClassFiles.sh

echo "$1"
echo "
#ifndef MyClass_hh
#define MyClass_hh

class MyClass
{
  public:
    MyClass();
    ~MyClass();

  private:
};
#endif" > MyClass.hh

echo "
#include "./MyClass.hh"

MyClass::MyClass()
{}

MyClass::~MyClass()
{}" > MyClass.cc

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


readded merge.sh

readded merge.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/jakebair/links.git/'


Add simple Stack commands list

Add simple Stack commands list

function stack_sandbox_info() {
    stack_files=(*.stack(N))
    if [ $#stack_files -gt 0 ]; then
        if [ -f stack.sandbox.config ]; then
            echo "%{$fg[green]%}sandboxed%{$reset_color%}"
        else
            echo "%{$fg[red]%}not sandboxed%{$reset_color%}"
        fi
    fi
}

function _stack_commands() {
    local ret=1 state
    _arguments ':subcommand:->subcommand' && ret=0

    case $state in
      subcommand)
        subcommands=(
          "build:Build the project(s) in this directory/configuration"
          "install:Build executables and install to a user path"
          "test:Build and test the project(s) in this directory/configuration"
          "bench:Build and benchmark the project(s) in this directory/configuration"
          "haddock:Generate haddocks for the project(s) in this directory/configuration"
          "new:Create a brand new project"
          "init:Initialize a stack project based on one or more stack packages"
          "solver:Use a dependency solver to try and determine missing extra-deps"
          "setup:Get the appropriate ghc for your project"
          "path:Print out handy path information"
          "unpack:Unpack one or more packages locally"
          "update:Update the package index"
          "upgrade:Upgrade to the latest stack (experimental)"
          "upload:Upload a package to Hackage"
          "dot:Visualize your project's dependency graph using Graphviz dot"
          "exec:Execute a command"
          "ghc:Run ghc"
          "ghci:Run ghci in the context of project(s)"
          "ide:Run ide-backend-client with the correct arguments"
          "runghc:Run runghc"
          "clean:Clean the local packages"
          "docker:Subcommands specific to Docker use"
        )
        _describe -t subcommands 'stack subcommands' subcommands && ret=0
    esac

    return ret
}

compdef _stack_commands stack

error: pathspec 'plugins/stack/stack.plugin.zsh' did not match any file(s) known to git


add production bootstrap script.

add production bootstrap script.

#!/usr/bin/env sh

# Bootstraps the repository and installs Salt.

PROJECT_NAME=jitsi-meet-server
SALT_GIT_TAG=v2014.7.6

HOSTNAME=`hostname`

apt-get -y install git
mkdir -p /var/local/git
cd /var/local/git && git clone https://github.com/unhangout/${PROJECT_NAME}.git
ln -s /var/local/git/${PROJECT_NAME}/salt /srv/salt
cd && wget -O install_salt.sh https://bootstrap.saltstack.com && sh install_salt.sh -P git ${SALT_GIT_TAG} && systemctl disable salt-minion.service && systemctl stop salt-minion.service
cp /var/local/git/${PROJECT_NAME}/production/salt/minion /etc/salt/
sed -i.bak "s%###SALT_MINION_ID###%${HOSTNAME}%g" /etc/salt/minion
rm /etc/salt/minion.bak
cp /var/local/git/${PROJECT_NAME}/production/salt/grains.conf /etc/salt/minion.d/

echo "
If you see no error messages, the bootstrap was successful. Follow the
instructions in INSTALL.md for configuring pillar data and SSL certs, then
run the following command to complete the installation:

  salt-call state.highstate
"

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


Add new build script to support php

Add new build script to support php

#!/bin/bash

#MACHINE=avalon
MACHINE=avalon2                         # Support Avalon2/MM firmware

#AVA_TARGET_BOARD=tl-wr703n-v1   # TP-Link WR703N-v1
#AVA_TARGET_BOARD=tl-wr1043nd-v2 # TP-Link WR1043ND-v2
#AVA_TARGET_BOARD=pi-modelb-v2   # Raspberry-Pi ModelB-v2
[ -z "${AVA_TARGET_BOARD}" ]  && AVA_TARGET_BOARD=tl-wr703n-v1  # TP-Link WR703N-v1

OPENWRT_CONFIG=""
[ "${AVA_TARGET_BOARD}" == "tl-wr703n-v1" ] && AVA_TARGET_PLATFORM=ar71xx && OPENWRT_CONFIG=config.${MACHINE}.703n
[ "${AVA_TARGET_BOARD}" == "tl-wr1043nd-v2" ] && AVA_TARGET_PLATFORM=ar71xx && OPENWRT_CONFIG=config.${MACHINE}.1043nd-v2
[ "${AVA_TARGET_BOARD}" == "pi-modelb-v2" ] && AVA_TARGET_PLATFORM=brcm2708 && OPENWRT_CONFIG=config.${MACHINE}.raspberry-pi
[ -z "${OPENWRT_CONFIG}" ] && echo "[ERROR]: Target board not suported" && exit 1

which wget > /dev/null && DL_PROG=wget && DL_PARA="-nv -O"
which curl > /dev/null && DL_PROG=curl && DL_PARA="-L -o"

VERSION=20140415
OPENWRT_PATH=./openwrt
LUCI_PATH=./luci

# According to http://wiki.openwrt.org/doc/howto/build
unset SED
unset GREP_OPTIONS
[ "`id -u`" == "0" ] && echo "[ERROR]: Please use non-root user" && exit 1
CORE_NUM="$(expr $(nproc) + 1)"
[ -z "$CORE_NUM" ] && CORE_NUM=2

## Version
if [ "$#" == "0" -a ! -d ./avalon ]; then
    $0 --help
    exit 0
elif [ "$1" == "--version" ] || [ "$1" == "--help" ]; then
    echo "\

Usage: $0 [--version] [--help] [--clone] [--build] [--update] [--cgminer]

     --version
     --help             Display help message

     --clone            Get all source code, ONLY NEED ONCE

     --build            Get .config file and build firmware

     --update           Update all repos

     --cgminer          Re-compile only cgminer openwrt package

Without any parameter I will build the Avalon firmware. make sure you run
  [$0 --clone] ONCE for get all sources

     --removeall        Remove all files

     AVA_TARGET_BOARD   Environment variable, available target:
                        tl-wr703n-v1, tl-wr1043nd-v2, pi-modelb-v2
                        use tl-wr703n-v1 if unset

Written by: Xiangfu <xiangfu@openmobilefree.net>
                    19BT2rcGStUK23vwrmF6y6s3ZWpxzQQn8x

                                                     Version: ${VERSION}"
    exit 0
fi

## Remove
if [ "$1" == "--removeall" ]; then
    rm -rf avalon/cgminer avalon/cgminer-openwrt-packages/ avalon/luci/ avalon/openwrt/
    exit $?
fi

## Init
if [ "$1" == "--clone" ]; then
    [ ! -d avalon ] && mkdir -p avalon/bin
    cd avalon
    svn co svn://svn.openwrt.org/openwrt/trunk@41240 openwrt
    git clone git://github.com/Canaan-Creative/cgminer.git
    git clone git://github.com/Canaan-Creative/cgminer-openwrt-packages.git

    if [ "${MACHINE}" == "avalon2" ]; then
        (cd cgminer && git checkout -b avalon2 origin/avalon2)
        git clone git://github.com/Canaan-Creative/luci.git && (cd luci && git checkout -b cgminer-webui-avalon2 origin/cgminer-webui-avalon2)
    else
        git clone git://github.com/Canaan-Creative/luci.git && (cd luci && git checkout -b cgminer-webui origin/cgminer-webui)
    fi

    cd openwrt
    [ -d ../../dl ] && ln -sf ../dl ../dl
    [ ! -e ../dl ] && mkdir ../dl
    ln -sf ../dl
    $DL_PROG https://raw.github.com/Canaan-Creative/cgminer-openwrt-packages/php/cgminer/data/feeds.conf $DL_PARA feeds.conf
    ./scripts/feeds update -a && ./scripts/feeds install -a

    ln -s feeds/cgminer/cgminer/root-files files
    exit 0
fi

if [ "$1" == "--build" ]; then
    if [ ! -d avalon/openwrt ]; then
        "$0" --removeall
        "$0" --clone
        [ "$?" != "0" ] && echo "[ERROR]: clone failed" && exit 1
    fi
    cd avalon/openwrt/
    make clean
    cp ./feeds/cgminer/cgminer/data/${OPENWRT_CONFIG} .config
    yes "" | make oldconfig
    make -j${CORE_NUM} V=s IGNORE_ERRORS=m || make V=s IGNORE_ERRORS=m
    exit $?
fi

## Update all git
if [ "$1" == "--update" ]; then
    (cd avalon/cgminer && git pull)
    (cd avalon/luci    && git pull)
    (cd avalon/cgminer-openwrt-packages && git pull)
    cd avalon/openwrt
    ./scripts/feeds update cgminer; ./scripts/feeds install -a -p cgminer
    cp ./feeds/cgminer/cgminer/data/${OPENWRT_CONFIG} .config
    yes "" | make oldconfig
    exit $?
fi

## Rebuild cgminer
cd avalon
make -j${CORE_NUM} -C ${OPENWRT_PATH} package/cgminer/{clean,compile} V=s || make -C ${OPENWRT_PATH} package/cgminer/{clean,compile} V=s
RET="$?"
if [ "${RET}" != "0" ] || [ "$1" == "--cgminer" ]; then
    if [ "${RET}" == "0" ]; then
        mkdir -p bin/${AVA_TARGET_BOARD}
        cp ${OPENWRT_PATH}/bin/${AVA_TARGET_PLATFORM}/packages/cgminer*.ipk  bin/${AVA_TARGET_BOARD}
        cp ${OPENWRT_PATH}/build_dir/target-*uClibc-*/cgminer-*/cgminer bin/${AVA_TARGET_BOARD}/cgminer-${AVA_TARGET_PLATFORM}
        exit "$?"
    fi
    exit "${RET}"
fi

## Build the Web UI & OpenWrt
DATE=`date +%Y%m%d`
## Get all repo commit for Avalon version file /etc/avalon_version
GIT_VERSION=`cd cgminer && git rev-parse HEAD | cut -c 1-7`
if [ ! -z "`cd cgminer && git status -s -uno`" ]; then
    GIT_STATUS="+"
fi

LUCI_GIT_VERSION=`cd luci && git rev-parse HEAD | cut -c 1-7`
if [ ! -z "`cd luci && git status -s -uno`" ]; then
    LUCI_GIT_STATUS="+"
fi

OW_GIT_VERSION=`cd cgminer-openwrt-packages && git rev-parse HEAD | cut -c 1-7`
if [ ! -z "`cd cgminer-openwrt-packages && git status -s -uno`" ]; then
    OW_GIT_STATUS="+"
fi

rm -rf ${LUCI_PATH}/applications/luci-cgminer/dist                                                              && \
( make -j${CORE_NUM} -C ${LUCI_PATH} || make -C ${LUCI_PATH} )                                                  && \
cp -a  ${LUCI_PATH}/applications/luci-cgminer/dist/* ${OPENWRT_PATH}/files/                                     && \
echo "$DATE"                                                    >  ${OPENWRT_PATH}/files/etc/avalon_version     && \
echo "cgminer: $GIT_VERSION$GIT_STATUS"                         >> ${OPENWRT_PATH}/files/etc/avalon_version     && \
echo "cgminer-openwrt-packages: $OW_GIT_VERSION$OW_GIT_STATUS"  >> ${OPENWRT_PATH}/files/etc/avalon_version     && \
echo "luci: $LUCI_GIT_VERSION$LUCI_GIT_STATUS"                  >> ${OPENWRT_PATH}/files/etc/avalon_version     && \
( make -j${CORE_NUM} -C ${OPENWRT_PATH} V=s IGNORE_ERRORS=m || make -C ${OPENWRT_PATH} V=s IGNORE_ERRORS=m )    && \
mkdir -p bin/${AVA_TARGET_BOARD}/${DATE}/                                                                       && \
cp -a ${OPENWRT_PATH}/bin/${AVA_TARGET_PLATFORM}/*  bin/${AVA_TARGET_BOARD}/${DATE}/

error: pathspec 'scripts/build-avalon-image-php.sh' did not match any file(s) known to git


bugfix

bugfix

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/szilvajuhos/CAW.git/'


jenv requirements

jenv requirements

#!/bin/bash

#
#   Copyright 2012 Jacky Chan
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

# display jenv version
function __jenvtool_requirements {
	echo "jenv requirements"
	echo "====================================================="
	for cmdName in complete sed grep tar unzip curl git svn
	do
	   type $cmdName >/dev/null 2>&1
	   if [ "$?" -eq "0" ] ; then
	      printf "\e[32m%12s %15s\e[00m\n" "${cmdName}" "Available"
	   else
	      printf "\e[31m%12s %15s\e[00m\n" "${cmdName}" "Unavailable"
	   fi
	done
}

error: pathspec 'src/main/scripts/commands/jenv-requirements.sh' did not match any file(s) known to git


Adds host names to /etc/hosts

Adds host names to /etc/hosts

error: pathspec 'final_installation/terminal_server/08_install_hosts.sh' did not match any file(s) known to git


add server stop script

add server stop script

#
# Copyright (C) 2015 Agro-Know, Deutsches Forschungszentrum für Künstliche Intelligenz, iMinds,
# Institut für Angewandte Informatik e. V. an der Universität Leipzig,
# Istituto Superiore Mario Boella, Tilde, Vistatec, WRIPL (http://freme-project.eu)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

SCRIPT=$(readlink -f "$0")
BASEDIR=$(dirname "$SCRIPT")
cd $BASEDIR"/.."

kill `cat config/pid.txt`

error: pathspec 'package-maker/src/main/resources/bin/stop_server.sh' did not match any file(s) known to git


Create notes.sh

Create notes.sh

pwd      # Stands for 'Print Working Directory' and tells me where I am (WHERE)
whoami   # Tells me which user I'm logged in as (WHO)
ls       # Tells me what files are in the directory (WHAT)
cd       # Allows me to change into other directories (NAVIGATION)
date     # What time is it on the machine (WHEN)

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


Reorganized.

Reorganized.

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/chriskauffman/macScripts.git/'


updates on ARM version

updates on ARM version

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/fscherwi/tf-utility.git/'


added normal installer for brickd!

added normal installer for brickd!


changing link color

changing link color

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/amilaperera/oh-my-zsh.git/'


新增經濟數據試算

新增經濟數據試算

#!/usr/bin/env bash

URL2="http://www.dgbas.gov.tw/public/data/open/Stat/NA/NA8102A5A.xml"

function convert_date(){
    local input="$1"
python -c "$(cat <<EOPY
ss='$input'
rr=ss.split('/')
if int(rr[0]) < 200:
    rr[0] = str(int(rr[0])+1911)
print('/'.join(rr))
EOPY
)"
}

function feed_data(){
    local val_name="$1"
    local val_date="$2"
    local val_val="$3"

    local val_timestamp=$( echo "<?php date_default_timezone_set('Asia/Taipei'); echo( strtotime(\"$val_date 23:59 \") ); ?>" | php )

    echo "$val_date $val_val"

    # 先偵測有沒有開 influxdb / graphite
    if [ "$has_port" = "" ]; then
        nc -z 127.0.0.1 2003
        if [ $? -eq 0 ] ; then
            has_port="yes"
        else
            has_port="no"
        fi
    fi

    if [ "$has_port" = "yes" ] ; then
        printf "%s %s %s\n"  "$val_name" "$val_val" "$val_timestamp" \
        | nc -q 0 127.0.0.1 2003
    else
        printf "%s %s %s\n"  "$val_name" "$val_val" "$val_timestamp"
    fi
}

function get_data(){
    uu="$1"
    ff=$(basename $uu)

    test -e $ff || {
        curl --silent "$uu" | iconv -f utf16le -t utf8 | sed -e 's/utf-16/utf-8/g' > $ff
    }
}

function parse_data_99(){
    ff=$(basename $URL2)
    test -e $ff && {

python -c "$(cat <<EOPY
import xml.etree.ElementTree
import datetime
import sys

def parse_into_matrix(xpath_str,val_matrix):
    for item in root.findall(xpath_str):
        if item.items()[0][0] == "OBS_VALUE" :
            val = item.items()[0][1]
            ttt = item.items()[1][1]
        else:
            val = item.items()[1][1]
            ttt = item.items()[0][1]

        val_matrix[ttt] = val

tree = xml.etree.ElementTree.parse("$ff")
root = tree.getroot()

var_Y = {}
val_C = {}
val_I = {}
val_G = {}
val_X = {}
val_M = {}

common_xpath_substr = 'SeriesProperty[@TableName="國內生產毛額依支出分-年(1981以後)"][@SERIESTYPE="原始值"]/Obs'

parse_into_matrix( './/Series[@ITEM="當期價格(新台幣百萬元)-6.GDP"]/'+common_xpath_substr , var_Y )
parse_into_matrix( './/Series[@ITEM="當期價格(新台幣百萬元)-1.民間消費"]/'+common_xpath_substr, val_C )
parse_into_matrix( './/Series[@ITEM="當期價格(新台幣百萬元)-2.政府消費"]/'+common_xpath_substr, val_G )
parse_into_matrix( './/Series[@ITEM="當期價格(新台幣百萬元)-4.商品及服務輸出:4.1--4.2合計"]/'+common_xpath_substr , val_X )
parse_into_matrix( './/Series[@ITEM="當期價格(新台幣百萬元)-5.商品及服務輸入:5.1--5.2合計"]/'+common_xpath_substr , val_M )

for tt in var_Y.keys():
    var_y = float(var_Y[tt])
    var_c = float(val_C[tt])
    var_g = float(val_G[tt])
    var_x = float(val_X[tt])
    var_m = float(val_M[tt])
    var_i = var_y - var_c - var_g - ( var_x - var_m )
    var_nx = var_x - var_m

    sys.stdout.write( "%s %s %s\n" % (var_y, tt, "GDP" ))
    sys.stdout.write( "%s %s %s\n" % (var_c, tt, "民間消費" ))
    sys.stdout.write( "%s %s %s\n" % (var_g, tt, "政府消費" ))
    sys.stdout.write( "%s %s %s\n" % (var_x, tt, "出口" ))
    sys.stdout.write( "%s %s %s\n" % (var_m, tt, "進口" ))
    sys.stdout.write( "%s %s %s\n" % (var_i, tt, "民間投資" ))
    sys.stdout.write( "%s %s %s\n" % (var_nx, tt, "淨出口" ))

EOPY
)"

    }
}

function filter_data_99(){
    local keyword="$1"
    local rec_name="$2"

    parse_data_99 \
      | grep -e "\s${keyword}\s*" \
      | while read -r line
      do
        echo $line
        d1=$( echo "$line" | awk '{print $2}' )
        d1=$( convert_date "${d1}/12/31" )
        d2=$( echo "$line" | awk '{print $1}' )
        feed_data "$rec_name" "$d1" "$d2"
      done
}

get_data $URL2

filter_data_99 "民間投資" "econ.investment"
filter_data_99 "民間消費" "econ.consumption"
filter_data_99 "GDP" "econ.GDP"
filter_data_99 "出口" "econ.exports"
filter_data_99 "進口" "econ.imports"
filter_data_99 "政府消費" "econ.government_spending"
filter_data_99 "淨出口" "econ.net_exports"

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


simple run script closes getlantern/lantern#2277

#!/usr/bin/env bash

source setenv.bash
pushd src/github.com/getlantern/flashlight
go build
./flashlight
popd

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


Create recon.sh

Create recon.sh

Basic PoC first version using SubBrute and EyeWitness.

Usage:
./recon.sh DOMAIN

Example:
./recon.sh cisco.com

NOTE:
This first version uses hardcoded output for SubBrute file and the output directory for EyeWitness.
Also does not output status while its running.

Will need Subbrute and EyeWitness installed in the static directories defined in the script (CHANGE TO FIT YOUR NEEDS).

#!/bin/sh

if [ "$1" = "" ]; then
   echo USAGE: "./recon cisco.com"
   echo "./scan DOMAIN"
   exit
fi

echo "Starting SubDomain Brute Force!"
echo "testing $1"
python /tools/subbrute/subbrute.py $1 > /tmp/output.txt
echo "Taking SubDomain list and running it through EyeWitness"
python /tools/EyeWitness/EyeWitness.py -f /tmp/output/output.txt --web --results 250 -d /tmp/output/ --no-prompt
echo 'DONE! Check /tmp/output/report.html for output'

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


Abort early if vendor or model unreadable.

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/rhwood/paducah.git/'


compress_to_vp9.sh: fix filters parsing

compress_to_vp9.sh: fix filters parsing

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/DarkCaster/Linux-Helper-Tools.git/'


Add network tune script

Add network tune script

#!/bin/sh
#
# If you want to use this, call it from /etc/rc.local.

set -ex

echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo 32768 > /proc/sys/net/core/rps_sock_flow_entries
echo 32768 > /sys/class/net/eth0/queues/rx-0/rps_flow_cnt
echo 2 > /sys/class/net/eth0/queues/rx-0/rps_cpus
echo 1-2 > /proc/irq/114/smp_affinity_list
echo 3 > /proc/irq/92/smp_affinity_list

sysctl -w net.core.rmem_max=26214400
sysctl -w net.core.wmem_max=26214400
sysctl -w net.core.rmem_default=514400
sysctl -w net.core.wmem_default=514400
sysctl -w net.ipv4.tcp_rmem='10240 87380 26214400'
sysctl -w net.ipv4.tcp_wmem='10240 87380 26214400'
sysctl -w net.ipv4.udp_rmem_min=131072
sysctl -w net.ipv4.udp_wmem_min=131072
sysctl -w net.ipv4.tcp_timestamps=1
sysctl -w net.ipv4.tcp_window_scaling=1
sysctl -w net.ipv4.tcp_sack=1
sysctl -w net.core.optmem_max=65535
sysctl -w net.core.netdev_max_backlog=5000

error: pathspec 'simpleimage/platform-scripts/pine64_tune_network.sh' did not match any file(s) known to git


[scripts] Added convenience script start_cli_swarm.sh

Recently swarm was changed so, that --libra-node and --cli-path are
madatory, raising two issues:
    - there were no easy way to lauch swarm with CLI, because the
      documentation was out-of-date, and
    - the new way of lauching would not fit well to the documentation
      because the user might have "debug" or "release" version.

This script solves both problems by making lauching the swarm nice and
easy. It also forwards aguments after "--" straight to the swarm, so
user can configure their swarm if so desired.

Default is to build and use "debug" build, but "release" build can be
specified by issuing "-r" or "--release".

#!/bin/bash
# Copyright (c) The Libra Core Contributors
# SPDX-License-Identifier: Apache-2.0

print_help()
{
	echo "Build spawn a local swarm and open the CLI."
	echo "\`$0 -r|--release\` to use release build or"
	echo "\`$0\` to use debug build."
	echo "Use -- to pass arguments directly to libra-swarm."
}

source "$HOME/.cargo/env"

SCRIPT_PATH="$(dirname $0)"

RELEASE="debug"
FLAGS=""

while [[ ! -z "$1" ]]; do
	case "$1" in
		-h | --help)
			print_help;exit 0;;
		-r | --release)
			RELEASE="release";
			FLAGS="--release";;
		--)
			shift
			break
			;;
		*) echo "Invalid option"; print_help; exit 0;
	esac
	shift
done

echo "Building and running swarm in $RELEASE mode with the following flags: $FLAGS"

cargo build -p libra-node $FLAGS
cargo build -p cli $FLAGS
cargo run -p libra-swarm -- -s --libra-node $SCRIPT_PATH/../../target/$RELEASE/libra-node --cli-path $SCRIPT_PATH/../../target/$RELEASE/cli "$@"

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


Comment

Comment

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/MichelAquino/dotfiles.git/'


Added file correctSqlLoadPaths.sh, a script that's a hack to get around incorrect statements LOAD INFILE '/path/on/cluster/Answer.csv'... being produced into the .sql files that are the result of transforms run on a compute cluster.

#!/bin/bash

# This script is only useful if you ran a transform
# through a compute cluster using qsubClusterSubmission.sh
# B/c of shortcomings in my scripts, The .sql files produced
# will contain LOAD INFILE commands with paths to .csv files
# as they are on the cluster head machine. If you then
# copy those files to ~dataman/Data/EdX/tracking/CSV, those
# load paths are wrong. This script corrects the paths.
# A hack; I should fix the scripts that generate the LOAD
# commands in the first place!
#
# Example: scripts/correctSqlLoadPaths.sh /home/dataman/Data/EdX/tracking/CSV  /dfs/scratch1/paepcke /home/dataman/Data/EdX

USAGE='Usage: '`basename $0`' rootForSQLFiles filePathToReplace newFilePath'

if [[ $@ < 3 ]]
then
    echo $USAGE
    exit
fi

rootDir=$1
srcStr=$2
dstStr=$3

#******
# echo "rootDir: $rootDir"
# echo "srcStr: $srcStr"
# echo "dstStr: $dstStr"
#******

if [[ $srcStr == '*|*' || $dstStr == '*|*' ]]
then
    echo "File paths must not contain the character '|'."
    exit
fi

for fileName in `find ${rootDir} -name "*.sql"`
do
    echo "Fixing file ${fileName}"
    sed -e "s|${srcStr}|${dstStr}|g" ${fileName} > ${fileName}.tmp && mv ${fileName}.tmp ${fileName}
done

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