seb view tools/sebos @ rev 18

Some fixes after booting frugal and testing
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 07 10:51:02 2017 +0100 (2017-03-07)
parents 3928ba49c43c
children
line source
1 #!/bin/sh
2 #
3 # sebos: SliTaz Embedded OS - A tool to help getting hands on a Seb-OS
4 # system with some cmdline and Ncurses configs functions. The main goal
5 # is to manage a web server. Without gettext dependencies please :-)
6 #
7 # Copyright (C) 2017 SliTaz GNU/Linux - BSD License
8 # Author: Christophe Lincoln <pankso@slitaz.org>
9 #
11 # /lib/libseb.sh && seb.conf
12 if [ -f "../libseb.sh" ]; then
13 . ../libseb.sh
14 else
15 if ! . /lib/libseb.sh; then
16 echo "Can't source any: libseb.sh"; exit 1
17 fi
18 fi
19 [ -f "/etc/seb.conf" ] && . /etc/seb.conf
21 title="SliTaz Embedded OS"
22 doc="/usr/share/doc/seb-os.txt"
23 packages="/var/lib/packages"
24 tmpdir="/tmp/$(basename $0)"
25 tmp="$tmpdir/$$"
26 height='20'
27 width='72'
29 # Functions
31 help() {
32 cat << EOT
34 $(colorize 35 'Usage:') $(basename $0) [command] [file|daemon]
36 $(colorize 035 'Commands:')
38 -c config Configure the system
39 -i info Seb system information
40 -d daemon Run/kill a daemon
41 -p packages List installed packages
42 -v view File viewer
44 EOT
45 }
47 info() {
48 cat << EOT
49 Hostname : $host_name
50 Seb build date : $build_date
51 SliTaz release : $seb_os_release
52 Seb OS config : /etc/seb.conf
53 Network interface : $network_interface
54 Installed packages : $(cat /var/lib/packages | wc -l)
55 Running processes : $(ps -o pid | wc -l)
56 System time : $(date)
57 EOT
58 }
60 read_on() {
61 echo -n "Press ENTER to continue"; read
62 }
64 quit() {
65 rm -rf ${tmpdir}; exit 0
66 }
68 #
69 # GUI Functions
70 #
72 # Display any command output: exec_box [title] [command]
73 exec_box() {
74 dialog --cr-wrap --title "{ $1 }" \
75 --ok-label "Close" --msgbox "$($2)" ${height} ${width}
76 }
78 # Display a text file: text_box [title] [file]
79 text_box() {
80 dialog --cr-wrap --title "{ $1 }" \
81 --exit-label "Close" --textbox "$2" ${height} ${width}
82 }
84 # Show message and percentage on a gauge dialog
85 gauge_msg() {
86 sleep 1; echo -e "XXX\n$1\n$MSG\nXXX"
87 }
89 # Set root passwd
90 root_passwd() {
91 dialog --title "{ Root Password }" --colors \
92 --inputbox "\nEnter new password for root" \
93 12 $width 2>${tmp}
94 passwd=$(cat $tmp)
95 [ -z "$passwd" ] && return 0
96 echo "root:$passwd" | chpasswd --md5 2>/dev/null
97 }
99 # Add a new user
100 add_user() {
101 dialog --title "{ Add User }" --colors \
102 --inputbox "\nEnter login name for the new \Zb\Z4user" 12 ${width} 2>${tmp}
103 user=$(cat $tmp)
104 [ ! "$user" ] && return 0
106 dialog --title "{ Add User }" --colors \
107 --inputbox "\nEnter password for user \Zb\Z4${user}" 12 ${width} 2>${tmp}
108 passwd=$(cat $tmp)
109 [ ! "$passwd" ] && return 0
111 adduser -D -g "SliTaz User" ${user}
112 echo "$user:$passwd" | chpasswd --md5 2>/dev/null
113 }
115 set_date() {
116 echo ""; echo "Old date: $(date)"
117 rdate -s tick.greyware.com 2>/dev/null
118 echo "New date: $(date)"; echo ""
119 }
121 # Main Dialog menu
122 main_box() {
123 mkdir -p ${tmpdir}
124 dialog \
125 --clear --title "{ $title }" \
126 --ok-label "Exec" --cancel-label "Quit" \
127 --menu "" ${height} ${width} 14 \
128 "info" "Seb OS info and status" \
129 "add-user" "Add a new user to Seb-OS" \
130 "root-passwd" "Change root password" \
131 "set-date" "Set system date from the web" \
132 "packages" "List installed packages" \
133 "daemons" "List installed daemons" \
134 "commands" "Display sebos commands" \
135 "quit" "Exit from SliTaz Config" 2>${tmp}
137 # Handle options
138 case "$?" in
139 1|255) quit ;;
140 esac
142 # Handle actions
143 action=$(cat $tmp)
144 case "$action" in
145 info) exec_box "Seb OS Info" info ;;
146 add-user) add_user ;;
147 root-passwd) root_passwd ;;
148 set-date) clear; set_date; read_on ;;
149 packages) clear; ${0} -p; read_on ;;
150 daemons) clear; ${0} -d; read_on ;;
151 commands) clear; ${0} help; read_on ;;
152 quit) quit ;;
153 esac
154 }
156 #
157 # Handle commands
158 #
160 case "$1" in
162 -c|config)
163 check_root
164 while true; do
165 main_box
166 done ;;
168 -i|info)
169 title "SliTaz Embedded OS"
170 info; footer ;;
172 -d|daemon*)
173 # Handle daemons
174 daemons="/etc/daemons"
175 if [ ! "$2" ]; then
176 title "Installed daemons"
177 for d in $(ls $daemons); do
178 . ${daemons}/${d}
179 echo -n "${d}"; indent 20 "$desc"; unset desc
180 done; footer "Use: $(basename $0) -d [daemon] [--start|--kill|--info]"
181 exit 0
182 fi
183 if [ "$kill" ]; then
184 pid=$(pidof $2)
185 . ${daemons}/${2}
186 echo -n "Killing: $desc (pid $pid)"
187 kill ${pid} 2>/dev/null; status
188 fi
189 if [ "$start" ]; then
190 . ${daemons}/${2}
191 echo -n "Starting: $desc"
192 start; status
193 fi
194 if [ "$info" ]; then
195 . ${daemons}/${2}
196 pid=$(pidof $2)
197 [ ! "$pid" ] && pid="none"
198 title "$desc"
199 echo "$(colorize 036 Pidof $2:) $pid"
200 [ "$pid" != "" ] && ps | grep "$pid" | grep -v "grep" | grep -v "sebos"
201 footer
202 fi ;;
204 -p|package*)
205 title "Installed packages"
206 IFS="|"
207 cat /var/lib/packages | while read pkg desc; do
208 echo -n "$(colorize 036 $pkg)"; indent 20 "$desc"
209 done; unset IFS; footer ;;
211 -v|view) text_box "$(basename $2)" ${2} ;;
213 *_*) $@ ;; # Execute any fun_ctions
215 *|help) help ;;
216 esac
218 # Clean exit
219 rm -rf ${tmpdir} && exit 0