Initial scripted Terminal configuration.

* Creates BoochTek and BoochTek Presentations profiles.
  * Configures basic settings.
  * Sets window sizes (rows and columns).
  * Does not yet set fonts or colors.
* Adds cursor key bindings for Basic and both BoochTek profiles.
  * Cursor keys plus Shift, Option, and Control modifiers.
* Sets BoochTek as the default profile.

#!/bin/bash

## Configure Terminal.app the way we want it.

## WARNING: This will kill any running Terminal session, in order for the settings to take effect.

## NOTES:
##  We override the default actions for the Home, End, PageUp, and PageDown keys - moving around in the buffer.
##  To move around in the buffer, use the Command key with the Home, End, PageUp, and PageDown keys.
##  To test from scratch, delete `~/Library/Preferences/com.apple.Terminal.plist` and `killall -u cfprefsd` and `killall Terminal`.

source 'ansi_codes.sh'
source 'key_codes.sh'

# Make sure we have latest defaults+.
curl --silent https://raw.github.com/boochtek/defaults_plus/master/defaults+ -o /usr/local/bin/defaults+
chmod a+x /usr/local/bin/defaults+
hash -r

function main {
  # Always show tabs, even if only 1 tab is open.
  defaults write -app Terminal ShowTabBar 1

  # Only use UTF-8 in Terminal.
  defaults write -app Terminal StringEncodings -array 4

  # Define ANSI sequences for cursor keys (with and without modifiers).
  bind_cursor_keys 'Basic'

  # Copy "Basic" profile to "BoochTek", and configure "BoochTek" the way we want it.
  defaults+ copy com.apple.Terminal 'Window Settings.Basic' 'Window Settings.BoochTek'
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek.name' 'BoochTek'
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek.CursorBlink' 1
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek.Bell' 0
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek.VisualBell' 1
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek.columnCount' 120
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek.rowCount' 32
  # TODO: Font: Courier New, Bold, 18 pt (or Menlo Regular 16, or a downloaded font)
  # Use the background color that the Solarized (Light) color scheme from Sublime Text uses.
  # defaults+ write com.apple.Terminal 'Window Settings.BoochTek.BackgroundColor' '<62706c69 73743030 d4010203 04050615 16582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f701200 0186a0a3 07080f55 246e756c 6cd3090a 0b0c0d0e 554e5352 47425c4e 53436f6c 6f725370 61636556 24636c61 73734f10 26302e39 38343331 33373836 20302e39 35323934 31323338 3920302e 38373834 33313433 39340010 028002d2 10111213 5a24636c 6173736e 616d6558 24636c61 73736573 574e5343 6f6c6f72 a2121458 4e534f62 6a656374 5f100f4e 534b6579 65644172 63686976 6572d117 1854726f 6f748001 08111a23 2d32373b 41484e5b 628b8d8f 949fa8b0 b3bcced1 d6000000 00000001 01000000 00000000 19000000 00000000 00000000 00000000 d8>'

  # Copy "BoochTek" profile to "BoochTek Presentations", and change font and window sizes.
  # TODO: Do we want light and dark versions?
  defaults+ copy com.apple.Terminal 'Window Settings.Basic' 'Window Settings.BoochTek Presentations'
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek Presentations.name' 'BoochTek Presentations'
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek.columnCount' 80
  defaults+ write com.apple.Terminal 'Window Settings.BoochTek.rowCount' 24
  # TODO: Font: Courier New, Bold, 29 pt

  # Set default profile to use for new windows.
  defaults write -app Terminal 'Default Window Settings' -string 'BoochTek'
  defaults write -app Terminal 'Startup Window Settings' -string 'BoochTek'

  # Kill the preferences cache and Terminal app, so it will pick up new settings, and so it doesn't overwrite our changes.
  killall -u $USER cfprefsd
  killall -u $USER Terminal
}

# System-wide default bindings: /System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict
# Actions specific to Terminal.app: /Applications/Utilities/Terminal.app/Contents/Resources/English.lproj/actions.strings
# Also see http://www.hcs.harvard.edu/~jrus/Site/system-bindings.html
# Also see http://xahlee.info/kbd/osx_keybinding_action_code.html and http://xahlee.info/kbd/osx_keybinding.html

# Where alternative bindings are possible, we're using the ones in the xterm terminfo (except BS).
function bind_cursor_keys {
  local PROFILE_NAME="$1"

  terminal_keybinding $PROFILE_NAME 'del' "${CSI}3~"
  # terminal_keybinding $PROFILE_NAME 'ins' "${CSI}2~"

  terminal_keybinding $PROFILE_NAME 'shift del' "${CSI}3;2~"  # CUA Cut
  # terminal_keybinding $PROFILE_NAME 'shift ins' "${CSI}2;2~"  # CUA Paste

  terminal_keybinding $PROFILE_NAME 'control bs'  "${ESC}?"     # Delete word to the left of cursor. From https://github.com/vmalloc/emacs_config/blob/master/.emacs.d/terminal-config.el
  terminal_keybinding $PROFILE_NAME 'control del' "${CSI}3;5~"  # Delete word to the right of cursor.
  # terminal_keybinding $PROFILE_NAME 'control ins' "${CSI}2;5~"  # CUA Copy

  terminal_keybinding $PROFILE_NAME 'up'      "${ESC}OA"  # Alternatives: "${CSI}A"
  terminal_keybinding $PROFILE_NAME 'down'    "${ESC}OB"  # Alternatives: "${CSI}B"
  terminal_keybinding $PROFILE_NAME 'right'   "${ESC}OC"  # Alternatives: "${CSI}C"
  terminal_keybinding $PROFILE_NAME 'left'    "${ESC}OD"  # Alternatives: "${CSI}D"
  terminal_keybinding $PROFILE_NAME 'home'    "${ESC}OH"  # Alternatives: "${CSI}H" (Mac default), "${CSI}1~"
  terminal_keybinding $PROFILE_NAME 'end'     "${ESC}OF"  # Alternatives: "${CSI}F" (Mac default), "${CSI}4~"
  terminal_keybinding $PROFILE_NAME 'pg_up'   "${CSI}5~"
  terminal_keybinding $PROFILE_NAME 'pg_down' "${CSI}6~"

  terminal_keybinding $PROFILE_NAME 'shift up'      "${CSI}1;2A"
  terminal_keybinding $PROFILE_NAME 'shift down'    "${CSI}1;2B"
  terminal_keybinding $PROFILE_NAME 'shift right'   "${CSI}1;2C"
  terminal_keybinding $PROFILE_NAME 'shift left'    "${CSI}1;2D"
  terminal_keybinding $PROFILE_NAME 'shift home'    "${CSI}1;2H"
  terminal_keybinding $PROFILE_NAME 'shift end'     "${CSI}1;2F"
  terminal_keybinding $PROFILE_NAME 'shift pg_up'   "${CSI}5;2~"
  terminal_keybinding $PROFILE_NAME 'shift pg_down' "${CSI}6;2~"

  terminal_keybinding $PROFILE_NAME 'option up'      "${CSI}1;3A"
  terminal_keybinding $PROFILE_NAME 'option down'    "${CSI}1;3B"
  terminal_keybinding $PROFILE_NAME 'option right'   "${CSI}1;3C"
  terminal_keybinding $PROFILE_NAME 'option left'    "${CSI}1;3D"
  terminal_keybinding $PROFILE_NAME 'option home'    "${CSI}1;3H"
  terminal_keybinding $PROFILE_NAME 'option end'     "${CSI}1;3F"
  terminal_keybinding $PROFILE_NAME 'option pg_up'   "${CSI}5;3~"
  terminal_keybinding $PROFILE_NAME 'option pg_down' "${CSI}6;3~"

  terminal_keybinding $PROFILE_NAME 'option shift up'      "${CSI}1;4A"
  terminal_keybinding $PROFILE_NAME 'option shift down'    "${CSI}1;4B"
  terminal_keybinding $PROFILE_NAME 'option shift right'   "${CSI}1;4C"
  terminal_keybinding $PROFILE_NAME 'option shift left'    "${CSI}1;4D"
  terminal_keybinding $PROFILE_NAME 'option shift home'    "${CSI}1;4H"
  terminal_keybinding $PROFILE_NAME 'option shift end'     "${CSI}1;4F"
  terminal_keybinding $PROFILE_NAME 'option shift pg_up'   "${CSI}5;4~"
  terminal_keybinding $PROFILE_NAME 'option shift pg_down' "${CSI}6;4~"

  terminal_keybinding $PROFILE_NAME 'control up'      "${CSI}1;5A"
  terminal_keybinding $PROFILE_NAME 'control down'    "${CSI}1;5B"
  terminal_keybinding $PROFILE_NAME 'control right'   "${CSI}1;5C"
  terminal_keybinding $PROFILE_NAME 'control left'    "${CSI}1;5D"
  terminal_keybinding $PROFILE_NAME 'control home'    "${CSI}1;5H"
  terminal_keybinding $PROFILE_NAME 'control end'     "${CSI}1;5F"
  terminal_keybinding $PROFILE_NAME 'control pg_up'   "${CSI}5;5~"
  terminal_keybinding $PROFILE_NAME 'control pg_down' "${CSI}6;5~"

  terminal_keybinding $PROFILE_NAME 'control shift up'      "${CSI}1;6A"
  terminal_keybinding $PROFILE_NAME 'control shift down'    "${CSI}1;6B"
  terminal_keybinding $PROFILE_NAME 'control shift right'   "${CSI}1;6C"
  terminal_keybinding $PROFILE_NAME 'control shift left'    "${CSI}1;6D"
  terminal_keybinding $PROFILE_NAME 'control shift home'    "${CSI}1;6H"
  terminal_keybinding $PROFILE_NAME 'control shift end'     "${CSI}1;6F"
  terminal_keybinding $PROFILE_NAME 'control shift pg_up'   "${CSI}5;6~"
  terminal_keybinding $PROFILE_NAME 'control shift pg_down' "${CSI}6;6~"

  terminal_keybinding $PROFILE_NAME 'control option up'      "${CSI}1;7A"
  terminal_keybinding $PROFILE_NAME 'control option down'    "${CSI}1;7B"
  terminal_keybinding $PROFILE_NAME 'control option right'   "${CSI}1;7C"
  terminal_keybinding $PROFILE_NAME 'control option left'    "${CSI}1;7D"
  terminal_keybinding $PROFILE_NAME 'control option home'    "${CSI}1;7H"
  terminal_keybinding $PROFILE_NAME 'control option end'     "${CSI}1;7F"
  terminal_keybinding $PROFILE_NAME 'control option pg_up'   "${CSI}5;7~"
  terminal_keybinding $PROFILE_NAME 'control option pg_down' "${CSI}6;7~"

  terminal_keybinding $PROFILE_NAME 'control option shift up'      "${CSI}1;8A"
  terminal_keybinding $PROFILE_NAME 'control option shift down'    "${CSI}1;8B"
  terminal_keybinding $PROFILE_NAME 'control option shift right'   "${CSI}1;8C"
  terminal_keybinding $PROFILE_NAME 'control option shift left'    "${CSI}1;8D"
  terminal_keybinding $PROFILE_NAME 'control option shift home'    "${CSI}1;8H"
  terminal_keybinding $PROFILE_NAME 'control option shift end'     "${CSI}1;8F"
  terminal_keybinding $PROFILE_NAME 'control option shift pg_up'   "${CSI}5;8~"
  terminal_keybinding $PROFILE_NAME 'control option shift pg_down' "${CSI}6;8~"
}

function terminal_keybinding {
  local profile="$1"
  local key_code=$(key_code_with_modifier "$2")
  local binding=$(echo -e "$3")  # Convert escape codes.
  local key_path="Window Settings.$profile.keyMapBoundKeys.$key_code"

  defaults+ write com.apple.Terminal "$key_path" "$binding"
}

main

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


script for setting up Xcode config file inheritance

#!/bin/bash

SCRIPT_NAME=`basename "$0"`
SCRIPT_DIR=`dirname "$PWD/$0"`

INHERIT_DIRNAME="inherit"
INHERIT_FILE_INCLUDE_PATH="../../../../BuildControl/config/inherit"

showHelp()
{
	echo "$SCRIPT_NAME"
	echo
	printf "\tSets up inheritance for Xcode configuration files.\n"
	echo
	printf "\tThis is useful for passing down configuration settings from a\n"
	printf "\tcontaining Xcode project to contained Xcode projects. Normally,\n"
	printf "\tthe Xcode settings of a containing project are not inherited by\n"
	printf "\tcontained projects. This mechanism uses .xcconfig files to set\n"
	printf "\tup inheritance.\n"
	echo
	echo "Usage:"
	echo
	printf "\t$SCRIPT_NAME\n"
	echo
	echo "Optional arguments:"
	echo
	printf "\t--force\n"
	echo
	printf "\t\tThe --force (or -f) argument specifies that any local\n"
	printf "\t\tinheritence .xcconfig files will be overwritten with new ones.\n"
	echo
	printf "\t--inherit-dir <dir-path>\n"
	echo
	printf "\t\tThe --inherit-dir (or -i) argument specifies the path of a\n"
	printf "\t\tdirectory containing the .xcconfig files to inherit. This must\n"
	printf "\t\tbe a relative path that points to a directory within the file\n"
	printf "\t\tstructure of the containing project. If this argument is not\n"
	printf "\t\tsupplied, the following default will be used:\n"
	echo
	printf "\t\t\t${INHERIT_FILE_INCLUDE_PATH}\n"
	echo
	echo "Help"
	echo
	printf "\tThis documentation is displayed when supplying the --help (or\n"
	printf "\t-h or -?) argument.\n"
	echo
	printf "\tNote that when this script displays help documentation, all other\n"
	printf "\tcommand line arguments are ignored and no other actions are performed.\n"
	echo
}

printError()
{
	echo "error: $1"
	echo
	if [[ ! -z $2 ]]; then
		printf "  $2\n\n"
	fi
}

exitWithError()
{
	printError "$1" "$2"
	exit 1
}

exitWithErrorSuggestHelp()
{
	printError "$1" "$2"
	printf "  To display help, run:\n\n\t$0 --help\n"
	exit 1
}

#
# parse the command-line arguments
#
while [[ $1 ]]; do
	case $1 in
	--help|-h|-\?)
		SHOW_HELP=1
		;;

	--force|-f)
		FORCE_MODE=1
		;;

	--inherit-dir|-i)
		if [[ ! -z "$2" ]]; then
			INHERIT_FILE_INCLUDE_PATH="$2"
			shift
		else
			exitWithErrorSuggestHelp "The $1 argument requires a value"
		fi
		;;

	*)
		exitWithErrorSuggestHelp "Unrecognized argument: $1"
		;;
	esac
	shift
done

cd "$SCRIPT_DIR/../config"

if [[ $SHOW_HELP ]]; then
	showHelp
	exit
fi

mkdir -p inherit "$INHERIT_DIRNAME"

for CONFIG_FILENAME in *.xcconfig; do
	INHERIT_FILE="${INHERIT_DIRNAME}/${CONFIG_FILENAME}"
	INHERIT_INCLUDE="#include \"${INHERIT_FILE}\""
	FIRST_LINE=`head -1 "$CONFIG_FILENAME"`
	if [[ "$FIRST_LINE" != "$INHERIT_INCLUDE" ]]; then
		echo "Enabling Xcode config inheritance for: ${CONFIG_FILENAME}"
		BACKUP_FILENAME="${CONFIG_FILENAME}.bak"
		cp -f "$CONFIG_FILENAME" "$BACKUP_FILENAME"
		printf "${INHERIT_INCLUDE}\n\n" > "$CONFIG_FILENAME"
		cat "$BACKUP_FILENAME" >> "$CONFIG_FILENAME"
		rm -f "$BACKUP_FILENAME"
	else
		echo "Xcode config inheritance already enabled for: ${CONFIG_FILENAME}"
	fi

	if [[ $FORCE_MODE || ("$FIRST_LINE" != "$INHERIT_INCLUDE") ]]; then
		if [[ $FORCE_MODE ]]; then
			echo "Overwriting Xcode config inheritance file: ${INHERIT_FILE}"
		fi
		printf "// this file generated by ${SCRIPT_NAME}\n\n#include \"${INHERIT_FILE_INCLUDE_PATH}/${CONFIG_FILENAME}\"\n" > "$INHERIT_FILE"
	fi
done

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


script to make it easier to run all tests

#!/bin/sh

echo "\nunit tests"
python unit_tests.py > /dev/null
echo "\nclassical paradigm tests"
python data_test.py
echo "\nregression tests"
python regression_tests.py
echo "\ndoctests"
python -m doctest examples.rst
echo "\nmorphgnt tests"
python morphgnt_generate.py 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 23 24 25 26 27
echo "\nhomer paradigm tests"
python homer_generate_paradigms.py

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


ボツスクリプトだが、追加しておく。

ボツスクリプトだが、追加しておく。

#!/bin/bash

# Copyright (c) 2012 プレハブ小屋 <yojyo@hotmail.com>
# All Rights Reserved.  NO WARRANTY.
#
# ボツスクリプト

# サントラのファイルは MP3 形式に変換済み。
EXTENSION=mp3

DIR_DISC1="DQ8.1"
DIR_DISC2="DQ8.2"
DIR_DQ8="DQ8ALL"

# ファイル名はサントラに書いてある各曲のタイトルを
# 少し変更しておく。

ALBUM1=(\
    "01 トラック 1.mp3:01. 序曲" \
    "02 トラック 2.mp3:02. インテルメッツォ" \
    "03 トラック 3.mp3:03. 馬車を曳いて" \
    "04 トラック 4.mp3:04. 穏やかな街並み" \
    "05 トラック 5.mp3:05. 酒場でブギウギ" \
    "06 トラック 6.mp3:06. 穏やかな街並み" \
    "07 トラック 7.mp3:07. 広い世界へ" \
    "08 トラック 8.mp3:08. 雄叫びをあげて" \
    "09 トラック 9.mp3:09. それ行けトーポ" \
    "10 トラック 10.mp3:10. 暗い道の奥で" \
    "11 トラック 11.mp3:11. 静かな村" \
    "12 トラック 12.mp3:12. それ行けトーポ" \
    "13 トラック 13.mp3:13. 讃美歌に癒されて" \
    "14 トラック 14.mp3:14. 静かな村" \
    "15 トラック 15.mp3:15. 神秘なる塔" \
    "16 トラック 16.mp3:16. この想いを…" \
    "17 トラック 17.mp3:17. 難関を突破せよ" \
    "18 トラック 18.mp3:18. そうだあの時は…" \
    "19 トラック 19.mp3:19. 修道僧の決意" \
    "20 トラック 20.mp3:20. 急げ！ピンチだ" \
    "21 トラック 21.mp3:21. 忍び寄る影" \
    "22 トラック 22.mp3:22. つらい時を乗り越えて" \
    "23 トラック 23.mp3:23. 海の記憶" )

ALBUM2=(\
    "01 トラック 1.mp3:24. 城の威容～王宮のガヴォット" \
    "02 トラック 2.mp3:25. 王宮のガヴォット" \
    "03 トラック 3.mp3:26. 詩人の世界" \
    "04 トラック 4.mp3:27. 海の記憶" \
    "05 トラック 5.mp3:28. 錬金がま" \
    "06 トラック 6.mp3:29. 対話" \
    "07 トラック 7.mp3:30. 楽しいカジノ" \
    "08 トラック 8.mp3:31. 闇の遺跡" \
    "09 トラック 9.mp3:32. 大平原のマーチ" \
    "10 トラック 10.mp3:33. 大聖堂のある街" \
    "11 トラック 11.mp3:34. 終末へ向かう" \
    "12 トラック 12.mp3:35. ドルマゲス" \
    "13 トラック 13.mp3:36. おおぞらをとぶ" \
    "14 トラック 14.mp3:37. おおぞらに戦う" \
    "15 トラック 15.mp3:38. この想いをハープにのせて" \
    "16 トラック 16.mp3:39. 大聖堂のある街～空と海と大地" \
    "17 トラック 17.mp3:40. レベルアップ" \
    "18 トラック 18.mp3:41. 宿屋" \
    "19 トラック 19.mp3:42. 戦闘勝利" \
    "20 トラック 20.mp3:43. 仲間" \
    "21 トラック 21.mp3:44. アイテム発見" \
    "22 トラック 22.mp3:45. 全滅" \
    "23 トラック 23.mp3:46. ファンファーレ小" \
    "24 トラック 24.mp3:47. ファンファーレ中" \
    "25 トラック 25.mp3:48. ファンファーレ大" \
    "26 トラック 26.mp3:49. 教会" \
    "27 トラック 27.mp3:50. セーブ" \
    "28 トラック 28.mp3:51. 呪い" \
    "29 トラック 29.mp3:52. 魔物出現" \
    "30 トラック 30.mp3:53. ハープME1" \
    "31 トラック 31.mp3:54. ハープME2" \
    "32 トラック 32.mp3:55. ワシの歌を聴け" \
    "33 トラック 33.mp3:56. リサイタル" \
    "34 トラック 34.mp3:57. リンリン特技1" \
    "35 トラック 35.mp3:58. リンリン特技2" \
    "36 トラック 36.mp3:59. リンリン特技3" \
    "37 トラック 37.mp3:60. リンリン特技4" \
    "38 トラック 38.mp3:61. リンリン特技5" \
    "39 トラック 39.mp3:62. やまびこの笛1" \
    "40 トラック 40.mp3:63. やまびこの笛2" )

pushd $DIR_DISC1
for ITEM in "${ALBUM1[@]}" ; do
    OLDNAME="${ITEM%:*}.$EXTENSION"
    NEWNAME="${ITEM#*:}.$EXTENSION"
    if [ -e "$OLDNAME" ] ; then
        echo $OLDNAME "=>" $NEWNAME
        mv "$OLDNAME" "$NEWNAME"
    fi
done
popd

pushd $DIR_DISC2
for ITEM in "${ALBUM2[@]}" ; do
    OLDNAME="${ITEM%:*}.$EXTENSION"
    NEWNAME="${ITEM#*:}.$EXTENSION"
    if [ -e "$OLDNAME" ] ; then
        echo $OLDNAME "=>" $NEWNAME
        mv "$OLDNAME" "$NEWNAME"
    fi
done
popd

mkdir -p $DIR_DQ8
mv $DIR_DISC1/* $DIR_DQ8
mv $DIR_DISC2/* $DIR_DQ8

error: pathspec 'rename-dq8-mp3.sh' did not match any file(s) known to git


update

update

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/neoseele/gke.git/'


Forgot to add that.

Forgot to add that.

#!/bin/sh -e

. $1

if test -n "$dlname"; then
  nm -n "`dirname $1`/$dlname" | grep ' [tT] [^.]' > $2/symbols.dynamic
fi

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


fix system breakage window during make install due to permissions

install.sh was wrongly waiting until after atomically replacing the
old file to set the correct permissions on the new file. in the case
of the dynamic linker, this would cause a dynamic-linked chmod command
not to run (due to missing executable permissions on the dynamic
linker) and thus leave the system in an unusable state.

even if chmod is static-linked, the old behavior had a race window
where dynamic-linked programs could fail to run.

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/chardi/musl.git/'


Minor syntax to install.sh

Minor syntax to install.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/metao1/chat.git/'


Update install.sh

Update install.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/Jumpscale/play7.git/'


Add test for combination of artimetic and comparison operators over xsd:dateTime, xsd:dayTimeDuration and xsd:yearMonthDuration values

#! /bin/bash

# exercise combination of arithmetic and comparison operators over temporal data
# this test subtracts a duration from an xsd:dateTime literal bound to ?now variable and tests the result against other xsd:dateTime literals using the eq, lt and gt operators
# the repository is initialized with data where:
# - the value of ex:duration is the duration to be subtracted from ?now
# - the values of ex:dateEq, ex:dateLt and ex:dateGt are xsd:dateTime values that are used for the respective eq, lt and gt comparisons
# - these values are such that the result of the comparison is expected to be true

set_sparql_url "${STORE_ACCOUNT}" "${STORE_REPOSITORY}-write"
set_graph_store_url "${STORE_ACCOUNT}" "${STORE_REPOSITORY}-write"

$CURL -w "%{http_code}\n" -f -s -S -X PUT \
     -H "Content-Type: application/turtle" \
     --data-binary @- \
     -u "${STORE_TOKEN}:" \
     "${GRAPH_STORE_URL}?default" <<EOF \
    | egrep -q "$STATUS_PUT_SUCCESS"
@prefix ex: <http://example.com/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema-datatypes#> .

_:a ex:dateEq "2013-12-31T00:00:00Z"^^xsd:dateTime ;
  ex:dateLt "2013-12-31T00:00:01Z"^^xsd:dateTime ;
  ex:dateGt "2013-12-30T23:59:59Z"^^xsd:dateTime ;
  ex:duration "PT24H"^^xsd:dayTimeDuration .

_:b ex:dateEq "2013-12-02T00:00:00Z"^^xsd:dateTime ;
  ex:dateLt "2013-12-03T00:00:00Z"^^xsd:dateTime ;
  ex:dateGt "2013-12-01T00:00:00Z"^^xsd:dateTime ;
  ex:duration "P30D"^^xsd:dayTimeDuration .

_:c ex:dateEq "2013-10-01T00:00:00Z"^^xsd:dateTime ;
  ex:dateLt "2013-11-01T00:00:00Z"^^xsd:dateTime ;
  ex:dateGt "2013-09-01T00:00:00Z"^^xsd:dateTime ;
  ex:duration "P3M"^^xsd:yearMonthDuration .

_:d ex:dateEq "2012-07-01T00:00:00Z"^^xsd:dateTime ;
  ex:dateLt "2011-07-01T00:00:00Z"^^xsd:dateTime ;
  ex:dateGt "2013-07-01T00:00:00Z"^^xsd:dateTime ;
  ex:duration "P1Y6M"^^xsd:yearMonthDuration .
EOF

curl_sparql_request "Accept: application/sparql-results+json" <<EOF \
 | jq '.results.bindings[] | .[].value' | fgrep -q 'true'

prefix xsd: <http://www.w3.org/2001/XMLSchema-datatypes>
prefix ex: <http://example.com/>

select (((?date_offset = ?dateEq) &&
         (?date_offset < ?dateLt) &&
         (?date_offset > ?dateGt))
        as ?ok)
where {
  ?s ex:dateEq ?dateEq ;
    ex:dateLt ?dateLt ;
    ex:dateGt ?dateGt ;
    ex:duration ?duration .
  bind ('2014-01-01T00:00:00Z'^^xsd:dateTime as ?now)
  bind (?now - ?duration as ?date_offset)
}
EOF

error: pathspec 'extensions/sparql-protocol/temporal-data/dateTime-Duration.sh' did not match any file(s) known to git


added benchmark shell script

added benchmark shell script

#!/bin/bash
for i in {1..32}
do
	./SimpleMOC -t $i
done

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


test for common errors and apply fixes

test for common errors and apply fixes

#!/bin/bash

. config.sh
. app/colors.sh

# run as root only
if [[ $EUID -ne 0 ]] ; then
    run_error "This script must be run with root access\e[49m"
    exit 1
fi

# test aclocal-1.5
type aclocal-1.5 >/dev/null 2>&1 || {
    show_yellow "Warning" "aclocal-1.5 not found on your system. Trying to fix now..."
    ./fix/aclocal.sh
}

error: pathspec 'app/tests/common_errors.sh' did not match any file(s) known to git


Handle nsx ca certificates properly in json

- configure-director handles multi-line values in iaas_configuration on
vsphere install-pcf

[#145241533]

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/pvsone/pcf-pipelines.git/'


Create tracefunction.sh

Create tracefunction.sh

#!/system/bin/sh
DPATH="/sys/kernel/debug/tracing"
LPATH="/sys/kernel/debug/binder"
DATE=$(date +%Y%m%d%H%M%S)
echo nop > $DPATH/current_tracer
echo > $DPATH/trace
echo > $DPATH/trace_pipe

# set function tracer
echo function_graph > $DPATH/current_tracer
echo *binder*> $DPATH/set_ftrace_filter
echo funcgraph-abstime > $DPATH/trace_options
ps -t > /sdcard/binder_ftrace_ref_$DATE.txt
# start the tracing
echo 1 > $DPATH/tracing_on

sleep $1

echo 0 > $DPATH/tracing_on
cat $DPATH/trace > /sdcard/binder_ftrace_$DATE.txt

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


swapped from using atom to vim

swapped from using atom to vim

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


Delete test.sh

Delete test.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/fluxcapacitor/source.ml.git/'


Distcheck script.

Distcheck script.

--HG--
extra : convert_revision : svn%3A18234216-3d68-4496-97ee-3aadfc93d375/trunk%40582

# returns whether we're on Fedora or Ubuntu

if   [ -f /etc/fedora-release ] ; then
	echo 'Fedora'
elif [ -f /etc/lsb-release ] ; then
	echo `cat /etc/lsb-release | grep DISTRIB_ID | sed s/.*=//`
fi

error: pathspec 'Code/Tools/LinuxBuildTools/distcheck.sh' did not match any file(s) known to git


upload new content 2

upload new content 2

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/VirusTotal/content.git/'


Added script to run Cassandra migrations

# Script to run Cassandra migrations for docker container with Cassandra

# Receives optional positional argument with Cassandra container name,
# "cassandra" by default

CASSANDRA_CONTAINER="${1:-cassandra}"
SCRIPT="cqlsh -f /tmp/migrations.cql || rm /tmp/migrations.cql"
docker cp migrations.cql ${CASSANDRA_CONTAINER}:/tmp/
docker exec -it ${CASSANDRA_CONTAINER} sh -c "${SCRIPT}"

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


add network.sh

add network.sh

#!/bin/sh

# show tcp connections only
netstat -at

# show ipv4 and ipv6 connections only
netstat -au

# disable reverse dns lookup, show faster
netstat -n

# show only listening connections
netstat -l

# get process name
netstat -p

# show network statistics
netstat -s

# check if a services is running
sudo netstat -aple | grep ntp

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


Update tools.sh

Update tools.sh

#!/usr/bin/env bash
### every exit != 0 fails the script
set -e

echo "Install some common tools for further installation"
apt-get update
apt-get install -y --allow-unauthenticated vim wget unzip curl git gdebi-core bash-completion build-essential ruby make net-tools \
ca-certificates libglib2.0-0 libxext6 libsm6 libxrender1 mercurial subversion synaptic locales sudo apt-utils software-properties-common \
python-software-properties libgtk-3-bin libgtk-3-dev
apt-get clean -y

#!/usr/bin/env bash
### every exit != 0 fails the script
set -e

echo "Install some common tools for further installation"
apt-get update
apt-get install -y --allow-unauthenticated vim wget unzip curl git gdebi-core bash-completion build-essential ruby make net-tools \
ca-certificates libglib2.0-0 libxext6 libsm6 libxrender1 mercurial subversion synaptic locales sudo apt-utils software-properties-common \
python-software-properties
apt-get clean -y


Create configure_disk_image.sh

Create configure_disk_image.sh

!/bin/bash
# configure_disk_image.sh
# purpose: configure disk image
# last modified: 2015/09/30

if ! [ $(id -u) = 0 ]; then
   echo "to be run with sudo"
   exit 1
fi

# set up wap partition
target=/etc/fstab
if ! grep -Fxq /swap $target; then
    dd if=/dev/zero of=/swap bs=1M count=512
    mkswap /swap
    echo '/swap none swap sw 0 0' >> $target
else
    echo swap partition already configured
fi

# speed things up

#------------------------------------------------------
apt-get install -y raspi-copies-and-fills
apt-get install -y rng-tools
#------------------------------------------------------

target=/etc/modules
if ! grep -Fxq bcm2708-rng $target; then
    echo bcm2708-rng >> $target
else
    echo bcm2708-rng already present
fi

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


openvpn.sh derp

openvpn.sh derp

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/deusieeee/openvpn-client.git/'


misc/cgo/testso: use bash to run test.bash

R=golang-dev, minux.ma, capnm9
CC=golang-dev
https://codereview.appspot.com/9717043

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/wesolows/golang-old.git/'


Add cibuild

Add cibuild

#!/bin/sh

set -e

echo "building the site..."
bundle exec rake test

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


add mariadb

add mariadb

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


Added git

Added git

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


Adds chruby_prompt_info dummy function.

Adds chruby_prompt_info dummy function.

# using the chruby plugin will override this with a real implementation
function chruby_prompt_info() {
  return 1
}

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


tidy up the build script log - revised

tidy up the build script log - revised

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/simonracz/detox.git/'


jenv load

jenv load

#!/bin/bash

#
#   Copyright 2013 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.
#

# jenv load for jenvrc
# @Globals JENV_CANDIDATES JENV_CANDIDATES_DEFAULT
function __jenvtool_load {
	 if [[ -f "${PWD}/jenvrc" ]]; then
     echo "==============jenv load======================"
     while read entry
     do
       if ! __jenvtool_utils_string_contains "$entry", "#" ; then
            candidate1=`echo ${entry} | sed 's/=.*//g'`
            version1=`echo ${entry} | sed 's/.*=//g'`
            if [ -d "${JENV_DIR}/candidates/${candidate1}/${version1}" ]; then
                __jenvtool_use "${candidate1}" "${version1}"
            else
                __jenvtool_install "${candidate1}" "${version1}"
            fi
            unset candidate1
            unset version1
       fi
     done < "${PWD}/jenvrc"
  fi
}

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


small fix

small fix

#
# Copyright 2014 CyberVision, Inc.
#
# 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.
#

#!/bin/bash

RUN_DIR=`pwd`

function help {
    echo "Choose one of the following: {build|install|test|clean}"
    exit 1
}

if [ $# -eq 0 ]
then
    help
fi

DEBUG_ENABLED=1
UNITTESTS_COMPILE=0
MAX_LOG_LEVEL=6
COLLECT_COVERAGE=0

function prepare_build {
    mkdir -p build;
    cd build;
    cmake -DKAA_DEBUG_ENABLED=$DEBUG_ENABLED -DKAA_MAX_LOG_LEVEL=$MAX_LOG_LEVEL -DKAA_UNITTESTS_COMPILE=$UNITTESTS_COMPILE -DKAA_COLLECT_COVERAGE=$COLLECT_COVERAGE ..;
    cd ..
}

function build {
    cd build && make && cd ..
}

function execute_tests {
    cd build
    FAILUTE_COUNTER=0
    FAILED_TESTS=""
    for test in test_*
    do
        echo -e "Starting test $test"
        ./$test
        TEST_RESULT=$?
        echo -e "Test $test finished"
        if [ $TEST_RESULT -ne 0 ]
        then
            FAILUTE_COUNTER=$((FAILUTE_COUNTER + 1))
            FAILED_TESTS="$test\n$FAILED_TESTS"
        fi
    done
    if [[ -f ../gcovr ]]
    then
        chmod +x ../gcovr
        ../gcovr -d -x -f ".*" -e ".*(test|avro|gen).*" -o ./gcovr-report.xml -v > ./gcovr.log
    fi
    if [ "$FAILUTE_COUNTER" -ne "0" ]
    then
        echo -e "\n$FAILUTE_COUNTER TEST(S) FAILED:\n$FAILED_TESTS"
    else
        echo -e "\nTESTS WERE SUCCESSFULLY PASSED\n"
    fi
    cd ..

}

function check_installed_software {
    RATS_VERSION="$(rats -h)"
    if [[ $RATS_VERSION = RATS* ]]
    then
        RATS_INSTALLED=1
    else
        RATS_INSTALLED=0
    fi

    CPPCHECK_VERSION="$(cppcheck --version)"
    if [[ $CPPCHECK_VERSION = Cppcheck* ]]
    then
        CPPCHECK_INTSALLED=1
    else
        CPPCHECK_INSTALLED=0
    fi

    VALGRIND_VERSION="$(valgrind --version)"
    if [[ $VALGRIND_VERSION = valgrind* ]]
    then
        VALGRIND_INSTALLED=1
    else
        VALGRIND_INSTALLED=0
    fi
}

function run_valgrind {
    echo "Starting valgrind..."
    cd build
    if [[ ! -d valgrindReports ]]
    then
        mkdir valgrindReports
    fi
    for test in test_*
    do
        valgrind --leak-check=full --show-reachable=yes --trace-children=yes -v --log-file=./valgrind.log --xml=yes --xml-file=./valgrindReports/$test.memreport.xml ./$test
        chmod 0666 ./valgrindReports/$test.memreport.xml
    done
    cd ..
    echo "Valgrind analysis finished."
}

function run_cppcheck {
    echo "Starting Cppcheck..."
    cppcheck --enable=all --std=c99 --xml --suppress=unusedFunction src/ test/ 2>build/cppcheck_.xml > build/cppcheck.log
    sed 's@file=\"@file=\"client\/client-multi\/client-c\/@g' build/cppcheck_.xml > build/cppcheck.xml
    rm build/cppcheck_.xml
    echo "Cppcheck analysis finished."
}

function run_rats {
    echo "Starting RATS..."
    rats --xml `find src/ -name *.[ch]` > build/rats-report.xml
    echo "RATS analysis finished."
}

function run_analysis {
    check_installed_software
    if [[ VALGRIND_INSTALLED -eq 1 ]]
    then
        run_valgrind
    fi

    if [[ CPPCHECK_INTSALLED -eq 1 ]]
    then
        run_cppcheck
    fi

    if [[ RATS_INSTALLED -eq 1 ]]
    then
        run_rats
    fi
}

function clean {
    if [[ -d build ]]
    then
        cd build
        if [[ -f Makefile ]]
        then
            make clean
        fi
        cd .. && rm -r build
    fi
}

for cmd in $@
do

case "$cmd" in
    build)
        COLLECT_COVERAGE=0
        UNITTESTS_COMPILE=0
        prepare_build &&
        build
    ;;

    install)
        cd build && make install && cd ..
    ;;

    test)
        COLLECT_COVERAGE=1
        UNITTESTS_COMPILE=1
        prepare_build &&
        build &&
        execute_tests &&
        run_analysis
    ;;

    clean)
        clean
    ;;

    *)
        help
    ;;
esac
done


finish nfs server deployment script

finish nfs server deployment script

#!/bin/bash
# Description: create a nfs server for persistent volume
# Version: 0.1
#
# Author: wangtao 479021795@qq.com
# Date: 2016/01/03

set -o xtrace

if [[ $UID -ne 0 ]]; then
    echo "Not root user. Please run as root."
    exit 0
fi

bash ./update_source.sh

apt-get install -y nfs-kernel-server nfs-common

mkdir /hummer
chown -R wangtao:wangtao /hummer
cat >>/etc/exports <<EOF
/hummer *(rw,sync,no_root_squash,no_subtree_check)
EOF

# Restart service
service rpcbind restart
service nfs-kernel-server restart

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


Create begin.sh

Create begin.sh

Former-commit-id: 6c702de1c834dc83fa5d061357162102c9df17ca

mkdir /var/run/intelmq
chmod -R 770 /etc/intelmq/
chmod -R 700 /var/run/intelmq
chmod -R 700 /var/lib/intelmq
chmod -R 700 /usr/local/bin/intelmqctl
chmod -R 700 /var/log/intelmq
chown -R intelmq.intelmq /etc/intelmq/
chown -R intelmq.intelmq /var/run/intelmq
chown -R intelmq.intelmq /var/lib/intelmq
chown -R intelmq.intelmq /usr/local/bin/intelmqctl
chown -R intelmq.intelmq /var/log/intelmq

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


zsh: Add npm install auto completion

zsh: Add npm install auto completion

_npm_install_completion() {
	local si=$IFS

	# if 'install' or 'i ' is one of the subcommands, then...
	if [[ ${words} =~ 'install' ]] || [[ ${words} =~ 'i ' ]]; then

		# add the result of `ls ~/.npm` (npm cache) as completion options
		compadd -- $(COMP_CWORD=$((CURRENT-1)) \
			COMP_LINE=$BUFFER \
			COMP_POINT=0 \
			ls ~/.npm -- "${words[@]}" \
			2>/dev/null)
	fi

	IFS=$si
}

compdef _npm_install_completion 'npm'

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


Fix installation of Postgresql repo.

Fix installation of Postgresql repo.

https://launchpad.net/~pitti/+archive/postgresql
add-apt-repository ppa:pitti/postgresql does not work on new OS install

#!/bin/bash
#
# Newfies-Dialer License
# http://www.newfies-dialer.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#

#
# To download and run the script on your server :
#
# >> Install with Master script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/master/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#
# >> Install with develop script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/develop/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#

#Set branch to install DEVEL/STABLE
BRANCH="master"

#Install mode can me either CLONE or DOWNLOAD
INSTALL_MODE='CLONE'
DB_BACKEND=PostgreSQL
DATETIME=$(date +"%Y%m%d%H%M%S")
KERNEL_ARCH=$(uname -p)
INSTALL_DIR='/usr/share/newfies'
LUA_DIR='/usr/share/newfies-lua'
INSTALL_DIR_WELCOME='/var/www/newfies'
DATABASENAME='newfies_dialer_db'
DB_USERSALT=`</dev/urandom tr -dc 0-9| (head -c $1 > /dev/null 2>&1 || head -c 5)`
DB_USERNAME="newfies_dialer_$DB_USERSALT"
DB_PASSWORD=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 20)`
DB_HOSTNAME='localhost'
DB_PORT='5432'
FS_INSTALLED_PATH='/usr/local/freeswitch'
NEWFIES_USER='newfies_dialer'
CELERYD_USER='celery'
CELERYD_GROUP='celery'
NEWFIES_ENV='newfies-dialer'
HTTP_PORT='8008'
DEBVERSION=$( lsb_release -cs )

#Django bug https://code.djangoproject.com/ticket/16017
export LANG="en_US.UTF-8"

# Identify Linux Distribution type
func_identify_os() {
    if [ -f /etc/debian_version ] ; then
        if [ "$(lsb_release -cs)" != "precise" ]; then
            echo "This script is only intended to run on Ubuntu 12.04 TLS"
            exit 1
        fi
    else
        echo "This script is only intended to run on Ubuntu 12.04 TLS"
        exit 1
    fi
}

#Function accept_license
func_accept_license() {
    clear
    echo ""
    echo "Newfies-Dialer License MPL V2.0"
    echo "Further information at http://www.newfies-dialer.org/support/licensing/"
    echo ""
    echo "This Source Code Form is subject to the terms of the Mozilla Public"
    echo "License, v. 2.0. If a copy of the MPL was not distributed with this file,"
    echo "You can obtain one at http://mozilla.org/MPL/2.0/."
    echo ""
    echo "Copyright (C) 2011-2013 Star2Billing S.L."
    echo ""
    echo ""
    echo "I agree to be bound by the terms of the license - [YES/NO]"
    echo ""
    read ACCEPT

    while [ "$ACCEPT" != "yes" ]  && [ "$ACCEPT" != "Yes" ] && [ "$ACCEPT" != "YES" ]  && [ "$ACCEPT" != "no" ]  && [ "$ACCEPT" != "No" ]  && [ "$ACCEPT" != "NO" ]; do
        echo "I agree to be bound by the terms of the license - [YES/NO]"
        read ACCEPT
    done
    if [ "$ACCEPT" != "yes" ]  && [ "$ACCEPT" != "Yes" ] && [ "$ACCEPT" != "YES" ]; then
        echo "License rejected !"
        exit 0
    fi
}

#Function install the landing page
func_install_landing_page() {
    mkdir -p $INSTALL_DIR_WELCOME
    # Copy files
    cp -r /usr/src/newfies-dialer/install/landing-page/* $INSTALL_DIR_WELCOME
    echo ""
    echo "Add Nginx configuration for Welcome page..."
    cp -rf /usr/src/newfies-dialer/install/nginx/global /etc/nginx/
    cp /usr/src/newfies-dialer/install/nginx/sites-available/newfies_dialer.conf /etc/nginx/sites-available/
    ln -s /etc/nginx/sites-available/newfies_dialer.conf /etc/nginx/sites-enabled/newfies_dialer.conf

    #Remove default NGINX landing page
    rm /etc/nginx/sites-enabled/default

    #Restart Nginx
    service nginx restart

    #Update Welcome page IP
    sed -i "s/LOCALHOST/$IPADDR:$HTTP_PORT/g" $INSTALL_DIR_WELCOME/index.html
}

func_check_dependencies() {
    echo ""
    echo "Checking Python dependencies..."
    echo ""

    #Check South
    grep_pip=`pip freeze| grep South`
    if echo $grep_pip | grep -i "South" > /dev/null ; then
        echo "OK : South installed..."
    else
        echo "Error : South not installed..."
        exit 1
    fi

    #Check Django
    grep_pip=`pip freeze| grep Django`
    if echo $grep_pip | grep -i "Django" > /dev/null ; then
        echo "OK : Django installed..."
    else
        echo "Error : Django not installed..."
        exit 1
    fi

    #Check celery
    grep_pip=`pip freeze| grep celery`
    if echo $grep_pip | grep -i "celery" > /dev/null ; then
        echo "OK : celery installed..."
    else
        echo "Error : celery not installed..."
        exit 1
    fi

    #Check django-tastypie
    grep_pip=`pip freeze| grep django-tastypie`
    if echo $grep_pip | grep -i "django-tastypie" > /dev/null ; then
        echo "OK : django-tastypie installed..."
    else
        echo "Error : django-tastypie not installed..."
        exit 1
    fi

    echo ""
    echo "Python dependencies successfully installed!"
    echo ""
}

#Configure Firewall
func_iptables_configuration() {
    #add http port
    iptables -I INPUT 2 -p tcp -m state --state NEW -m tcp --dport $HTTP_PORT -j ACCEPT
    iptables -I INPUT 3 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

    service iptables save
}

#Fuction to create the virtual env
func_setup_virtualenv() {
    echo "This will install virtualenv & virtualenvwrapper"
    echo "and create a new virtualenv : $NEWFIES_ENV"

    easy_install virtualenv
    easy_install virtualenvwrapper

    # Enable virtualenvwrapper
    chk=`grep "virtualenvwrapper" ~/.bashrc|wc -l`
    if [ $chk -lt 1 ] ; then
        echo "Set Virtualenvwrapper into bash"
        echo "export WORKON_HOME=/usr/share/virtualenvs" >> ~/.bashrc
        echo "source $SCRIPT_VIRTUALENVWRAPPER" >> ~/.bashrc
    fi

    # Setup virtualenv
    export WORKON_HOME=/usr/share/virtualenvs
    source $SCRIPT_VIRTUALENVWRAPPER

    mkvirtualenv $NEWFIES_ENV
    workon $NEWFIES_ENV

    echo "Virtualenv $NEWFIES_ENV created and activated"
}

#Function to install Frontend
func_install_frontend(){

    echo ""
    echo ""
    echo "This script will install Newfies-Dialer on your server"
    echo "======================================================"
    echo ""

    #python setup tools
    echo "Install Dependencies and python modules..."

    #Install Postgresql repository (https://wiki.postgresql.org/wiki/Apt)
    if grep -Fxq "deb http://apt.postgresql.org/pub/repos/apt/ $DEBVERSION-pgdg main" /etc/apt/sources.list.d/pgdg.list
    then
        echo "Postgresql repository already installed"
    else
        echo "deb http://apt.postgresql.org/pub/repos/apt/ $DEBVERSION-pgdg main" >> /etc/apt/sources.list.d/pgdg.list
        wget -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
    fi

    apt-get update
    apt-get -y install python-setuptools python-dev build-essential
    apt-get -y install nginx supervisor
    apt-get -y install git-core mercurial gawk
    apt-get -y install python-pip python-dev
    #for audiofile convertion
    apt-get -y install libsox-fmt-mp3 libsox-fmt-all mpg321 ffmpeg

    #PostgreSQL
    apt-get -y install python-software-properties
    apt-get -y install postgresql-9.2 postgresql-server-dev-9.2
    apt-get -y install libpq-dev
    #Start PostgreSQL
    /etc/init.d/postgresql start

    #Lua Deps
    apt-get -y install liblua5.1-sql-postgres-dev
    apt-get -y install liblua5.1-curl0 liblua5.1-curl-dev
    #Memcached
    apt-get install memcached
    #Luarocks
    apt-get -y install luarocks luasocket
    luarocks install luasql-postgres PGSQL_INCDIR=/usr/include/postgresql/
    luarocks install lualogging
    luarocks install loop
    luarocks install md5
    luarocks install luafilesystem
    luarocks install luajson
    luarocks install inspect
    luarocks install redis-lua
    luarocks install lua-cmsgpack

    #Create Newfies User
    echo ""
    echo "Create Newfies-Dialer User/Group : $NEWFIES_USER"
    useradd $NEWFIES_USER --user-group --system --no-create-home

    if [ -d "$INSTALL_DIR" ]; then
        # Newfies-Dialer is already installed
        clear
        echo ""
        echo "We detect an existing Newfies-Dialer Installation"
        echo "if you continue the existing installation will be removed!"
        echo ""
        echo "Press Enter to continue or CTRL-C to exit"
        read TEMP

        mkdir /tmp/old-newfies-dialer_$DATETIME
        mv $INSTALL_DIR /tmp/old-newfies-dialer_$DATETIME
        mkdir /tmp/old-lua-newfies-dialer_$DATETIME
        mv $LUA_DIR /tmp/old-lua-newfies-dialer_$DATETIME
        echo "Files from $INSTALL_DIR has been moved to /tmp/old-newfies-dialer_$DATETIME and /tmp/old-lua-newfies-dialer_$DATETIME"

        if [ `sudo -u postgres psql -qAt --list | egrep '^$DATABASENAME\|' | wc -l` -eq 1 ]; then
            echo ""
            echo "Run backup with postgresql..."
            sudo -u postgres pg_dump $DATABASENAME > /tmp/old-newfies-dialer_$DATETIME.pgsqldump.sql
            echo "PostgreSQL Dump of database $DATABASENAME added in /tmp/old-newfies-dialer_$DATETIME.pgsqldump.sql"
            echo "Press Enter to continue"
            read TEMP
        fi
    fi

    #Create and enable virtualenv
    func_setup_virtualenv

    #get Newfies-Dialer
    echo "Install Newfies-Dialer..."
    cd /usr/src/
    rm -rf newfies-dialer
    mkdir /var/log/newfies

    case $INSTALL_MODE in
        'CLONE')
            git clone git://github.com/Star2Billing/newfies-dialer.git
            #Install Develop / Master
            if echo $BRANCH | grep -i "^develop" > /dev/null ; then
                cd newfies-dialer
                git checkout -b develop --track origin/develop
            fi
        ;;
        # 'DOWNLOAD')
        #    VERSION=master
        #    wget --no-check-certificate https://github.com/Star2Billing/newfies-dialer/tarball/$VERSION
        #    mv master Star2Billing-newfies-dialer-$VERSION.tar.gz
        #    tar xvzf Star2Billing-newfies-dialer-*.tar.gz
        #    rm -rf Star2Billing-newfies-*.tar.gz
        #    mv newfies-dialer newfies-dialer_$DATETIME
        #    mv Star2Billing-newfies-* newfies-dialer
        #;;
    esac

    #Copy files
    cp -r /usr/src/newfies-dialer/newfies $INSTALL_DIR
    cp -r /usr/src/newfies-dialer/lua $LUA_DIR
    cd $LUA_DIR/libs/
    wget --no-check-certificate https://raw.github.com/areski/lua-acapela/master/acapela.lua

    #Install Newfies-Dialer depencencies
    easy_install -U distribute
    #For python 2.6 only
    pip install importlib
    echo "Install basic requirements..."
    for line in $(cat /usr/src/newfies-dialer/install/requirements/basic-requirements.txt | grep -v \#)
    do
        pip install $line
    done
    echo "Install Django requirements..."
    for line in $(cat /usr/src/newfies-dialer/install/requirements/django-requirements.txt | grep -v \#)
    do
        pip install $line
    done
    #pip install plivohelper

    #Install Python ESL
    cd /usr/src/freeswitch/libs/esl
    make pymod-install

    #Check Python dependencies
    func_check_dependencies

    echo "**********"
    echo "PIP Freeze"
    echo "**********"
    pip freeze

    #Copy settings_local.py into newfies dir
    cp /usr/src/newfies-dialer/install/conf/settings_local.py $INSTALL_DIR

    #Update Secret Key
    echo "Update Secret Key..."
    RANDPASSW=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 50)`
    sed -i "s/^SECRET_KEY.*/SECRET_KEY = \'$RANDPASSW\'/g"  $INSTALL_DIR/settings.py
    echo ""

    #Disable Debug
    sed -i "s/DEBUG = True/DEBUG = False/g"  $INSTALL_DIR/settings_local.py
    sed -i "s/TEMPLATE_DEBUG = DEBUG/TEMPLATE_DEBUG = False/g"  $INSTALL_DIR/settings_local.py

    #Setup settings_local.py for POSTGRESQL
    sed -i "s/DATABASENAME/$DATABASENAME/"  $INSTALL_DIR/settings_local.py
    sed -i "s/DB_USERNAME/$DB_USERNAME/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_PASSWORD/$DB_PASSWORD/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_HOSTNAME/$DB_HOSTNAME/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_PORT/$DB_PORT/" $INSTALL_DIR/settings_local.py

    #Setup settings_local.py for POSTGRESQL
    sed -i "s/newfiesdb/$DATABASENAME/"  $LUA_DIR/libs/settings.lua
    sed -i "s/newfiesuser/$DB_USERNAME/" $LUA_DIR/libs/settings.lua
    sed -i "s/password/$DB_PASSWORD/" $LUA_DIR/libs/settings.lua
    sed -i "s/127.0.0.1/$DB_HOSTNAME/" $LUA_DIR/libs/settings.lua
    sed -i "s/5432/$DB_PORT/" $LUA_DIR/libs/settings.lua

    # Create the Database
    echo "We will remove existing Database"
    echo "Press Enter to continue"
    read TEMP
    echo "sudo -u postgres dropdb $DATABASENAME"
    sudo -u postgres dropdb $DATABASENAME
    # echo "Remove Existing Database if exists..."
    #if [ `sudo -u postgres psql -qAt --list | egrep $DATABASENAME | wc -l` -eq 1 ]; then
    #     echo "sudo -u postgres dropdb $DATABASENAME"
    #     sudo -u postgres dropdb $DATABASENAME
    # fi
    echo "Create Database..."
    echo "sudo -u postgres createdb $DATABASENAME"
    sudo -u postgres createdb $DATABASENAME

    #CREATE ROLE / USER
    echo "Create Postgresql user $DB_USERNAME"
    #echo "sudo -u postgres createuser --no-createdb --no-createrole --no-superuser $DB_USERNAME"
    #sudo -u postgres createuser --no-createdb --no-createrole --no-superuser $DB_USERNAME
    echo "sudo -u postgres psql --command=\"create user $DB_USERNAME with password 'XXXXXXXXXXXX';\""
    sudo -u postgres psql --command="CREATE USER $DB_USERNAME with password '$DB_PASSWORD';"

    echo "Grant all privileges to user..."
    sudo -u postgres psql --command="GRANT ALL PRIVILEGES on database $DATABASENAME to $DB_USERNAME;"

    cd $INSTALL_DIR/

    #Fix permission on python-egg
    mkdir /usr/share/newfies/.python-eggs
    chown $NEWFIES_USER:$NEWFIES_USER /usr/share/newfies/.python-eggs
    mkdir database

    #Upload audio files
    mkdir -p /usr/share/newfies/usermedia/upload/audiofiles
    chown -R $NEWFIES_USER:$NEWFIES_USER /usr/share/newfies/usermedia

    #Following lines is for apache logs
    touch /var/log/newfies/newfies-django.log
    touch /var/log/newfies/newfies-django-db.log
    touch /var/log/newfies/err-apache-newfies.log
    chown -R $NEWFIES_USER:$NEWFIES_USER /var/log/newfies

    python manage.py syncdb --noinput
    python manage.py migrate
    echo ""
    echo "Create a super admin user..."
    python manage.py createsuperuser

    #Collect static files from apps and other locations in a single location.
    python manage.py collectstatic --noinput

    #Load Countries Dialcode
    #python manage.py load_country_dialcode

    IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
    IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`
    if [ -z "$IPADDR" ]; then
        clear
        echo "We have not detected your IP address automatically, please enter it manually"
        read IPADDR
    fi

    ##Update Freeswitch XML CDR
    #NEWFIES_CDR_API='api\/v1\/store_cdr\/'
    #CDR_API_URL="http:\/\/$IPADDR:$HTTP_PORT\/$NEWFIES_CDR_API"
    #cd "$FS_INSTALLED_PATH/conf/autoload_configs/"
    #sed -i "s/NEWFIES_API_STORE_CDR/$CDR_API_URL/g" xml_cdr.conf.xml
    #
    ##Update API username and password
    #sed -i "s/APIUSERNAME/$APIUSERNAME/g" xml_cdr.conf.xml
    #sed -i "s/APIPASSWORD/$APIPASSWORD/g" xml_cdr.conf.xml

    #Update Authorize local IP
    sed -i "s/SERVER_IP_PORT/$IPADDR:$HTTP_PORT/g" $INSTALL_DIR/settings_local.py
    sed -i "s/#'SERVER_IP',/'$IPADDR',/g" $INSTALL_DIR/settings_local.py
    sed -i "s/dummy/esl/g" $INSTALL_DIR/settings_local.py

    #Get TZ
    ZONE=$(head -1 /etc/timezone)

    #Set Timezone in settings_local.py
    sed -i "s@Europe/Madrid@$ZONE@g" $INSTALL_DIR/settings_local.py
    sed -i "s@Europe/Madrid@$ZONE@g" $INSTALL_DIR/celeryconfig.py

    # * * NGINX / SUPERVISOR * *

    #Configure and Start supervisor
    cp /usr/src/newfies-dialer/install/supervisor/gunicorn_newfies_dialer.conf /etc/supervisor/conf.d/
    /etc/init.d/supervisor force-stop
    /etc/init.d/supervisor start

    #Prepare and Start Nginx
    echo "Prepare Nginx configuration..."
    cp -rf /usr/src/newfies-dialer/install/nginx/global /etc/nginx/
    cp /usr/src/newfies-dialer/install/nginx/sites-available/newfies_dialer /etc/nginx/sites-available/
    service nginx restart

    # * * LOGROTATE * *

    echo "Install Logrotate..."
    # First delete to avoid error when running the script several times.
    rm /etc/logrotate.d/newfies_dialer
    touch /etc/logrotate.d/newfies_dialer
    echo '
    /var/log/newfies/*.log {
        daily
        rotate 10
        size = 50M
        missingok
        compress
    }
    '  >> /etc/logrotate.d/newfies_dialer

    logrotate /etc/logrotate.d/newfies_dialer

    #Restart FreeSWITCH to find the startup-script
    /etc/init.d/freeswitch restart

    echo ""
    echo "*****************************************************************"
    echo "Congratulations, Newfies-Dialer Web Application is now installed!"
    echo "*****************************************************************"
    echo ""
    echo "Please log on to Newfies-Dialer at "
    echo "http://$IPADDR:$HTTP_PORT"
    echo "the username and password are the ones you entered during this installation."
    echo ""
    echo "Thank you for installing Newfies-Dialer"
    echo "Yours"
    echo "The Star2Billing Team"
    echo "http://www.star2billing.com and http://www.newfies-dialer.org/"
    echo ""
    echo "**************************************************************"
    echo ""
}

#Function to install backend
func_install_backend() {
    echo ""
    echo ""
    echo "This will install Newfies-Dialer Backend, Celery & Redis on your server"
    echo "Press Enter to continue or CTRL-C to exit"
    read TEMP

    IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
    IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`
    if [ -z "$IPADDR" ]; then
        clear
        echo "we have not detected your IP address automatically, please enter it manually"
        read IPADDR
    fi

    #Create directory for pid file
    mkdir -p /var/run/celery

    #Install Celery & redis-server
    func_install_redis_server

    #Memcache installation
    #pip install python-memcached

    echo "Configure Celery..."

    # Add init-scripts
    cp /usr/src/newfies-dialer/install/celery-init/debian/etc/default/newfies-celeryd /etc/default/
    cp /usr/src/newfies-dialer/install/celery-init/debian/etc/init.d/newfies-celeryd /etc/init.d/
    # Configure init-scripts
    sed -i "s/CELERYD_USER='celery'/CELERYD_USER='$CELERYD_USER'/g"  /etc/default/newfies-celeryd
    sed -i "s/CELERYD_GROUP='celery'/CELERYD_GROUP='$CELERYD_GROUP'/g"  /etc/default/newfies-celeryd
    chmod +x /etc/default/newfies-celeryd
    chmod +x /etc/init.d/newfies-celeryd

    /etc/init.d/newfies-celeryd restart
    cd /etc/init.d; update-rc.d newfies-celeryd defaults 99

    #Check permissions on /dev/shm to ensure that celery can start and run for openVZ.
    DIR="/dev/shm"
    echo "Checking the permissions for $dir"
    stat $DIR
    if [ `stat -c "%a" $DIR` -ge 777 ] ; then
        echo "$DIR has Read Write permissions."
    else
        echo "$DIR has no read write permissions."
        chmod -R 777 /dev/shm
        if [ `grep -i /dev/shm /etc/fstab | wc -l` -eq 0 ]; then
            echo "Adding fstab entry to set permissions /dev/shm"
            echo "none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0" >> /etc/fstab
        fi
    fi

    echo ""
    echo "**************************************************************"
    echo "Congratulations, Newfies-Dialer Backend is now installed!"
    echo "**************************************************************"
    echo ""
    echo "Thank you for installing Newfies-Dialer"
    echo "Yours"
    echo "The Star2Billing Team"
    echo "http://www.star2billing.com and http://www.newfies-dialer.org/"
    echo ""
    echo "**************************************************************"
    echo ""
}

#Install recent version of redis-server
func_install_redis_server() {
    echo "Install Redis-server ..."
    apt-get -y install redis-server
    /etc/init.d/redis-server restart
}

#Menu Section for Script
show_menu_newfies() {
    clear
    echo " > Newfies-Dialer Installation Menu"
    echo "====================================="
    echo "  1)  Install All"
    echo "  2)  Install Newfies-Dialer Web Frontend"
    echo "  3)  Install Newfies-Dialer Backend / Celery"
    echo "  0)  Quit"
    echo -n "(0-3) : "
    read OPTION < /dev/tty
}

# * * * * * * * * * * * * Start Script * * * * * * * * * * * *

#Identify the OS
func_identify_os

#Prepare settings for installation
SCRIPT_VIRTUALENVWRAPPER="/usr/local/bin/virtualenvwrapper.sh"

#Request the user to accept the license
func_accept_license

ExitFinish=0

while [ $ExitFinish -eq 0 ]; do

    # Show menu with Installation items
    show_menu_newfies

    case $OPTION in
        1)
            func_install_frontend
            func_install_landing_page
            func_install_backend
            echo done
        ;;
        2)
            func_install_frontend
            func_install_landing_page
        ;;
        3)
            func_install_backend
        ;;
        0)
        ExitFinish=1
        ;;
        *)
    esac

done

# Clean the system
#=================
# deactivate ; rm -rf /usr/share/newfies ; rm -rf /var/log/newfies ; rmvirtualenv newfies-dialer ; rm -rf /etc/init.d/newfies-celer* ; rm -rf /etc/default/newfies-celeryd ; rm /etc/apache2/sites-enabled/newfies.conf

#!/bin/bash
#
# Newfies-Dialer License
# http://www.newfies-dialer.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#

#
# To download and run the script on your server :
#
# >> Install with Master script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/master/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#
# >> Install with develop script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/develop/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#

#Set branch to install DEVEL/STABLE
BRANCH="master"

#Install mode can me either CLONE or DOWNLOAD
INSTALL_MODE='CLONE'
DB_BACKEND=PostgreSQL
DATETIME=$(date +"%Y%m%d%H%M%S")
KERNEL_ARCH=$(uname -p)
INSTALL_DIR='/usr/share/newfies'
LUA_DIR='/usr/share/newfies-lua'
INSTALL_DIR_WELCOME='/var/www/newfies'
DATABASENAME='newfies_dialer_db'
DB_USERSALT=`</dev/urandom tr -dc 0-9| (head -c $1 > /dev/null 2>&1 || head -c 5)`
DB_USERNAME="newfies_dialer_$DB_USERSALT"
DB_PASSWORD=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 20)`
DB_HOSTNAME='localhost'
DB_PORT='5432'
FS_INSTALLED_PATH='/usr/local/freeswitch'
NEWFIES_USER='newfies_dialer'
CELERYD_USER='celery'
CELERYD_GROUP='celery'
NEWFIES_ENV='newfies-dialer'
HTTP_PORT='8008'

#Django bug https://code.djangoproject.com/ticket/16017
export LANG="en_US.UTF-8"

# Identify Linux Distribution type
func_identify_os() {
    if [ -f /etc/debian_version ] ; then
        if [ "$(lsb_release -cs)" != "precise" ]; then
            echo "This script is only intended to run on Ubuntu 12.04 TLS"
            exit 1
        fi
    else
        echo "This script is only intended to run on Ubuntu 12.04 TLS"
        exit 1
    fi
}

#Function accept_license
func_accept_license() {
    clear
    echo ""
    echo "Newfies-Dialer License MPL V2.0"
    echo "Further information at http://www.newfies-dialer.org/support/licensing/"
    echo ""
    echo "This Source Code Form is subject to the terms of the Mozilla Public"
    echo "License, v. 2.0. If a copy of the MPL was not distributed with this file,"
    echo "You can obtain one at http://mozilla.org/MPL/2.0/."
    echo ""
    echo "Copyright (C) 2011-2013 Star2Billing S.L."
    echo ""
    echo ""
    echo "I agree to be bound by the terms of the license - [YES/NO]"
    echo ""
    read ACCEPT

    while [ "$ACCEPT" != "yes" ]  && [ "$ACCEPT" != "Yes" ] && [ "$ACCEPT" != "YES" ]  && [ "$ACCEPT" != "no" ]  && [ "$ACCEPT" != "No" ]  && [ "$ACCEPT" != "NO" ]; do
        echo "I agree to be bound by the terms of the license - [YES/NO]"
        read ACCEPT
    done
    if [ "$ACCEPT" != "yes" ]  && [ "$ACCEPT" != "Yes" ] && [ "$ACCEPT" != "YES" ]; then
        echo "License rejected !"
        exit 0
    fi
}

#Function install the landing page
func_install_landing_page() {
    mkdir -p $INSTALL_DIR_WELCOME
    # Copy files
    cp -r /usr/src/newfies-dialer/install/landing-page/* $INSTALL_DIR_WELCOME
    echo ""
    echo "Add Nginx configuration for Welcome page..."
    cp -rf /usr/src/newfies-dialer/install/nginx/global /etc/nginx/
    cp /usr/src/newfies-dialer/install/nginx/sites-available/newfies_dialer.conf /etc/nginx/sites-available/
    ln -s /etc/nginx/sites-available/newfies_dialer.conf /etc/nginx/sites-enabled/newfies_dialer.conf

    #Remove default NGINX landing page
    rm /etc/nginx/sites-enabled/default

    #Restart Nginx
    service nginx restart

    #Update Welcome page IP
    sed -i "s/LOCALHOST/$IPADDR:$HTTP_PORT/g" $INSTALL_DIR_WELCOME/index.html
}

func_check_dependencies() {
    echo ""
    echo "Checking Python dependencies..."
    echo ""

    #Check South
    grep_pip=`pip freeze| grep South`
    if echo $grep_pip | grep -i "South" > /dev/null ; then
        echo "OK : South installed..."
    else
        echo "Error : South not installed..."
        exit 1
    fi

    #Check Django
    grep_pip=`pip freeze| grep Django`
    if echo $grep_pip | grep -i "Django" > /dev/null ; then
        echo "OK : Django installed..."
    else
        echo "Error : Django not installed..."
        exit 1
    fi

    #Check celery
    grep_pip=`pip freeze| grep celery`
    if echo $grep_pip | grep -i "celery" > /dev/null ; then
        echo "OK : celery installed..."
    else
        echo "Error : celery not installed..."
        exit 1
    fi

    #Check django-tastypie
    grep_pip=`pip freeze| grep django-tastypie`
    if echo $grep_pip | grep -i "django-tastypie" > /dev/null ; then
        echo "OK : django-tastypie installed..."
    else
        echo "Error : django-tastypie not installed..."
        exit 1
    fi

    echo ""
    echo "Python dependencies successfully installed!"
    echo ""
}

#Configure Firewall
func_iptables_configuration() {
    #add http port
    iptables -I INPUT 2 -p tcp -m state --state NEW -m tcp --dport $HTTP_PORT -j ACCEPT
    iptables -I INPUT 3 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

    service iptables save
}

#Fuction to create the virtual env
func_setup_virtualenv() {
    echo "This will install virtualenv & virtualenvwrapper"
    echo "and create a new virtualenv : $NEWFIES_ENV"

    easy_install virtualenv
    easy_install virtualenvwrapper

    # Enable virtualenvwrapper
    chk=`grep "virtualenvwrapper" ~/.bashrc|wc -l`
    if [ $chk -lt 1 ] ; then
        echo "Set Virtualenvwrapper into bash"
        echo "export WORKON_HOME=/usr/share/virtualenvs" >> ~/.bashrc
        echo "source $SCRIPT_VIRTUALENVWRAPPER" >> ~/.bashrc
    fi

    # Setup virtualenv
    export WORKON_HOME=/usr/share/virtualenvs
    source $SCRIPT_VIRTUALENVWRAPPER

    mkvirtualenv $NEWFIES_ENV
    workon $NEWFIES_ENV

    echo "Virtualenv $NEWFIES_ENV created and activated"
}

#Function to install Frontend
func_install_frontend(){

    echo ""
    echo ""
    echo "This script will install Newfies-Dialer on your server"
    echo "======================================================"
    echo ""

    #python setup tools
    echo "Install Dependencies and python modules..."

    add-apt-repository ppa:pitti/postgresql
    apt-get update
    apt-get -y install python-setuptools python-dev build-essential
    apt-get -y install nginx supervisor
    apt-get -y install git-core mercurial gawk
    apt-get -y install python-pip python-dev
    #for audiofile convertion
    apt-get -y install libsox-fmt-mp3 libsox-fmt-all mpg321 ffmpeg

    #PostgreSQL
    apt-get -y install python-software-properties
    apt-get -y install postgresql-9.2 postgresql-server-dev-9.2
    apt-get -y install libpq-dev
    #Start PostgreSQL
    /etc/init.d/postgresql start

    #Lua Deps
    apt-get -y install liblua5.1-sql-postgres-dev
    apt-get -y install liblua5.1-curl0 liblua5.1-curl-dev
    #Memcached
    apt-get install memcached
    #Luarocks
    apt-get -y install luarocks luasocket
    luarocks install luasql-postgres PGSQL_INCDIR=/usr/include/postgresql/
    luarocks install lualogging
    luarocks install loop
    luarocks install md5
    luarocks install luafilesystem
    luarocks install luajson
    luarocks install inspect
    luarocks install redis-lua
    luarocks install lua-cmsgpack

    #Create Newfies User
    echo ""
    echo "Create Newfies-Dialer User/Group : $NEWFIES_USER"
    useradd $NEWFIES_USER --user-group --system --no-create-home

    if [ -d "$INSTALL_DIR" ]; then
        # Newfies-Dialer is already installed
        clear
        echo ""
        echo "We detect an existing Newfies-Dialer Installation"
        echo "if you continue the existing installation will be removed!"
        echo ""
        echo "Press Enter to continue or CTRL-C to exit"
        read TEMP

        mkdir /tmp/old-newfies-dialer_$DATETIME
        mv $INSTALL_DIR /tmp/old-newfies-dialer_$DATETIME
        mkdir /tmp/old-lua-newfies-dialer_$DATETIME
        mv $LUA_DIR /tmp/old-lua-newfies-dialer_$DATETIME
        echo "Files from $INSTALL_DIR has been moved to /tmp/old-newfies-dialer_$DATETIME and /tmp/old-lua-newfies-dialer_$DATETIME"

        if [ `sudo -u postgres psql -qAt --list | egrep '^$DATABASENAME\|' | wc -l` -eq 1 ]; then
            echo ""
            echo "Run backup with postgresql..."
            sudo -u postgres pg_dump $DATABASENAME > /tmp/old-newfies-dialer_$DATETIME.pgsqldump.sql
            echo "PostgreSQL Dump of database $DATABASENAME added in /tmp/old-newfies-dialer_$DATETIME.pgsqldump.sql"
            echo "Press Enter to continue"
            read TEMP
        fi
    fi

    #Create and enable virtualenv
    func_setup_virtualenv

    #get Newfies-Dialer
    echo "Install Newfies-Dialer..."
    cd /usr/src/
    rm -rf newfies-dialer
    mkdir /var/log/newfies

    case $INSTALL_MODE in
        'CLONE')
            git clone git://github.com/Star2Billing/newfies-dialer.git
            #Install Develop / Master
            if echo $BRANCH | grep -i "^develop" > /dev/null ; then
                cd newfies-dialer
                git checkout -b develop --track origin/develop
            fi
        ;;
        # 'DOWNLOAD')
        #    VERSION=master
        #    wget --no-check-certificate https://github.com/Star2Billing/newfies-dialer/tarball/$VERSION
        #    mv master Star2Billing-newfies-dialer-$VERSION.tar.gz
        #    tar xvzf Star2Billing-newfies-dialer-*.tar.gz
        #    rm -rf Star2Billing-newfies-*.tar.gz
        #    mv newfies-dialer newfies-dialer_$DATETIME
        #    mv Star2Billing-newfies-* newfies-dialer
        #;;
    esac

    #Copy files
    cp -r /usr/src/newfies-dialer/newfies $INSTALL_DIR
    cp -r /usr/src/newfies-dialer/lua $LUA_DIR
    cd $LUA_DIR/libs/
    wget --no-check-certificate https://raw.github.com/areski/lua-acapela/master/acapela.lua

    #Install Newfies-Dialer depencencies
    easy_install -U distribute
    #For python 2.6 only
    pip install importlib
    echo "Install basic requirements..."
    for line in $(cat /usr/src/newfies-dialer/install/requirements/basic-requirements.txt | grep -v \#)
    do
        pip install $line
    done
    echo "Install Django requirements..."
    for line in $(cat /usr/src/newfies-dialer/install/requirements/django-requirements.txt | grep -v \#)
    do
        pip install $line
    done
    #pip install plivohelper

    #Install Python ESL
    cd /usr/src/freeswitch/libs/esl
    make pymod-install

    #Check Python dependencies
    func_check_dependencies

    echo "**********"
    echo "PIP Freeze"
    echo "**********"
    pip freeze

    #Copy settings_local.py into newfies dir
    cp /usr/src/newfies-dialer/install/conf/settings_local.py $INSTALL_DIR

    #Update Secret Key
    echo "Update Secret Key..."
    RANDPASSW=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 50)`
    sed -i "s/^SECRET_KEY.*/SECRET_KEY = \'$RANDPASSW\'/g"  $INSTALL_DIR/settings.py
    echo ""

    #Disable Debug
    sed -i "s/DEBUG = True/DEBUG = False/g"  $INSTALL_DIR/settings_local.py
    sed -i "s/TEMPLATE_DEBUG = DEBUG/TEMPLATE_DEBUG = False/g"  $INSTALL_DIR/settings_local.py

    #Setup settings_local.py for POSTGRESQL
    sed -i "s/DATABASENAME/$DATABASENAME/"  $INSTALL_DIR/settings_local.py
    sed -i "s/DB_USERNAME/$DB_USERNAME/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_PASSWORD/$DB_PASSWORD/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_HOSTNAME/$DB_HOSTNAME/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_PORT/$DB_PORT/" $INSTALL_DIR/settings_local.py

    #Setup settings_local.py for POSTGRESQL
    sed -i "s/newfiesdb/$DATABASENAME/"  $LUA_DIR/libs/settings.lua
    sed -i "s/newfiesuser/$DB_USERNAME/" $LUA_DIR/libs/settings.lua
    sed -i "s/password/$DB_PASSWORD/" $LUA_DIR/libs/settings.lua
    sed -i "s/127.0.0.1/$DB_HOSTNAME/" $LUA_DIR/libs/settings.lua
    sed -i "s/5432/$DB_PORT/" $LUA_DIR/libs/settings.lua

    # Create the Database
    echo "We will remove existing Database"
    echo "Press Enter to continue"
    read TEMP
    echo "sudo -u postgres dropdb $DATABASENAME"
    sudo -u postgres dropdb $DATABASENAME
    # echo "Remove Existing Database if exists..."
    #if [ `sudo -u postgres psql -qAt --list | egrep $DATABASENAME | wc -l` -eq 1 ]; then
    #     echo "sudo -u postgres dropdb $DATABASENAME"
    #     sudo -u postgres dropdb $DATABASENAME
    # fi
    echo "Create Database..."
    echo "sudo -u postgres createdb $DATABASENAME"
    sudo -u postgres createdb $DATABASENAME

    #CREATE ROLE / USER
    echo "Create Postgresql user $DB_USERNAME"
    #echo "sudo -u postgres createuser --no-createdb --no-createrole --no-superuser $DB_USERNAME"
    #sudo -u postgres createuser --no-createdb --no-createrole --no-superuser $DB_USERNAME
    echo "sudo -u postgres psql --command=\"create user $DB_USERNAME with password 'XXXXXXXXXXXX';\""
    sudo -u postgres psql --command="CREATE USER $DB_USERNAME with password '$DB_PASSWORD';"

    echo "Grant all privileges to user..."
    sudo -u postgres psql --command="GRANT ALL PRIVILEGES on database $DATABASENAME to $DB_USERNAME;"

    cd $INSTALL_DIR/

    #Fix permission on python-egg
    mkdir /usr/share/newfies/.python-eggs
    chown $NEWFIES_USER:$NEWFIES_USER /usr/share/newfies/.python-eggs
    mkdir database

    #Upload audio files
    mkdir -p /usr/share/newfies/usermedia/upload/audiofiles
    chown -R $NEWFIES_USER:$NEWFIES_USER /usr/share/newfies/usermedia

    #Following lines is for apache logs
    touch /var/log/newfies/newfies-django.log
    touch /var/log/newfies/newfies-django-db.log
    touch /var/log/newfies/err-apache-newfies.log
    chown -R $NEWFIES_USER:$NEWFIES_USER /var/log/newfies

    python manage.py syncdb --noinput
    python manage.py migrate
    echo ""
    echo "Create a super admin user..."
    python manage.py createsuperuser

    #Collect static files from apps and other locations in a single location.
    python manage.py collectstatic --noinput

    #Load Countries Dialcode
    #python manage.py load_country_dialcode

    IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
    IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`
    if [ -z "$IPADDR" ]; then
        clear
        echo "We have not detected your IP address automatically, please enter it manually"
        read IPADDR
    fi

    ##Update Freeswitch XML CDR
    #NEWFIES_CDR_API='api\/v1\/store_cdr\/'
    #CDR_API_URL="http:\/\/$IPADDR:$HTTP_PORT\/$NEWFIES_CDR_API"
    #cd "$FS_INSTALLED_PATH/conf/autoload_configs/"
    #sed -i "s/NEWFIES_API_STORE_CDR/$CDR_API_URL/g" xml_cdr.conf.xml
    #
    ##Update API username and password
    #sed -i "s/APIUSERNAME/$APIUSERNAME/g" xml_cdr.conf.xml
    #sed -i "s/APIPASSWORD/$APIPASSWORD/g" xml_cdr.conf.xml

    #Update Authorize local IP
    sed -i "s/SERVER_IP_PORT/$IPADDR:$HTTP_PORT/g" $INSTALL_DIR/settings_local.py
    sed -i "s/#'SERVER_IP',/'$IPADDR',/g" $INSTALL_DIR/settings_local.py
    sed -i "s/dummy/esl/g" $INSTALL_DIR/settings_local.py

    #Get TZ
    ZONE=$(head -1 /etc/timezone)

    #Set Timezone in settings_local.py
    sed -i "s@Europe/Madrid@$ZONE@g" $INSTALL_DIR/settings_local.py
    sed -i "s@Europe/Madrid@$ZONE@g" $INSTALL_DIR/celeryconfig.py

    # * * NGINX / SUPERVISOR * *

    #Configure and Start supervisor
    cp /usr/src/newfies-dialer/install/supervisor/gunicorn_newfies_dialer.conf /etc/supervisor/conf.d/
    /etc/init.d/supervisor force-stop
    /etc/init.d/supervisor start

    #Prepare and Start Nginx
    echo "Prepare Nginx configuration..."
    cp -rf /usr/src/newfies-dialer/install/nginx/global /etc/nginx/
    cp /usr/src/newfies-dialer/install/nginx/sites-available/newfies_dialer /etc/nginx/sites-available/
    service nginx restart

    # * * LOGROTATE * *

    echo "Install Logrotate..."
    # First delete to avoid error when running the script several times.
    rm /etc/logrotate.d/newfies_dialer
    touch /etc/logrotate.d/newfies_dialer
    echo '
    /var/log/newfies/*.log {
        daily
        rotate 10
        size = 50M
        missingok
        compress
    }
    '  >> /etc/logrotate.d/newfies_dialer

    logrotate /etc/logrotate.d/newfies_dialer

    #Restart FreeSWITCH to find the startup-script
    /etc/init.d/freeswitch restart

    echo ""
    echo "*****************************************************************"
    echo "Congratulations, Newfies-Dialer Web Application is now installed!"
    echo "*****************************************************************"
    echo ""
    echo "Please log on to Newfies-Dialer at "
    echo "http://$IPADDR:$HTTP_PORT"
    echo "the username and password are the ones you entered during this installation."
    echo ""
    echo "Thank you for installing Newfies-Dialer"
    echo "Yours"
    echo "The Star2Billing Team"
    echo "http://www.star2billing.com and http://www.newfies-dialer.org/"
    echo ""
    echo "**************************************************************"
    echo ""
}

#Function to install backend
func_install_backend() {
    echo ""
    echo ""
    echo "This will install Newfies-Dialer Backend, Celery & Redis on your server"
    echo "Press Enter to continue or CTRL-C to exit"
    read TEMP

    IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
    IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`
    if [ -z "$IPADDR" ]; then
        clear
        echo "we have not detected your IP address automatically, please enter it manually"
        read IPADDR
    fi

    #Create directory for pid file
    mkdir -p /var/run/celery

    #Install Celery & redis-server
    func_install_redis_server

    #Memcache installation
    #pip install python-memcached

    echo "Configure Celery..."

    # Add init-scripts
    cp /usr/src/newfies-dialer/install/celery-init/debian/etc/default/newfies-celeryd /etc/default/
    cp /usr/src/newfies-dialer/install/celery-init/debian/etc/init.d/newfies-celeryd /etc/init.d/
    # Configure init-scripts
    sed -i "s/CELERYD_USER='celery'/CELERYD_USER='$CELERYD_USER'/g"  /etc/default/newfies-celeryd
    sed -i "s/CELERYD_GROUP='celery'/CELERYD_GROUP='$CELERYD_GROUP'/g"  /etc/default/newfies-celeryd
    chmod +x /etc/default/newfies-celeryd
    chmod +x /etc/init.d/newfies-celeryd

    /etc/init.d/newfies-celeryd restart
    cd /etc/init.d; update-rc.d newfies-celeryd defaults 99

    #Check permissions on /dev/shm to ensure that celery can start and run for openVZ.
    DIR="/dev/shm"
    echo "Checking the permissions for $dir"
    stat $DIR
    if [ `stat -c "%a" $DIR` -ge 777 ] ; then
        echo "$DIR has Read Write permissions."
    else
        echo "$DIR has no read write permissions."
        chmod -R 777 /dev/shm
        if [ `grep -i /dev/shm /etc/fstab | wc -l` -eq 0 ]; then
            echo "Adding fstab entry to set permissions /dev/shm"
            echo "none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0" >> /etc/fstab
        fi
    fi

    echo ""
    echo "**************************************************************"
    echo "Congratulations, Newfies-Dialer Backend is now installed!"
    echo "**************************************************************"
    echo ""
    echo "Thank you for installing Newfies-Dialer"
    echo "Yours"
    echo "The Star2Billing Team"
    echo "http://www.star2billing.com and http://www.newfies-dialer.org/"
    echo ""
    echo "**************************************************************"
    echo ""
}

#Install recent version of redis-server
func_install_redis_server() {
    echo "Install Redis-server ..."
    apt-get -y install redis-server
    /etc/init.d/redis-server restart
}

#Menu Section for Script
show_menu_newfies() {
    clear
    echo " > Newfies-Dialer Installation Menu"
    echo "====================================="
    echo "  1)  Install All"
    echo "  2)  Install Newfies-Dialer Web Frontend"
    echo "  3)  Install Newfies-Dialer Backend / Celery"
    echo "  0)  Quit"
    echo -n "(0-3) : "
    read OPTION < /dev/tty
}

# * * * * * * * * * * * * Start Script * * * * * * * * * * * *

#Identify the OS
func_identify_os

#Prepare settings for installation
SCRIPT_VIRTUALENVWRAPPER="/usr/local/bin/virtualenvwrapper.sh"

#Request the user to accept the license
func_accept_license

ExitFinish=0

while [ $ExitFinish -eq 0 ]; do

    # Show menu with Installation items
    show_menu_newfies

    case $OPTION in
        1)
            func_install_frontend
            func_install_landing_page
            func_install_backend
            echo done
        ;;
        2)
            func_install_frontend
            func_install_landing_page
        ;;
        3)
            func_install_backend
        ;;
        0)
        ExitFinish=1
        ;;
        *)
    esac

done

# Clean the system
#=================
# deactivate ; rm -rf /usr/share/newfies ; rm -rf /var/log/newfies ; rmvirtualenv newfies-dialer ; rm -rf /etc/init.d/newfies-celer* ; rm -rf /etc/default/newfies-celeryd ; rm /etc/apache2/sites-enabled/newfies.conf


BUILD: add jenkins script

BUILD: add jenkins script

#!/bin/bash -eExl

rc=0

if [ -z "$BUILD_NUMBER" ]; then
    echo Running interactive
    WORKSPACE=$PWD
    BUILD_NUMBER=1
    WS_URL=file://$WORKSPACE
    JENKINS_RUN_TESTS=yes
else
    echo Running under jenkins
    WS_URL=$JOB_URL/ws
fi

make_opt="-j$(($(nproc) - 1))"
inst=${WORKSPACE}/install

echo Starting on host: $(hostname)

echo "Autogen"
./autogen.sh

echo "Build release"
./configure --prefix=$inst
make $make_opt install

if [ -n "$JENKINS_RUN_TESTS" ]; then
    # Set CPU affinity to 2 cores, for performance tests
    if [ -n "$EXECUTOR_NUMBER" ]; then
        AFFINITY="taskset -c $(( 2 * EXECUTOR_NUMBER ))","$(( 2 * EXECUTOR_NUMBER + 1))"
        TIMEOUT="timeout 40m"
    else
        AFFINITY=""
        TIMEOUT=""
    fi

    ibv_test=$(find $INST/ -name ibv_test)

    VALGRIND_ARGS="--show-reachable=yes --xml=yes --gen-suppressions=all --tool=memcheck --leak-check=full --track-origins=yes --fair-sched=try"

    for dev in $(ibstat -l); do
        env IBV_TEST_DEV=${dev} $AFFINITY $ibv_test
        module load tools/valgrind
        env IBV_TEST_DEV=${dev} $AFFINITY valgrind $VALGRIND_ARGS --xml-file=$WORKSPACE/${dev}_valgrind.xml --log-file=$WORKSPACE/${dev}_valgrind.txt $ibv_test
        module unload tools/valgrind
    done

fi

exit $rc

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


start of script to spin up dev environment

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/simonsdave/cloudfeaster-services.git/'


add script to create RPM for Elastix Close #27

#!/bin/sh

#
# Create a RPM from last stable version or other if setted
# This script need have installed git, sed, rpmdevtools and curl
#
# Author: Rodrigo Ramírez Norambuena <a@rodrigoramirez.com>
#

# config
BRANCH=stable
REPO="https://github.com/roramirez/qpanel.git"
URL_STABLE_VERSION="https://raw.githubusercontent.com/roramirez/qpanel/$BRANCH/VERSION"

if ! [ -x "$(command -v git)" ]; then
  echo "Please install git"
  exit 1
fi

if ! [ -x "$(command -v rpmdev-setuptree)" ]; then
  echo "Please install rpm-build and rpmdevtools"
  exit 1
fi

if ! [ -x "$(command -v curl)" ]; then
  echo "Please install curl"
  exit 1
fi

VERSION_STABLE=$(curl $URL_STABLE_VERSION)
CLONE_DIR="/tmp/qpanel-$VERSION_STABLE"
FILE_TAR="qpanel-$VERSION_STABLE.tar.gz"
if [ ! -d "$CLONE_DIR" ]; then
  git clone -b $BRANCH $REPO $CLONE_DIR_NAME
else·
  cd $CLONE_DIR
  git pull
fi

cd /tmp
tar  cvfz $FILE_TAR qpanel-$VERSION_STABLE

rpmdev-setuptree
cd
cp /tmp/$FILE_TAR rpmbuild/SOURCES
cd rpmbuild
cp $CLONE_DIR/samples/elastix/elastix-qpanel.spec elastix-qpanel.spec
sed -i s/"Version: *.*.*"/"Version: $VERSION_STABLE"/g  elastix-qpanel.spec
rpmbuild -v -bb elastix-qpanel.spec

error: pathspec 'samples/elastix/create_rpm_elastix.sh' did not match any file(s) known to git


Create Linux start script

Create Linux start script

#!/bin/bash

welcome() {
    echo ""
    echo "Welcome to AvaIre's Linux launcher"
    echo "Please select an option to begin:"
    echo ""
    echo "   1. Start the bot normally"
    echo "   2. Start the bot with automatic restarts"
    echo "   3. Update the bot using the nightly build"
    echo "   9. Exit program"
    echo ""

    echo "Enter your option: "

    read option

    if [ 1 -eq $option ]; then
        echo "Nornal start has been selected, starting the bot..."
        echo ""

        startApplication

    elif [ 2 -eq $option ]; then
        echo "Starting the bot with automatic restarts..."
        echo ""

        startLoop
    elif [ 3 -eq $option ]; then
        echo "Updating using the nightly build..."
        echo ""

        updateWithNightlyBuild
    fi
}

startLoop() {
    while true; do
        startApplication false

        echo ""
        echo "Restarting the application in 5 seconds!"
        echo "If you want to cancel the process, you can use CTRL + C now"
        sleep 5
    done
}

startApplication() {
    java -jar AvaIre.jar

    if [ "$1" != "false" ]; then
        welcome
    fi
}

updateWithNightlyBuild() {
    echo "Downloading the latest version..."
    curl -sS https://avairebot.com/nightly-build.jar --output nightly-build.jar

    echo "Replacing jar files with the latest version..."
    mv nightly-build.jar AvaIre.jar

    echo "Done!"

    welcome
}

welcome

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


lamp + sublime install initial commit

lamp + sublime install initial commit

sudo apt-get install apache2
sudo apt-get install php5 libapache2-mod-php5
sudo apt-get install mysql-server
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
sudo service apache2 restart
sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

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


Replaced path literal with variable in visualstudiocode.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/xcjs/workstation-provision.git/'


Reduce false positives with zman alias

Reduce false positives with zman alias

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


Script to deduplicate web domain corpora; fixes #17

#!/bin/bash

# Usage: dedupe.sh <input folder> <output folder> <sourcelangid> <targetlangid>

# Location of dedupe binary built from https://github.com/kpu/preprocess
dedupebin=~/preprocess/bin/dedupe

if [ ! -d $1 ]
then
    echo "$1 is not a folder."
    exit
fi

if [ -e $2]
then
    if [ ! -d $2 ]
    then
	echo "$2 is not a directory."
	exit
    fi
else
    mkdir -p $2
fi

for insrc in $1/*.$3
do
    intgt=${insrc%.$3}.$4
    outsrc=$2/${insrc##*/}
    outtgt=$2/${intgt##*/}
    `$dedupebin $insrc $intgt $outsrc $outtgt`
done

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


add bash util script folder

add bash util script folder

show-path() {
    echo $PATH | tr ":" "\n"
}

prepend-path() {
    export PATH="$1:$PATH"
}

append-path() {
    export PATH="$PATH:$1"
}

error: pathspec 'bash/path-utils.sh' did not match any file(s) known to git


Create package.sh

Create package.sh

#工作原理
#1.首先需要在程序中对info.plist添加一个渠道字段,用来区分是那个渠道.
#2.使用xcodebuild命令生成archive文件
#3.循环修改info.plist文件,修改渠道名.并倒出ipa
#4.删除临时文件

#Schema名称
schema="***"
#设置项目路径
work="**.xcworkspace"
#倒出存档
xcodebuild -workspace $work -scheme $schema -configuration Release archive -archivePath ./archive

#work="/Users/bing/XCodeProjects/LearningBar/trunk/LearningBar/LearningBar.xcodeproj"
#xcodebuild -project $work -scheme $schema -configuration Release archive -archivePath ./archive

channels=("91手机助手" "同步推" "PP助手")

for i in ${channels[@]}; do
	#修改info.plist文件
	/usr/libexec/PlistBuddy -c "Set :Channel ""$i" ./archive.xcarchive/Products/Applications/*.app/info.plist
	#删除当前已存在的包
	rm -Rf ./$i.ipa
	#倒出IPA
	xcodebuild -exportArchive —exportFormat ipa -archivePath ./archive.xcarchive -exportPath ./$i.ipa -exportWithOriginalSigningIdentity
done
#删除archive
rm -Rf ./archive.xcarchive

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


scripts to ease editing

scripts to ease editing

#!/bin/bash

#deduplice onto scripts and sshd_config in amd64
rm amd64/include-docker-client/{init.sh,sshd_config,update_keys.sh}
ln amd64/init.sh amd64/include-docker-client/init.sh
ln amd64/sshd_config amd64/include-docker-client/sshd_config
ln amd64/update_keys.sh amd64/include-docker-client/update_keys.sh

rm armv7/{init.sh,sshd_config,update_keys.sh}
ln amd64/init.sh armv7/init.sh
ln amd64/sshd_config armv7/sshd_config
ln amd64/update_keys.sh armv7/update_keys.sh

rm armv7/include-docker-client/{init.sh,sshd_config,update_keys.sh}
ln amd64/init.sh armv7/include-docker-client/init.sh
ln amd64/sshd_config armv7/include-docker-client/sshd_config
ln amd64/update_keys.sh armv7/include-docker-client/update_keys.sh

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


removed mackup

removed mackup

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


man-db plan

man-db plan

Signed-off-by: Nathan L Smith <2b5c240e6abd88e71ffc225b0459016e4cba9bda@chef.io>

pkg_origin=core
pkg_name=man-db
pkg_version=2.7.5
pkg_maintainer="The Habitat Maintainers <humans@habitat.sh>"
pkg_license=('GPL-2.0')
pkg_description="man-db is an implementation of the standard Unix documentation system accessed using the man command."
pkg_upstream_url=http://man-db.nongnu.org/
pkg_source="http://git.savannah.gnu.org/cgit/man-db.git/snapshot/man-db-${pkg_version}.tar.gz"
pkg_shasum=3a1af4b7f17193e45b5abdb12d935b70a7757dfe7e1a4196f6c00b500c6fca78
pkg_deps=(
  core/gdbm
  core/glibc
  core/groff
  core/gzip
  core/libiconv
)
pkg_build_deps=(
  core/coreutils
  core/diffutils
  core/flex
  core/gcc
  core/gettext
  core/libpipeline
  core/make
  core/m4
  core/pkg-config
)
pkg_bin_dirs=(bin sbin)
pkg_lib_dirs=(lib/man-db)

do_prepare() {
  export CFLAGS="${CFLAGS} -O2 -fstack-protector-strong -Wformat -Werror=format-security "
  build_line "Setting CFLAGS=$CFLAGS"
  export CXXFLAGS="${CXXFLAGS} -O2 -fstack-protector-strong -Wformat -Werror=format-security "
  build_line "Setting CXXFLAGS=$CXXFLAGS"
  export CPPFLAGS="${CPPFLAGS} -Wdate-time"
  build_line "Setting CPPFLAGS=$CPPFLAGS"
  export LDFLAGS="${LDFLAGS} -Wl,-Bsymbolic-functions -Wl,-z,relro"
  build_line "Setting LDFLAGS=$LDFLAGS"
}

do_build() {
  ./configure \
    --prefix="${pkg_prefix}" \
    --disable-setuid \
    --disable-silent-rules \
    --enable-automatic-create \
    --enable-mandirs=GNU \
    --enable-threads=posix \
    --enable-mb-groff \
    --with-gzip="$(pkg_path_for gzip)/bin/gzip" \
    --with-libiconv-prefix="$(pkg_path_for libiconv)" \
    --with-systemdtmpfilesdir="${pkg_svc_config_path}/tmpfiles.d"

  make
}

do_prepare() {
  # /var/cache/man is hard-coded in a few places. We should replace this with
  # /hab/svc/man-db/var/cache/man. Since man-db isn't run as a service, this
  # directory won't actually exist unless created manually, but it will keep us out
  # of the filesystem and in the /hab directory.
  #
  # The file that gets generated here gets written to
  # $pkg_prefix/etc/man_db.conf.
  sed -i -e "s#/var/#$pkg_svc_var_path/#g" "$CACHE_PATH/src/man_db.conf.in"
}

do_check() {
  make check
}

do_install() {
  do_default_install

  # Removing reference to non-existent user(--disable-setuid), inspired from Linux From Scratch:
  # http://www.linuxfromscratch.org/lfs/view/development/chapter06/man-db.html
  sed -i "s:man root:root root:g" "${pkg_svc_config_path}/tmpfiles.d/man-db.conf"
}

error: pathspec 'man-db/plan.sh' did not match any file(s) known to git


Remove quotes from file listings

Remove quotes from file listings

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


added helper function "to" to quickly navigate to projects in my projects folder

to() {
  cd ~/projects/$1
}

_to_completion() {
  COMPREPLY=($(compgen -W "$(ls ~/projects/)" ${COMP_WORDS[COMP_CWORD]}))
}

complete -F _to_completion to

error: pathspec 'source/60_misc.sh' did not match any file(s) known to git


travis: try upgrading to Python 3.5.2

travis: try upgrading to Python 3.5.2

Summary:
This is nice to have.

Closes https://github.com/facebook/watchman/pull/401

Differential Revision: D4338621

Pulled By: sid0

fbshipit-source-id: 9e67eac01b4c549327706ca7f16f2843e4bbd5e8

#!/bin/bash
set -x
case `uname` in
  Darwin)
    brew update
    brew tap facebook/fb
    brew install wget pcre ruby openssl readline buck pyenv
    # reinstall to get the latest versions
    brew upgrade
    # avoid snafu with OS X and python builds
    ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future
    CFLAGS="$CFLAGS $ARCHFLAGS"
    export ARCHFLAGS CFLAGS
    case "$TRAVIS_PYTHON" in
      python2.6)
        pyenv install 2.6.9
        eval "$(pyenv init -)"
        pyenv global 2.6.9
        # install some other required dependencies
        pip2.6 install unittest2==1.1.0 argparse
        ;;
      python2.7)
        pyenv install 2.7.11
        pyenv global 2.7.11
        ;;
      python3.5)
        pyenv install 3.5.2
        pyenv global 3.5.2
        ;;
    esac
    ;;
esac

#!/bin/bash
set -x
case `uname` in
  Darwin)
    brew update
    brew tap facebook/fb
    brew install wget pcre ruby openssl readline buck pyenv
    # reinstall to get the latest versions
    brew upgrade
    # avoid snafu with OS X and python builds
    ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future
    CFLAGS="$CFLAGS $ARCHFLAGS"
    export ARCHFLAGS CFLAGS
    case "$TRAVIS_PYTHON" in
      python2.6)
        pyenv install 2.6.9
        eval "$(pyenv init -)"
        pyenv global 2.6.9
        # install some other required dependencies
        pip2.6 install unittest2==1.1.0 argparse
        ;;
      python2.7)
        pyenv install 2.7.11
        pyenv global 2.7.11
        ;;
      python3.5)
        pyenv install 3.5.1
        pyenv global 3.5.1
        ;;
    esac
    ;;
esac


Create rough outline of a tmux init script

# bin/sh

# TODO - make this easily useable via command line (e.g., `init shell-stuff` to
#   load this repo

# TODO - pretty sure there's built-out options for tmux session initialization

#if [ tmux ls | grep 'dev' ]
#  # TODO - maybe have this pass in an argument?
#  tmux attach-session
#  #TODO - return
#fi

# Note: 'C-m' for character return (I think?)
tmux new-session -d -s 'rawr' -c 'startDirectory' -n 'windowName'\;\
  send-keys 'some command, e.g. gulp serve' 'C-m'\;\
  split-window -h -d -p 60 -c 'startDirectory'\;\
  select-pane -t 1\;\
  send-keys 'vim' 'C-m'\;\
  select-pane -t 0\;\
  split-window -v -d -c 'startDirectory' -p 80\;\
  select-pane -t 1\;\
  send-keys 'some command, e.g. gulp test' 'C-m'\;\
  select-pane -t 2\;\
\
  new-window -d -c 'startDirectory -n 'windowName'\;\
  select-window -t windowName:1\;\
  send-keys 'rails c' 'C-m'\;\
  split-window -h -d -p 60 -c 'startDirectory'\;\
  select-pane -t 1\;\
  send-keys 'vim' 'C-m'\;\
  select-pane -t 0\;\
  split-window -v -d -c 'rails s' -p 80\;\
  select-pane -t 1\;\
  send-keys 'rspec' 'C-m'\;\
  select-pane -t 2\;\
\
  attach

# TODO - where did I get this from?
#tmux new-session -d -s foo 'exec pfoo'
#tmux send-keys 'bundle exec thin start' 'C-m'
#tmux rename-window 'Foo'
#tmux select-window -t foo:0
#tmux split-window -h 'exec pfoo'
#tmux send-keys 'bundle exec compass watch' 'C-m'
#tmux split-window -v -t 0 'exec pfoo'
#tmux send-keys 'rake ts:start' 'C-m'
#tmux split-window -v -t 1 'exec pfoo'
#tmux -2 attach-session -t foo
#

error: pathspec 'wip/tmux/init.sh' did not match any file(s) known to git


Script for generating JNI header files

Script for generating JNI header files

#!/bin/bash
#
# Generate header file for JNI calls:
# 1. Compile relevant files (and what they depend on)
# 2. Generate the headers
# 3. Remove the class files
# 4. Remove "empty" header files

REALMDIR="../realm/src/main/java/io/realm/"
TMPDIR=$(mktemp -d /tmp/$$.XXXXXX)
JNIDIR="$(pwd)/src"
(cd "$REALMDIR" && javac -d "$TMPDIR" internal/*.java exceptions/*.java)
(cd "$TMPDIR" && javah -jni -classpath "$TMPDIR" -d "$JNIDIR" io.realm.internal.Group io.realm.internal.LinkView io.realm.internal.Row io.realm.internal.SharedGroup io.realm.internal.SubtableSchema io.realm.internal.Table io.realm.internal.TableQuery io.realm.internal.TableView io.realm.internal.Util io.realm.internal.Version)

rm -rf "$TMPDIR"
wc -l "$JNIDIR"/*.h | grep " 13 " | awk '{print $2}' | xargs rm -f

error: pathspec 'realm-jni/generate-jni-headers.sh' did not match any file(s) known to git


Zsh: python path setup

Zsh: python path setup

# setup for globally installed python software, e.g. with brew-pip
export PYTHONPATH=$bp/lib/python2.7/site-packages
export PATH=$PATH:$bp/share/python

error: pathspec 'dotfiles/zsh/rc/python.zsh' did not match any file(s) known to git


shell script to create users from textfile with usernames

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/carthagecollege/archer.git/'