No abstract yet


Extend :: Shell Module Guide

    What we will make

    This is very simple. We want to make a shell module that can clone a site with wget and make a static site which we then can publish on For an example you can see my personal github site which is made from the following module. Se <a href=""></a> This is a static site made from a dynamic site.

    If you just want to look at the source you can do a:

     ./ git --mod-in git://

    Install File

    First step is to make a install file

    // first we set a version for our module Note it has to be a float!
    $_INSTALL['VERSION'] = 2.1;
    // we specify that it is a shell module.
    // this means that the source files will be loaded when the base shell
    // command is getting loaded.
    $_INSTALL['IS_SHELL'] = "1";
    // we add a public clone url for easy distribution
    $_INSTALL['PUBLIC_CLONE_URL'] = 'git://';
    // and also a private url if we want to commit directly from base
    // shell command

    Ini File

    We also make a ini file where we can add some settings which can be changed with ease. It looks like this:

    gh_static_push_url = ""
    gh_static_site_dir = "/home/dennis/www/"
    gh_static_index_url = ""

    The first setting of the ini file is the push url. This is the git repo url we can push to. The next setting is the dir where our site will be placed local. Third setting is the url to index: mygithub (a more normal url to spider would be e.g.

    The module file

    Then we can make our module:

     * This is function which genrates the static site.
    function gh_static_generate (){
        // ini settings will be found in the static var mainClin::$ini
        $static_dir = config::getModuleIni('gh_static_site_dir');
        // The url to index (mygithub)
        $url = config::getModuleIni('gh_static_index_url');
        // create dir where files will be put
        if (!file_exists($static_dir)) {
            $command = "mkdir $static_dir";
        // wget command
        $command = "wget -m -k -K -E  $url";
        // execute
        // copy the content of the url to the static dir
        // (/home/dennis/www/
        //$command = "mkdir $static_dir";
        $command = "cp -rf ./$url/* $static_dir";
        // execute
     * next command is the push command.
    function gh_static_push (){
        // the static dir where we will push from
        $static_dir = config::getModuleIni('gh_static_site_dir');
        // cd into dir add - commit - push
        $command = "cd $static_dir && git add . && git commit -m \"auto-commit\" && git push";
        // execute
    // enable commands in shell - first we set a base command
    mainCli::setCommand('gh-static', array(
        'description' => 'Command to generate a static site from a dynamic',
    // then we set a option
    mainCli::setOption('gh_static_generate', array(
        'long_name'   => '--generate',
        'description' => 'Will generate the static site into location specified in .ini file',
        'action'      => 'StoreTrue'
    // and another option
    mainCli::setOption('gh_static_push', array(
        'long_name'   => '--push',
        'description' => 'Will push the static site to git url specified in .ini file',
        'action'      => 'StoreTrue'


    ./ gh-static -h

    Will give you the help options.

    ./ gh-static --generate

    Will generate the static site with wget

    ./ gh-static --push

    Will push the site to remote repo.

    Simple as that!

    This page has been viewed 526 times. First hit: 22-Aug-2015 01:30:52
    Share email, Google+, Twitter, Facebook.
    comments powered by Disqus