# HG changeset patch # User Christophe Lincoln # Date 1398294343 -7200 # Node ID 70b6a1ca9106bef9431a1dbdff84c45b2cb2e6bd # Parent e899fcee1cd529a184df0c49950cee07eeb769e2 Add tinycm utility to help update and do new install (now that scn is powered by tinxcm) diff -r e899fcee1cd5 -r 70b6a1ca9106 tinycm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tinycm Thu Apr 24 01:05:43 2014 +0200 @@ -0,0 +1,114 @@ +#!/bin/sh +# +# TinyCM Command line tool. Dont use libtaz since TinyCM can run on any +# Linux/BSD distribution providing a web server with CGI SHell support +# such as LightTPD. +# +# Copyright (C) 2014 SliTaz GNU/Linux - BSD License +# + +list="tinycm.list" +path="${2%/}" +hgurl="http://hg.slitaz.org/tinycm" +dlurl="$hgurl/archive/tip.tar.bz2" + +# +# Functions +# + +boldify() { + echo -e "\\033[1m$@\\033[0m" +} + +error() { + echo -e "\\033[1;31m$@\\033[0;39m" +} + +usage() { + cat << EOT + +$(boldify "Usage:") $(basename $0) [command] [path|list] + +$(boldify "Commands:") + inst Install TinyCM and set permissions + up Update one a list of TinyCM installation + +EOT +} + +check_source() { + if [ ! -f "Makefile" ] || [ ! -f "index.cgi" ]; then + error "No source found" && exit 1 + fi +} + +check_path() { + if [ ! "$path" ]; then + error "Missing path argument" && exit 1 + fi +} + +check_tiny() { + if [ ! -f "$path/index.cgi" ] || [ ! -d "$path/lib" ]; then + error "Missing TinyCM in: $path" + continue + fi +} + +# +# Commands +# + +case "$1" in + inst) + check_source + check_path + echo "" + boldify "Installing TinyCM..." + echo "Path:"; echo "$path" + mkdir -p $path + for file in index.cgi style.css images lib plugins + do + cp -a $file $path + done + if [ $(id) == 0 ]; then + echo root + else + echo user + fi + echo "" ;; + up) + check_source + if [ ! "$path" ] && [ ! -f "$list" ]; then + error "Missing path argument or paths list: $list" + exit 1 + fi + echo "" + boldify $(echo "Updating TinyCM install's...") + + # Priority to cmdline path argument + if [ "$path" ]; then + paths="$path" + else + paths="$(cat ${list})" + fi + + for path in ${paths} + do + check_tiny + echo "Updating: $path" + cp -a index.cgi $path + cp -a lib/functions.js $path/lib + cp -a lib/jseditor.html $path/lib + for plug in $(ls plugins) + do + if [ -d "$path/plugins/$plug" ]; then + cp -a plugins/$plug $path/plugins + fi + done + done && echo "" ;; + *) + usage ;; +esac + +exit 0