tinycm view tinycm @ rev 114

tinycm: dont overwrite images
author Christophe Lincoln <pankso@slitaz.org>
date Mon Feb 27 12:19:10 2017 +0100 (2017-02-27)
parents b5820178a40b
children 035728efb7ad
line source
1 #!/bin/sh
2 #
3 # TinyCM Command line tool. Dont use libtaz since TinyCM can run on any
4 # Linux/BSD distribution providing a web server with CGI SHell support
5 # such as LightTPD.
6 #
7 # Copyright (C) 2014-2017 SliTaz GNU/Linux - BSD License
8 #
10 list="tinycm.list"
11 path="${2%/}"
12 hgurl="http://hg.slitaz.org/tinycm"
13 dlurl="$hgurl/archive/tip.tar.bz2"
15 #
16 # Functions
17 #
19 boldify() {
20 echo -e "\\033[1m$@\\033[0m"
21 }
23 error() {
24 echo -e "\\033[1;31m$@\\033[0;39m"
25 }
27 usage() {
28 cat << EOT
30 $(boldify "Usage:") $(basename $0) [command] [path|list]
32 $(boldify "Commands:")
33 inst Install TinyCM and set permissions
34 up Update one or a list of TinyCM installations
36 EOT
37 }
39 check_source() {
40 if [ ! -f "Makefile" ] || [ ! -f "index.cgi" ]; then
41 error "No source found" && exit 1
42 fi
43 }
45 check_path() {
46 if [ ! "$path" ]; then
47 error "Missing path argument" && exit 1
48 fi
49 }
51 check_tiny() {
52 if [ ! -f "$path/index.cgi" ] || [ ! -d "$path/lib" ]; then
53 error "Missing TinyCM in: $path"
54 continue
55 fi
56 }
58 # Rebuild an up-to-date config file, plugins may need new variables
59 update_config() {
60 echo "Updating config file: confi.cgi"
61 . ${path}/config.cgi
62 # Def value for new variables
63 [ ! "$WALL_MODE" ] && WALL_MODE="public"
64 [ ! "$WALL_MESSAGES_LENGTH" ] && WALL_MESSAGES_LENGTH="240"
65 # from 1.4
66 [ ! "$ADMIN_USERS" ] && ADMIN_USERS=$(dirname "$AUTH_FILE")/admin
67 cat > ${path}/config.cgi << EOT
68 #
69 # TinyCM configuration
70 #
72 # Administrator email.
73 ADMIN_MAIL="$ADMIN_MAIL"
75 # Auth file for user
76 AUTH_FILE="$AUTH_FILE"
78 # Admin users file list
79 ADMIN_USERS="/var/lib/slitaz/auth/admin"
81 # People config files
82 PEOPLE="$PEOPLE"
84 # CM documents languages.
85 LANGUAGES="$LANGUAGES"
87 # Online registration for user
88 ONLINE_SIGNUP="$ONLINE_SIGNUP"
90 # Use Mercurial repo for content and configure user name
91 HG="$HG"
93 #
94 # Plugin configuration: community.cgi
95 #
97 # Wall mode: public/private
98 WALL_MODE="$WALL_MODE"
100 # Max length for messages on the Wall
101 WALL_MESSAGES_LENGTH="$WALL_MESSAGES_LENGTH"
103 # Twitter user name and/or Facebook page URL name
104 TWITTER_USER="$TWITTER_USER"
105 FACEBOOK_PAGE="$FACEBOOK_PAGE"
106 EOT
107 unset TWITTER_USER FACEBOOK_PAGE
108 }
110 #
111 # Commands
112 #
114 case "$1" in
115 inst)
116 check_source
117 check_path
118 echo ""
119 boldify "Installing TinyCM..."
120 echo "Path:"; echo "$path"
121 mkdir -p $path
122 for file in index.cgi style.css images lib plugins
123 do
124 echo "* Installing: $file"
125 cp -a $file $path
126 done
127 if [ $(id) == 0 ]; then
128 echo root
129 else
130 echo user
131 fi
132 echo "" ;;
133 up)
134 check_source
135 if [ ! "$path" ] && [ ! -f "$list" ]; then
136 error "Missing path argument or paths list: $list"
137 exit 1
138 fi
139 echo ""
140 boldify "Updating TinyCM install(s)..."
141 echo ""
143 # File list of args
144 if [ -f "$path" ]; then
145 paths="$(cat ${list})"
146 else
147 paths="$path"
148 fi
150 for path in ${paths}
151 do
152 check_tiny
153 echo "Updating TinyCM: $path"
154 cp -a index.cgi $path
155 cp -a lib/functions.js $path/lib
156 cp -a lib/jseditor.html $path/lib
157 #cp -a images/* $path/images
158 echo "Updating plugins..."
159 for plug in $(ls plugins)
160 do
161 if [ -d "$path/plugins/$plug" ]; then
162 echo "* Updating plugin: $plug"
163 cp -a plugins/$plug $path/plugins
164 fi
165 done
166 update_config
167 done && echo "" ;;
168 *)
169 usage ;;
170 esac
172 exit 0