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

#!/bin/sh
pgm="${0##*/}"
what="${1:-usage}"
# vim: syntax=sh
#
echo "--- # $pgm"
if [ "x$what" = 'xusage' ]; then
cat <<EOT
# welcome to toychain a simple educational blockchain
available commands:
$pgm init \$name # to initialize \$name node
$pgm config \$name # to change configuration to this \$name node
$pgm start \$name # to start a local \$name node
$pgm stop \$name # to stop a \$name node
$pgm restart \$name # to restart a \$name node
$pgm sync \$name # to synchronize a \$name node
$pgm update \$tag # to synchronize a \$tag node
$pgm test \$tc # to run the \$tc test case
$pgm debug \$cmd # to running \$cmd in debug mode
$pgm install # to install dependant libraries essentially CPAN perl modules
$pgm ship # to package and ship libraries (i.e. push to holo-git)
EOT
fi
main() {
case $what in
init) tcinitialize $2;;
version) tcversion;;
config) tcconfigure $@;;
start) tcstart $2;;
stop) tcstop $2;;
stop) tcstop $2;;
update) tcupdate $@;;
test) tctest $@;;
debug) tcdebug $@;;
support) echo "do you need help with $pgm ?\n- call our support line at https://www.drit.ml\n-- Dr I·T";;
install) tcinstall $@;;
ship) tcship $@;;
log) tclog;;
*) tcrun $@;;
esac
}
tcinitialize() {
echo "$pgm: initializing ..."
echo "---"
}
tcconfigure() {
echo "$pgm: configure ..."
echo "---"
}
tcstart() {
echo "$pgm: starting daemon ..."
perl -S apirun.pl
echo "---"
}
tcstop() {
echo "$pgm: stopping daemon ..."
echo "---"
}
tcsync() {
echo "$pgm: synchronizing daemon ..."
echo "---"
}
tcupdate() {
shift;
tag=$2
echo "$pgm: updating daemon with tag $tag..."
top=$(git rev-parse --show-toplevel)
date +%s >> transcript.log
echo // updating $top >> transcript.log
git pull --ff-only --recurse-submodules=yes origin master 2>&1 | tee -a transcript.log
echo // checking out $tag
git checkout $tag 2>&1 | tee -a transcript.log
git log -1
cd $top/lib
echo // updating $top/lib
git pull --ff-only origin master 2>&1 | tee -a transcript.log
echo . >> transcript.log
git log -1
echo "---"
}
tclog() {
echo "$pgm: transcript log"
tail -f transctip.log
echo "---"
}
tctest() {
tc="$2"
echo "$pgm: running $1 $tc"
echo "---"
}
tcrun() {
cmd="$@"
echo "$pgm: running $cmd"
$cmd
echo "..."
}
tcdebug() {
shift;
cmd="$@"
echo "$pgm: running $cmd in debug mode..."
echo "---"
}
tcinstall() {
echo "$pgm: installing dependancies ..."
echo "---"
}
tcversion() {
top=$(git rev-parse --show-toplevel)
gitid0=$(git rev-parse --short HEAD)
date +%s >> transcript.log
git pull --ff-only --recurse-submodules=yes origin master 1>> transcript.log 2>&1
git checkout $tag 1>> transcript.log 2>&1
gitid1=$(git rev-parse --short HEAD)
if [ "x$gitid0" != "x$gitid1" ]; then gitid1=$gitid0-$gitid1; fi
cd $top/lib
git pull --ff-only origin master 1>> transcript.log 2>&1
gitid2=$(git rev-parse --short HEAD)
echo Version: $gitid1-$gitid2
echo Version: $gitid1-$gitid2 >> transcript.log
echo . >> transcript.log
}
tcship() { # only for internal use (i.e. Dr I·T)
date=$(date)
top=$(git rev-parse --show-toplevel)
cd $top/lib
gituser
git commit -a -m "snapshot $date"
if which holo-git-push 2> /dev/null; then
holo-git-push
else
git push origin master
fi
gitid=$(git rev-parse --short HEAD)
cd $top
gituser
git commit -a -m "library update ($gitid) on $date"
git push origin master
git push keybase master
git push toptal master
}
main $@;
exit $?;
true; # $Source: /my/shell/scripts/toychain.sh $