slitaz-tools view tinyutils/slitaz-config @ rev 862

Tiny bit of color for new user and root pass in slitaz-config
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 20 17:26:40 2014 +0200 (2014-04-20)
parents db2e1eae0bf2
children 5062327d8e93
line source
1 #!/bin/sh
2 #
3 # SliTaz Config - A tool with all SliTaz Ncurses configs in one place for
4 # text mode systems (server, ARM devices)
5 #
6 # Copyright (C) 2014 SliTaz ARM - BSD License
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /lib/libtaz.sh
10 check_root
12 title="{ SliTaz Config }"
13 about="/usr/share/doc/slitaz/post-install.txt"
14 tmpdir="/tmp/$(basename $0)"
15 tmp="$tmpdir/$$"
16 height="20"
17 width="72"
19 # Use a tmp directory
20 mkdir -p ${tmpdir}
22 #
23 # GUI Functions
24 #
26 # Coded for the ARM first boot settings
27 about_post_install() {
28 dialog --cr-wrap \
29 --title "{ Post Installation }" \
30 --exit-label "Continue" \
31 --textbox "$about" ${height} ${width}
32 }
34 # Set root passwd
35 root_passwd() {
36 dialog --title "{ Root Password }" --colors \
37 --inputbox "\nEnter new password for \Zb\Z1root" \
38 12 ${width} 2>${tmp}
39 passwd=$(cat $tmp)
40 [ "$passwd" == "" ] && return 0
41 echo "root:$passwd" | chpasswd --md5
42 }
44 # Add a new user
45 add_user() {
46 title="{ Add User }"
47 dialog --title "$title" --colors \
48 --inputbox "\nEnter login name for the new \Zb\Z4user" 12 ${width} 2>${tmp}
49 user=$(cat $tmp)
50 [ "$user" == "" ] && return 0
51 dialog --title "$title" --colors \
52 --inputbox "\nEnter password for user \Zb\Z4${user}" 12 ${width} 2>${tmp}
53 passwd=$(cat $tmp)
54 [ "$passwd" == "" ] && return 0
55 adduser -D -g "SliTaz User" -G users ${user}
56 echo "$user:$passwd" | chpasswd --md5
57 # User groups
58 for group in audio cdrom video tty; do
59 addgroup ${user} ${group}
60 done
61 # Slim default user on post-install
62 if [ -f "/etc/slim.conf" ] && [ ! -f "/var/lib/slitaz/post-install" ]; then
63 sed -i s"/default_user .*/default_user $user/" /etc/slim.conf
64 fi
65 }
67 set_date() {
68 clear && newline
69 echo -n "Old date:"; date
70 rdate -s tick.greyware.com 2>/dev/null
71 echo -n "New date:"; date
72 sleep 4
73 }
75 # Main Dialog menu
76 main_box() {
77 dialog \
78 --clear --title "$title" \
79 --ok-label "Exec" --cancel-label "Quit" \
80 --menu "" ${height} ${width} 14 \
81 "keyboard" "$(gettext 'System keyboard setting')" \
82 "locale" "$(gettext 'System language setting')" \
83 "add-user" "$(gettext 'Add a new user')" \
84 "root-passwd" "$(gettext 'Change root password')" \
85 "set-date" "$(gettext 'Set system date from the web')" \
86 "quit" "$(gettext 'Exit from SliTaz Config')" 2>${tmp}
88 # Handle options
89 opt=${?}
90 case "$opt" in
91 1|255) rm -rf ${tmpdir} && exit 0 ;;
92 esac
94 # Handle actions
95 action=$(cat $tmp)
96 case "$action" in
97 keyboard) tazkeymap ;;
98 locale) tazlocale ;;
99 add-user) add_user ;;
100 root-passwd) root_passwd ;;
101 set-date) set_date ;;
102 quit) rm -rf ${tmpdir} && exit 0 ;;
103 esac
104 }
106 #
107 # Handle commands
108 #
110 case "$1" in
111 *_*)
112 # Execute functions
113 $@ ;;
114 *)
115 while true; do
116 main_box
117 done ;;
118 esac
120 # Clean exit
121 rm -rf ${tmpdir}
122 exit 0