From 751cbe8d2333a5fd0d2ad868a7fa99de87f19304 Mon Sep 17 00:00:00 2001 From: shylinux Date: Tue, 14 Apr 2020 08:11:02 +0800 Subject: [PATCH] add template.sh --- bin/template.sh | 189 ++++++++++++++++++++++++++++++++++++++++++++++++ etc/init.shy | 2 +- 2 files changed, 190 insertions(+), 1 deletion(-) create mode 100755 bin/template.sh diff --git a/bin/template.sh b/bin/template.sh new file mode 100755 index 00000000..be2557e7 --- /dev/null +++ b/bin/template.sh @@ -0,0 +1,189 @@ +#! /bin/sh + +ice_sh="bin/ice.sh" +ice_bin="bin/ice.bin" +ice_mod="${PWD##**/}" +init_shy="etc/init.shy" +local_shy="etc/local.shy" +exit_shy="etc/exit.shy" +main_go="src/main.go" +main_js="src/main.js" +readme="README.md" +shy="src/main.shy" + +prepare() { + [ -d src ] || mkdir src + + [ -f ${main_go} ] || cat >> ${main_go} <> ${shy} <> ${main_js} <> Makefile <> ${init_shy} <> ${local_shy} <> "${exit_shy}" <> ${ice_sh} <\$ctx_log && echo -e "\n\nrestarting..." || break + done +} +restart() { + [ -e \$ctx_pid ] && kill -2 \`cat \$ctx_pid\` || echo +} +shutdown() { + [ -e \$ctx_pid ] && kill -3 \`cat \$ctx_pid\` || echo +} +serve() { + prepare && shutdown && start \$@ +} + +cmd=\$1 && [ -n "\$cmd" ] && shift || cmd=serve +\$cmd \$* +END + chmod u+x ${ice_sh} +} + +build() { + export CGO_ENABLED=0 + export GOPRIVATE=github.com + export GOPROXY=https://goproxy.cn + miss=./ && [ "$1" != "" ] && miss=$1 && shift && mkdir $miss + cd $miss && prepare && go build -o ${ice_bin} ${main_go} && chmod u+x ${ice_bin} && ./${ice_sh} start serve +} + +tutor() { + [ -d $1 ] || mkdir $1 + + [ -f "$1/$1.js" ] || cat >> "$1/$1.js" <> "$1/$1.shy" <> "$1/$1.go" <