Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 372 lines (320 sloc) 7.533 kb
#!/usr/bin/env bash
__PWD="$PWD"
__version="0.9" #TODO: to be automatic
__author='Rhiokim <rhio.kim@gmail.com>'
__process_header="Haroopress $__version $__author"
__pid=$$
__instance="haroopress[$__pid]"
__LOCKFILE="${PWD}/.h-get.lock"
# prefix(__) is removed for compatibility
SOURCE_DIR="${PWD}/source/public"
DEPLOY_DIR="${PWD}/_deploy"
PUBLIC_DIR="${PWD}/_public"
declare -i __arguments_length=$#
declare -i __pre_requisite_not_found=0
__HCMD=$1
trap "{ __cleanup; }" SIGINT SIGTERM SIGHUP SIGQUIT
# for secure processing, multiple process is not allowed.
[ -f $__LOCKFILE ] && echo "another h-get process is running. quit" && exit 0
touch $__LOCKFILE
__cleanup ()
{
echo ${__instance} -- got an Interrupt.
__remove_lock
exit 0
}
__remove_lock ()
{
rm -f $__LOCKFILE
}
# showing copyright first of all
echo $__process_header
echo
__usage ()
{
echo "./h-get [<cmd>]"
echo " cmd:"
echo " help"
echo " gen -- generate static page"
echo " preivew -- preview a post"
echo " new-post | a-post -- writing a new post"
echo " new-page | a-page -- writing a new page"
echo " new-slide | a-page -- writing a new slide"
echo " init | install -- setup Haroopress"
echo " clear"
echo "------------------------------------------------------"
__guide
echo
}
__log ()
{
echo " --------------- $*"
}
__stop ()
{
if [ "$*" != "0" ]; then
__log "[ STOP! ]"
__remove_lock; exit 0
fi
}
__guide ()
{
cat ${__PWD}/lib/haroopress/QUICK.markdown
}
__initialize ()
{
if [ -e "${__PWD}/.init.done" ]; then
echo " -- init process is already done"
return
fi
__log "start: initilizing"
cd $__PWD; ./bin/init.js
__stop $?
touch ${__PWD}/.init.done
__log "end: initilizing"
}
__init_update_git_submodules ()
{
if [ -e "${__PWD}/.init-git-submodules.done" ]; then
echo " -- git submodule update is already done"
return
fi
__log "start: updating git submodules"
cd $__PWD; git submodule update --init --recursive
__stop $?
touch ${__PWD}/.init-git-submodules.done
__log "end: updating git submodules"
}
__init_install_locally ()
{
if [ -e "${__PWD}/.init-install-locally.done" ]; then
echo " -- locally installation is already done"
return
fi
__log "start: updating locally"
cd $__PWD; cd ./node_modules/locally/; npm install
__stop $?
touch ${__PWD}/.init-install-locally.done
__log "end: updating locally"
}
__init_install_python_modules ()
{
if [ -e "${__PWD}/.init-install-python-modules.done" ]; then
echo " -- python modules installation is already done"
return
fi
__log "start: updating python modules"
cd $__PWD; python ./lib/highlight.js/tools/build.py
__stop $?
touch ${__PWD}/.init-install-python-modules.done
__log "end: updating python modules"
}
__rebuild_node_modules ()
{
if [ -e "${__PWD}/.init-rebuild-node-modules.done" ]; then
echo " -- updating node modules is already done"
return
fi
__log "start: updating node modules"
cd $__PWD/node_modules/robotskirt/
node-gyp rebuild
__stop $?
touch ${__PWD}/.init-rebuild-node-modules.done
__log "end: updating node modules"
}
__setup ()
{
if [ -e "${__PWD}/.setup.done" ]; then
echo " -- setup procedure is already done"
return
fi
cd $__PWD; ./bin/setup.js
__stop $?
touch ${__PWD}/.setup.done
}
__clear ()
{
__log "clear"
cd $__PWD; ./bin/clear.js
}
__gh_pages ()
{
if [ -e "${__PWD}/.gh-pages.done" ]; then
echo " -- gh-pages process is already done"
return
fi
__log "start: gh-pages"
__clear
cd $__PWD/bin; ./gh-pages.js
__stop $?
touch ${__PWD}/.gh-pages.done
__log "end: gh-pages"
}
__assert ()
{
__expr__="$*"
`${__expr__} > /dev/null 2>&1`
if [ $? -ne 0 ]; then
__pre_requisite_not_found=$(( __pre_requisite_not_found + 1))
return 1
fi
return 0
}
__guide_install_nodejs ()
{
__log "[ NodeJS ] missing"
__log "Ubuntu: sudo apt-get install nodejs nodejs-dev"
__log "Mac OS: brew install nodejs"
echo
}
__guide_install_nodegyp ()
{
__log "[ node-gyp ] missing"
__log "Ubuntu \& Mac OS: npm install node-gyp -g"
echo
}
__guide_install_python ()
{
__log "[ python ] missing"
}
__guide_install_java ()
{
__log "[ java ] missing"
}
__guide_install_git ()
{
__log "[ git ] missing"
__log "Ubuntu: sudo apt-get install git-core"
__log "Mac OS: brew install git"
echo
}
__guide_install_gpp ()
{
__log "[ g++ or gcc ] missing"
__log "Ubuntu: sudo apt-get install build-essentail"
__log "Mac OS: Install XCode and commandline tools"
echo
}
__chk_pre_requisites ()
{
__assert node -v || __guide_install_nodejs
__assert node-gyp -v || __guide_install_nodegyp
__assert python --version || __guide_install_python
__assert java -version || __guide_install_java
__assert git --version || __guide_install_git
__assert g++ -v || __guide_install_gpp
__assert gcc -v || __guide_install_gpp
if [ $__pre_requisite_not_found -gt 0 ]; then
echo
echo "[STOP] You need to install $__pre_requisite_not_found package(s) first! (See INSTALL.pre-requisites)"
echo
__remove_lock; exit 0
fi
#TODO: robotskirt gyp module, PGP key for pushing at github
}
__gen ()
{
__log "start: gen"
__clear
cd $__PWD; ./bin/gen.js
mkdir -p ${PUBLIC_DIR}/slides/@asserts
cp -R ./lib/shower/themes ${PUBLIC_DIR}/slides/@asserts
cp -R ./lib/shower/scripts ${PUBLIC_DIR}/slides/@asserts
mkdir -p ${PUBLIC_DIR}/css/code
cp -R ./lib/highlight.js/src/styles/* ${PUBLIC_DIR}/css/code
cp -R ./lib/highlight.js/build/* ${PUBLIC_DIR}/js
cp -R ./lib/bootstrap/* ${PUBLIC_DIR}
__log "end: gen"
}
__preview ()
{
__log "start: preview"
cd $__PWD; ./bin/preview.js
__log "end: preview"
}
__deploy ()
{
__log "start: deploy"
cd $__PWD/bin; ./deploy.js "${msg}" # where is comes from ?
__log "end: deploy"
}
__main ()
{
if [ $__arguments_length -le 0 ]; then
__usage
return;
fi
if [[ "$__HCMD" == "guide" ]] || [[ "$__HCMD" == "help" ]]; then
__guide
return
fi
if [[ "$__HCMD" == "setup" ]]; then
__chk_pre_requisites
__setup
return;
fi
if [[ "$__HCMD" == "clear" ]]; then
__clear
return;
fi
if [[ "$__HCMD" == "gh-pages" ]]; then
__chk_pre_requisites
__gh_pages
return;
fi
if [[ "$__HCMD" == "new-post" ]] || [[ "$__HCMD" == "a-post" ]]; then
__chk_pre_requisites
cd $__PWD/bin/; ./new-post.js
return;
fi
if [[ "$__HCMD" == "new-page" ]] || [[ "$__HCMD" == "a-page" ]]; then
__chk_pre_requisites
cd $__PWD/bin/; ./new-page.js
return;
fi
if [[ "$__HCMD" == "new-slide" ]] || [[ "$__HCMD" == "a-slide" ]]; then
__chk_pre_requisites
cd $__PWD/bin/; ./new-slide.js
return;
fi
if [[ "$__HCMD" == "octopress" ]] || [[ "$__HCMD" == "convert" ]]; then
__chk_pre_requisites
cd $__PWD/bin/convert; ./octopress.js
return;
fi
if [[ "$__HCMD" == "init" ]] || [[ "$__HCMD" == "install" ]]; then
__chk_pre_requisites
__init_update_git_submodules
__init_install_locally
__init_install_python_modules
__rebuild_node_modules
__setup
__gh_pages
__initialize
return;
fi
if [[ "$__HCMD" == "check" ]]; then
__chk_pre_requisites
echo " [ OK ] -- You're good to go"
echo
fi
if [[ "$__HCMD" == "gen" ]]; then
__chk_pre_requisites
__gen
return
fi
if [[ "$__HCMD" == "preview" ]]; then
__chk_pre_requisites
__gen
__preview
return
fi
if [[ "$__HCMD" == "deploy" ]]; then
__chk_pre_requisites
__gen
__deploy
return
fi
}
__main "$*"
__remove_lock; exit 0
Jump to Line
Something went wrong with that request. Please try again.