move more duplicate code to function library

On branch master
Changes to be committed:

	modified:   init.sh
	modified:   scripts/middleman.sh
	modified:   setup.sh