* updated krdc (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / base / stone / stone_mod_setup.sh
blobc1b16d49246ddeb2a684c01cec746ed1e1819eb8
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/stone/stone_mod_setup.sh
3 # Copyright (C) 2004 - 2021 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 # This module should only be executed once directly after the installation
15 get_uuid() {
16 local dev="$1"
18 # look up uuid
19 for _dev in /dev/disk/by-uuid/*; do
20 local d=$(readlink $_dev)
21 d="/dev/${d##*/}"
22 if [ "$d" = $dev ]; then
23 echo $_dev
24 return
26 done
27 echo $dev
30 make_fstab() {
31 tmp1=`mktemp` ; tmp2=`mktemp`
33 # some defaults and fallbacks
34 cat <<- EOT > $tmp2
35 none /proc proc defaults 0 0
36 none /dev devtmpfs mode=755 0 0
37 none /dev/pts devpts defaults 0 0
38 none /dev/shm tmpfs defaults 0 0
39 none /sys sysfs defaults 0 0
40 none /tmp tmpfs nosuid,nodev,noexec 0 0
41 EOT
43 # currently mounted filesystems
44 sed -e "s/ nfs [^ ]\+/ nfs rw/" < /etc/mtab |
45 sed "s/ rw,/ /; s/ rw / defaults /" >> $tmp2
46 # currently active swaps
47 sed -e 1d -e 's/ .*//' -e 's,.*$,& none swap defaults 0 0,' \
48 /proc/swaps >> $tmp2
50 # sort resulting entries and grab the last (e.g. non-default) one
51 cut -f2 -d' ' < $tmp2 | sort -u | while read dn; do
52 grep " $dn " $tmp2 | tail -n 1 |
53 while read dev point type residual; do
54 dev=$(get_uuid $dev)
55 case $type in
56 *tmpfs|swap)
57 echo $dev $point $type $residual && continue ;;
58 esac
59 case $point in
60 /dev*|/proc*|/sys)
61 echo $dev $point $type $residual ;;
63 echo $dev $point $type ${residual%0 0} 0 1 ;;
65 echo $dev $point $type ${residual%0 0} 0 2 ;;
66 esac
67 done
68 done > $tmp1
70 cat << EOT > $tmp2
71 ARGIND == 1 {
72 for (c=1; c<=NF; c++) if (ss[c] < length(\$c)) ss[c]=length(\$c);
74 ARGIND == 2 {
75 for (c=1; c<NF; c++) printf "%-*s",ss[c]+2,\$c;
76 printf "%s\n",\$NF;
78 EOT
79 gawk -f $tmp2 $tmp1 $tmp1 > /etc/fstab
81 while read a b c d e f ; do
82 printf "%-60s %s\n" "$(
83 printf "%-50s %s" "$(
84 printf "%-40s %s" "$(
85 printf "%-25s %s" "$a" "$b"
86 )" $c
87 )" "$d"
88 )" "$e $f"
89 done < /etc/fstab | tr ' ' '\240' > $tmp1
91 gui_message $'Auto-created /etc/fstab file:\n\n'"$( cat $tmp1 )"
92 rm -f $tmp1 $tmp2
95 set_rootpw() {
96 if [ "$SETUPG" = dialog ] ; then
97 tmp1="`mktemp`" ; tmp2="`mktemp`" ; rc=0
98 gui_dialog --nocancel --passwordbox "Setting a root password. `
99 `Type password:" 8 70 > $tmp1
100 gui_dialog --nocancel --passwordbox "Setting a root password. `
101 `Retype password:" 8 70 > $tmp2
102 if [ -s $tmp1 ] && cmp -s $tmp1 $tmp2 ; then
103 echo -n "root:" > $tmp1 ; echo >> $tmp2
104 cat $tmp1 $tmp2 | chpasswd
105 else
106 gui_message "Password 1 and password 2 are `
107 `not the same" ; rc=1
109 rm $tmp1 $tmp2
110 return $rc
111 else
112 passwd root
113 return $?
117 main() {
118 type -p ldconfig && ldconfig
119 export gui_nocancel=1
121 make_fstab
122 $STONE general set_keymap
123 while ! set_rootpw; do :; done
125 unset gui_nocancel
127 # run the stone modules that registered itself for the first SETUP pass
128 while read -u 200 a b c cmd ; do
129 $STONE $cmd
130 done 200< <( grep -h '^# \[SETUP\] [0-9][0-9] ' \
131 $SETUPD/mod_*.sh | sort )
133 cron.run
135 # run the postinstall scripts right here
136 for x in /etc/postinstall.d/* ; do
137 [ -f $x ] || continue
138 echo "Running $x ..."
140 done
142 exec $STONE