refactory nightly-build.sh and related programs