tinycm view tinycm @ rev 121

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 12:26:25 2019 +0100 (2019-02-26)
parents 49d179cd32d2
children
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 -i inst Install TinyCM and set permissions
34 -u up Update one or a list of TinyCM installations
35 -g get Download latest source tarball from repository
36 -p plugins List installed/available plugins
38 EOT
39 }
41 check_source() {
42 if [ ! -f "Makefile" ] || [ ! -f "index.cgi" ]; then
43 error "No source found" && exit 1
44 fi
45 }
47 check_path() {
48 if [ ! "$path" ]; then
49 error "Missing path argument" && exit 1
50 fi
51 }
53 check_tiny() {
54 if [ ! -f "$path/index.cgi" ] || [ ! -d "$path/lib" ]; then
55 error "Missing TinyCM in: $path"
56 continue
57 fi
58 }
60 # Rebuild an up-to-date config file, plugins may need new variables
61 update_config() {
62 echo "Updating config file: confi.cgi"
63 . ${path}/config.cgi
64 # Def value for new variables
65 [ ! "$WALL_MODE" ] && WALL_MODE="public"
66 [ ! "$WALL_MESSAGES_LENGTH" ] && WALL_MESSAGES_LENGTH="240"
67 # from 1.4
68 [ ! "$ADMIN_USERS" ] && ADMIN_USERS=$(dirname "$AUTH_FILE")/admin
69 cat > ${path}/config.cgi << EOT
70 #
71 # TinyCM configuration
72 #
74 # Administrator email.
75 ADMIN_MAIL="$ADMIN_MAIL"
77 # Auth file for user
78 AUTH_FILE="$AUTH_FILE"
80 # Admin users file list
81 ADMIN_USERS="/var/lib/slitaz/auth/admin"
83 # People config files
84 PEOPLE="$PEOPLE"
86 # CM documents languages.
87 LANGUAGES="$LANGUAGES"
89 # Online registration for user
90 ONLINE_SIGNUP="$ONLINE_SIGNUP"
92 # Use Mercurial repo for content and configure user name
93 HG="$HG"
95 #
96 # Plugin configuration: community.cgi
97 #
99 # Wall mode: public/private
100 WALL_MODE="$WALL_MODE"
102 # Max length for messages on the Wall
103 WALL_MESSAGES_LENGTH="$WALL_MESSAGES_LENGTH"
105 # Twitter user name and/or Facebook page URL name
106 TWITTER_USER="$TWITTER_USER"
107 FACEBOOK_PAGE="$FACEBOOK_PAGE"
108 EOT
109 unset TWITTER_USER FACEBOOK_PAGE
110 }
112 #
113 # Commands
114 #
116 case "$1" in
118 -i|inst*)
119 check_source
120 check_path
122 echo ""
123 boldify "TinyCM installation"
124 echo "Path: $path"
125 mkdir -p ${path}
126 for file in index.cgi config.cgi style.css images lib plugins
127 do
128 echo " * Installing: $file"
129 cp -a ${file} ${path}
130 done
132 # Content with wiki/*/help.txt
133 for lang in en
134 do
135 mkdir -p ${path}/content/wiki/${lang}
136 cp content/wiki/${lang}/help.txt ${path}/content/wiki/${lang}
137 done
139 # Set permissions
140 if [ $(id -u) = 0 ]; then
141 chown -R www.www ${path}/content
142 install -d -o www -g www ${path}/cache
143 else
144 chmod 0777 ${path}/content ${path}/content/*
145 install -d -m 0777 ${path}/cache
146 fi
147 echo "" ;;
149 -u|up*)
150 check_source
151 if [ ! "$path" ] && [ ! -f "$list" ]; then
152 error "Missing path argument or paths list: $list"
153 exit 1
154 fi
155 echo ""
156 boldify "Updating TinyCM install(s)..."
157 echo ""
159 # File list of args
160 if [ -f "$path" ]; then
161 paths="$(cat ${list})"
162 else
163 paths="$path"
164 fi
166 for path in ${paths}
167 do
168 check_tiny
169 echo "Updating TinyCM: $path"
170 cp -a index.cgi $path
171 cp -a lib/functions.js $path/lib
172 cp -a lib/jseditor.html $path/lib
173 #cp -a images/* $path/images
174 echo "Updating plugins..."
175 for plug in $(ls plugins)
176 do
177 if [ -d "$path/plugins/$plug" ]; then
178 echo "* Updating plugin: $plug"
179 cp -a plugins/$plug $path/plugins
180 fi
181 done
182 update_config
183 done && echo "" ;;
185 -p|plug*)
186 echo ""
187 boldify "TinyCM plugins:"
188 ls -1 plugins
189 echo "" ;;
191 -g|get)
192 tarball="tinycm-tip.tar.bz2"
193 if [ ! -f "$tarball" ]; then
194 wget ${dlurl} -O ${tarball}
195 fi ;;
197 *) usage ;;
198 esac
200 exit 0