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

Edit tinyutils
author Paul Issott <paul@slitaz.org>
date Fri Apr 18 20:01:11 2014 +0100 (2014-04-18)
parents 59ac61f85a23
children db2e1eae0bf2
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 }" \
37 --inputbox "\nEnter new root password:" \
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" \
48 --inputbox "\nEnter new user name login:" 12 ${width} 2>${tmp}
49 user=$(cat $tmp)
50 [ "$user" == "" ] && return 0
51 dialog --title "$title" \
52 --inputbox "\nEnter password for $user:" 12 ${width} 2>${tmp}
53 passwd=$(cat $tmp)
54 [ "$passwd" == "" ] && return 0
55 adduser -D -g "SliTaz User" -G users ${user}
56 # User groups
57 for group in audio cdrom video tty; do
58 addgroup ${user} ${group}
59 done
60 # Slim default user on post-install
61 if [ -f "/etc/slim.conf" ] && [ ! -f "/var/lib/slitaz/post-install" ]; then
62 sed -i s"/default_user .*/default_user $user/" /etc/slim.conf
63 fi
64 }
66 set_date() {
67 clear && newline
68 echo -n "Old date:"; date
69 rdate -s tick.greyware.com 2>/dev/null
70 echo -n "New date:"; date
71 sleep 4
72 }
74 # Main Dialog menu
75 main_box() {
76 dialog \
77 --clear --title "$title" \
78 --ok-label "Exec" --cancel-label "Quit" \
79 --menu "" ${height} ${width} 14 \
80 "keyboard" "$(gettext 'System keyboard setting')" \
81 "locale" "$(gettext 'System language setting')" \
82 "add-user" "$(gettext 'Add a new user')" \
83 "root-passwd" "$(gettext 'Change root password')" \
84 "set-date" "$(gettext 'Set system date from the web')" \
85 "quit" "$(gettext 'Exit from SliTaz Config')" 2>${tmp}
87 # Handle options
88 opt=${?}
89 case "$opt" in
90 1|255) rm -rf ${tmpdir} && exit 0 ;;
91 esac
93 # Handle actions
94 action=$(cat $tmp)
95 case "$action" in
96 keyboard) tazkeymap ;;
97 locale) tazlocale ;;
98 add-user) add_user ;;
99 root-passwd) root_passwd ;;
100 set-date) set_date ;;
101 quit) rm -rf ${tmpdir} && exit 0 ;;
102 esac
103 }
105 #
106 # Handle commands
107 #
109 case "$1" in
110 *_*)
111 # Execute functions
112 $@ ;;
113 *)
114 while true; do
115 main_box
116 done ;;
117 esac
119 # Clean exit
120 rm -rf ${tmpdir}
121 exit 0