2017년 4월 5일 수요일

qq

#! /usr/bin/bash

UPDATE=/update

error()
{
    echo "$*"
    exit
}

cmd_mkdir()
{
    echo "* $@"
}

cmd_put()
{
    echo "* $@"
}

cmd_puts()
{
    local argv=("$@")
    local argc=${#argv[@]}

    local dst=${argv[$((argc - 1))]}
    unset -v argv[$((argc - 1))]

    for src in "${argv[@]}"; do
        [ ${src:0:1} = . ] && error "not support: start with ."

        if [ -d "$src" ]; then
            cmd_mkdir "$dst/$(basename $src)"
            cmd_puts "$src"/* "$dst/$(basename $src)"
        else
            cmd_put "$src" "$dst"
        fi
    done
}

cmd_update()
{
    local TMP=update.$$
    RMF=no

    unzip $1 -d $TMP || exit

    cmd_qcl rm $UPDATE > /dev/null
    cmd_mkdir $UPDATE

    cmd_puts $TMP/* $UPDATE

    rm -rf $TMP
}

# main

if [ "$1" = "put" ]; then
    shift
    cmd_puts "$@"
elif [ "$1" = "update" ]; then
    cmd_update "$2"
else
fi