seb view tools/sebos @ rev 5

Add tools
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 06 16:41:26 2017 +0100 (2017-03-06)
parents
children 052432697dd3
line source
1 #!/bin/sh
2 #
3 # sebos: SliTaz Embedded OS - A tool to help getting hand 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 informations
40 -d daemon Run/kill a daemon
41 -p packages List installed packages
42 -v view File viewer
43 doc Built-in documentation
45 EOT
46 }
48 info() {
49 cat << EOT
50 Hostname : $host_name
51 Seb build date : $build_date
52 SliTaz release : $seb_os_release
53 Seb OS config : /etc/seb.conf
54 Netwotk interface : $network_interface
55 Installed packages : $(cat /var/lib/packages | wc -l)
56 Running processes : $(ps -o pid | wc -l)
57 System time : $(date)
58 EOT
59 }
61 read_on() {
62 echo -n "Press ENTER to continue"; read
63 }
65 quit() {
66 rm -rf ${tmpdir}; exit 0
67 }
69 #
70 # GUI Functions
71 #
73 # Display any command output: exec_box [title] [command]
74 exec_box() {
75 dialog --cr-wrap --title "{ $1 }" \
76 --ok-label "Close" --msgbox "$($2)" ${height} ${width}
77 }
79 # Display a text file: text_box [title] [file]
80 text_box() {
81 dialog --cr-wrap --title "{ $1 }" \
82 --exit-label "Close" --textbox "$2" ${height} ${width}
83 }
85 # Show message and percentage on a gauge dialog
86 gauge_msg() {
87 sleep 1; echo -e "XXX\n$1\n$MSG\nXXX"
88 }
90 # Set root passwd
91 root_passwd() {
92 dialog --title "{ Root Password }" --colors \
93 --inputbox "\nEnter new password for root" \
94 12 $width 2>${tmp}
95 passwd=$(cat $tmp)
96 [ -z "$passwd" ] && return 0
97 echo "root:$passwd" | chpasswd --md5 >/dev/null
98 }
100 # Add a new user
101 add_user() {
102 dialog --title "{ Add User }" --colors \
103 --inputbox "\nEnter login name for the new \Zb\Z4user" 12 ${width} 2>${tmp}
104 user=$(cat $tmp)
105 [ ! "$user" ] && return 0
107 dialog --title "{ Add User }" --colors \
108 --inputbox "\nEnter password for user \Zb\Z4${user}" 12 ${width} 2>${tmp}
109 passwd=$(cat $tmp)
110 [ ! "$passwd" ] && return 0
112 adduser -D -g "SliTaz User" ${user}
113 echo "$user:$passwd" | chpasswd --md5 2>/dev/null
114 }
116 set_date() {
117 echo ""; echo "Old date: $(date)"
118 rdate -s tick.greyware.com 2>/dev/null
119 echo "New date: $(date)"; echo ""
120 }
122 # Main Dialog menu
123 main_box() {
124 mkdir -p ${tmpdir}
125 dialog \
126 --clear --title "{ $title }" \
127 --ok-label "Exec" --cancel-label "Quit" \
128 --menu "" ${height} ${width} 14 \
129 "info" "Seb OS info and status" \
130 "add-user" "Add a new user to Seb-OS" \
131 "root-passwd" "Change root password" \
132 "set-date" "Set system date from the web" \
133 "packages" "List installed packages" \
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 commands) clear; ${0} help; read_on ;;
151 quit) quit ;;
152 esac
153 }
155 #
156 # Handle commands
157 #
159 case "$1" in
161 -c|config)
162 check_root
163 while true; do
164 main_box
165 done ;;
167 -i|info)
168 title "SliTaz Embedded OS"
169 info; footer ;;
171 -d|daemon)
172 # Start/stop Busybox httpd server
173 #pid=$(ps | grep "httpd" | grep -v "grep" | awk '{print $1}')
174 daemon="$2"
175 pid=$(pidof $daemon)
176 if [ "$pid" != "" ]; then
177 echo -n "Starting $daemon daemon..."
178 case "$daemon" in
179 httpd)
180 httpd -u 80:80 -r "Seb OS Authentication" ;;
181 esac; status
182 else
183 echo -n "Stopping $daemon daemon..."
184 kill ${pid}; status
185 fi ;;
187 -p|packages)
188 title "Installed packages"
189 IFS="|"
190 cat /var/lib/packages | while read pkg desc; do
191 echo -n "$(colorize 036 $pkg)"; indent 20 "$desc"
192 done; unset IFS; footer ;;
194 -v|view) text_box "$(basename $2)" ${2} ;;
196 *_*) $@ ;; # Execute any fun_ctions
198 *|help) help ;;
199 esac
201 # Clean exit
202 rm -rf ${tmpdir} && exit 0