You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
3.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #!/bin/sh
  2. pgm="${0##*/}"
  3. what="${1:-usage}"
  4. # vim: syntax=sh
  5. #
  6. echo "--- # $pgm"
  7. if [ "x$what" = 'xusage' ]; then
  8. cat <<EOT
  9. # welcome to toychain a simple educational blockchain
  10. available commands:
  11. $pgm init \$name # to initialize \$name node
  12. $pgm config \$name # to change configuration to this \$name node
  13. $pgm start \$name # to start a local \$name node
  14. $pgm stop \$name # to stop a \$name node
  15. $pgm restart \$name # to restart a \$name node
  16. $pgm sync \$name # to synchronize a \$name node
  17. $pgm update \$tag # to synchronize a \$tag node
  18. $pgm test \$tc # to run the \$tc test case
  19. $pgm debug \$cmd # to running \$cmd in debug mode
  20. $pgm install # to install dependant libraries essentially CPAN perl modules
  21. $pgm ship # to package and ship libraries (i.e. push to holo-git)
  22. EOT
  23. fi
  24. main() {
  25. case $what in
  26. init) tcinitialize $2;;
  27. version) tcversion;;
  28. config) tcconfigure $@;;
  29. start) tcstart $2;;
  30. stop) tcstop $2;;
  31. stop) tcstop $2;;
  32. update) tcupdate $@;;
  33. test) tctest $@;;
  34. debug) tcdebug $@;;
  35. support) echo "do you need help with $pgm ?\n- call our support line at https://www.drit.ml\n-- Dr I·T";;
  36. install) tcinstall $@;;
  37. ship) tcship $@;;
  38. log) tclog;;
  39. *) tcrun $@;;
  40. esac
  41. }
  42. tcinitialize() {
  43. echo "$pgm: initializing ..."
  44. echo "---"
  45. }
  46. tcconfigure() {
  47. echo "$pgm: configure ..."
  48. echo "---"
  49. }
  50. tcstart() {
  51. echo "$pgm: starting daemon ..."
  52. perl -S apirun.pl
  53. echo "---"
  54. }
  55. tcstop() {
  56. echo "$pgm: stopping daemon ..."
  57. echo "---"
  58. }
  59. tcsync() {
  60. echo "$pgm: synchronizing daemon ..."
  61. echo "---"
  62. }
  63. tcupdate() {
  64. shift;
  65. tag=$2
  66. echo "$pgm: updating daemon with tag $tag..."
  67. top=$(git rev-parse --show-toplevel)
  68. date +%s >> transcript.log
  69. echo // updating $top >> transcript.log
  70. git pull --ff-only --recurse-submodules=yes origin master 2>&1 | tee -a transcript.log
  71. echo // checking out $tag
  72. git checkout $tag 2>&1 | tee -a transcript.log
  73. git log -1
  74. cd $top/lib
  75. echo // updating $top/lib
  76. git pull --ff-only origin master 2>&1 | tee -a transcript.log
  77. echo . >> transcript.log
  78. git log -1
  79. echo "---"
  80. }
  81. tclog() {
  82. echo "$pgm: transcript log"
  83. tail -f transctip.log
  84. echo "---"
  85. }
  86. tctest() {
  87. tc="$2"
  88. echo "$pgm: running $1 $tc"
  89. echo "---"
  90. }
  91. tcrun() {
  92. cmd="$@"
  93. echo "$pgm: running $cmd"
  94. $cmd
  95. echo "..."
  96. }
  97. tcdebug() {
  98. shift;
  99. cmd="$@"
  100. echo "$pgm: running $cmd in debug mode..."
  101. echo "---"
  102. }
  103. tcinstall() {
  104. echo "$pgm: installing dependancies ..."
  105. echo "---"
  106. }
  107. tcversion() {
  108. top=$(git rev-parse --show-toplevel)
  109. gitid0=$(git rev-parse --short HEAD)
  110. date +%s >> transcript.log
  111. git pull --ff-only --recurse-submodules=yes origin master 1>> transcript.log 2>&1
  112. git checkout $tag 1>> transcript.log 2>&1
  113. gitid1=$(git rev-parse --short HEAD)
  114. if [ "x$gitid0" != "x$gitid1" ]; then gitid1=$gitid0-$gitid1; fi
  115. cd $top/lib
  116. git pull --ff-only origin master 1>> transcript.log 2>&1
  117. gitid2=$(git rev-parse --short HEAD)
  118. echo Version: $gitid1-$gitid2
  119. echo Version: $gitid1-$gitid2 >> transcript.log
  120. echo . >> transcript.log
  121. }
  122. tcship() { # only for internal use (i.e. Dr I·T)
  123. date=$(date)
  124. top=$(git rev-parse --show-toplevel)
  125. cd $top/lib
  126. gituser
  127. git commit -a -m "snapshot $date"
  128. if which holo-git-push 2> /dev/null; then
  129. holo-git-push
  130. else
  131. git push origin master
  132. fi
  133. gitid=$(git rev-parse --short HEAD)
  134. cd $top
  135. gituser
  136. git commit -a -m "library update ($gitid) on $date"
  137. git push origin master
  138. git push keybase master
  139. git push toptal master
  140. }
  141. main $@;
  142. exit $?;
  143. true; # $Source: /my/shell/scripts/toychain.sh $