1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
#!/bin/bash
# Synopsis: update_fstab_on_target
#
# This function is partly adapted from the Knoppix-Installer
# It creates a new fstab for the new installed system in $TARGET.
# * proc, usbfs, sysfs, tmpfs: hardcoded
# * all mountpoints of the hd_map
# * cdroms, floppy
# * remove not needed device links
function update_fstab_on_target()
{
send install_step update_fstab_on_target
emit_progress 0
local progress_steps=$(( $(wc -l <<<"$cfg_hdmap") + 2 ))
local progress=0
# Charset stuff for FAT/NTFS-Filesystems
unset utf_option nls
if [ "$(locale charmap)" = "UTF-8" ]; then
utf_option=",utf8"
nls=",nls=utf8"
fi
chroot_it locale-gen &>/dev/null
# Build new /etc/fstab
cat <<EOF >$TARGET/etc/fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
EOF
[ -x $TARGET/etc/init.d/mountkernfs.sh ] || cat <<EOF >>$TARGET/etc/fstab
sysfs /sys sysfs defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
EOF
while IFS=: read device mountpoint filesystem automount
do
if [ -z "$mountpoint" ]; then
# update progress
progress=$[progress+1]; emit_progress $[100*progress/progress_steps]
continue
fi
fstab_options=""; fstab_dump=0; fstab_pass=2; fstab_type=""
[ -z "$fstab_type" ] && fstab_type=$filesystem
[ -z "$fstab_type" ] && fstab_type=$(get_filesystem $device)
[ -z "$fstab_type" ] && fstab_type=auto
case "$automount" in
auto)
fstab_options="defaults";;
*)
fstab_options="noauto,users";;
esac
case "$fstab_type" in
msdos)
fstab_options="${fstab_options},umask=000,quiet${utf_option}"; fstab_pass=0;;
vfat)
fstab_options="${fstab_options},umask=000,shortname=mixed,quiet${utf_option}"; fstab_pass=0;;
esac
if [ "$mountpoint" = "/" ]; then
fstab_pass=1
case $fstab_type in
btrfs)
fstab_options="defaults"
fstab_pass=0
;;
reiser*|xfs|jfs)
fstab_options="defaults"
;;
*)
fstab_options="defaults,errors=remount-ro"
;;
esac
elif [ "${mountpoint:0:7}" = "/media/" ]; then
# don't run fsck on boot for all /media/* mountpoints
fstab_pass=0
else
# don't run fsck on boot if device is a removable disk (if group of /dev/XXX == floppy)
[ "$(stat --format "%G" $device)" = "floppy" ] && fstab_pass=0
fi
fstab_options="${fstab_options##defaults,}"
unset DEV UUID
case $device in
/dev/mapper/*) ;;
/dev/disk/by-uuid/*) DEV=/dev/$(readlink $device|sed s@../../@@)
UUID="UUID=${device#/dev/disk/by-uuid/}"
;;
/dev/*) DEV=$device
UUID="UUID=$(get_partition_uuid $device)"
;;
UUID=*) UUID=$device
DEV=/dev/$(readlink /dev/disk/by-uuid/${device#UUID=}|sed s@../../@@)
;;
esac
[ -n "${DEV#/dev/}" ] && echo "# $DEV" >> $TARGET/etc/fstab
if [ -n "${UUID#UUID=}" ]; then
printf "%-15s %-15s %-7s %-15s %-7s %s\n" "$UUID" "$mountpoint" "$fstab_type" "$fstab_options" "$fstab_dump" "$fstab_pass" >> $TARGET/etc/fstab
else
# this partition doesn't have an UUID
printf "%-15s %-15s %-7s %-15s %-7s %s\n" "$device" "$mountpoint" "$fstab_type" "$fstab_options" "$fstab_dump" "$fstab_pass" >> $TARGET/etc/fstab
fi
# Remove not needed device links
[ "/media/${device##*/}" != "$mountpoint" ] && rmdir "$TARGET/media/${device##*/}" &>/dev/null
rm -f "$TARGET/home/$cfg_username/Desktop/${device##*/}"
# update progress
progress=$[progress+1]; emit_progress $[100*progress/progress_steps]
done <<<"$cfg_hdmap"
# Add swap to /etc/fstab
while read device
do
UUID="$(get_partition_uuid $device)"
if [ -z "$UUID" ]; then
# swap partition without UUID
swapoff $device
mkswap $device
swapon $device
UUID="$(get_partition_uuid $device)"
fi
[ -z "$UUID" ] && continue # should never happen...
printf "%-15s %-15s %-7s %-15s %-7s %s\n" "UUID=$UUID" "none" "swap" "sw" "0" "0" >> $TARGET/etc/fstab
done < <(list_swap_partitions)
# Add cdrom devices to /etc/fstab
CDROM=0
for c in $(gawk '/name/{for (i=NF;i>=3;i--) {print $i}}' /proc/sys/dev/cdrom/info 2>/dev/null); do
[ -d $TARGET/media/cdrom$CDROM ] || mkdir -p $TARGET/media/cdrom$CDROM
if [ "$CDROM" = "0" ]; then
if [ "$(readlink $TARGET/media/cdrom)" != "cdrom0" ]; then
rm -f $TARGET/media/cdrom
ln -s cdrom0 $TARGET/media/cdrom
fi
if [ "$(readlink $TARGET/cdrom)" != "media/cdrom" ]; then
rm -f $TARGET/cdrom
ln -s media/cdrom $TARGET/cdrom
fi
fi
printf "%-15s %-15s %-7s %-15s %-7s %s\n" "/dev/$c" "/media/cdrom$CDROM" "udf,iso9660" "user,noauto" "0" "0" >> $TARGET/etc/fstab
CDROM=$(($CDROM+1))
done
if [ "$CDROM" = "0" ]; then
rm -f $TARGET/cdrom $TARGET/media/cdrom
fi
# Add floppy devices to /etc/fstab
for f in $(ls -d /sys/block/fd* 2>/dev/null); do
[ -d $TARGET/media/floppy${f#/sys/block/fd} ] || mkdir -p $TARGET/media/floppy${f#/sys/block/fd}
printf "%-15s %-15s %-7s %-15s %-7s %s\n" "/dev${f#/sys/block}" "/media/floppy${f#/sys/block/fd}" "auto" "rw,user,noauto" "0" "0" >> $TARGET/etc/fstab
done
}
# Synopsis: update_passwd_on_target
#
function update_passwd_on_target()
{
send install_step update_passwd_on_target
chroot $TARGET sh -c "usermod --password '$cfg_rootpwd' root"
if [ -x $ROOT/usr/sbin/adduser ]; then
LC_ALL=C chroot $TARGET adduser --disabled-password --force-badname --no-create-home --gecos "$cfg_realname,,," --uid 1000 "$cfg_username" >/dev/null
else
chroot $TARGET useradd -c "$cfg_realname,,," "$cfg_username" -u 1000 >/dev/null
fi
chroot $TARGET sh -c "usermod --password '$cfg_userpwd' '$cfg_username'"
for group in lpadmin scanner; do
chroot $TARGET addgroup --system $group >/dev/null 2>&1
done
for group in adm audio cdrom dialout floppy video plugdev dip lpadmin lp scanner powerdev netdev; do
chroot $TARGET adduser --force-badname "$cfg_username" $group >/dev/null 2>&1
done
}
# Synopsis: copy_home_to_target
#
# This function copies the home directory from the live user
function copy_home_to_target()
{
send install_step copy_home_to_target
#check if already data is there then stop
if [ -d "$TARGET/home/$cfg_username" ]; then
chroot "$TARGET" chown -R "$cfg_username":"$cfg_username" "/home/$cfg_username"
return 0
fi
if [ -d "/home/$FLL_LIVE_USER/.kde" ]; then
rm -rf "$TARGET/home/$FLL_LIVE_USER"
cp -a "/home/$FLL_LIVE_USER" "$TARGET/home"
[ "$cfg_username" != "$FLL_LIVE_USER" ] && mv "$TARGET/home/$FLL_LIVE_USER" "$TARGET/home/$cfg_username"
else
cp -a "$TARGET/etc/skel" "$TARGET/home"
mv "$TARGET/home/skel" "$TARGET/home/$cfg_username"
fi
# update home-path in user's config files
if [ "$cfg_username" != "$FLL_LIVE_USER" ]; then
rm -f "$TARGET/home/$cfg_username/.mozilla/appreg"
rm -f "$TARGET/home/$cfg_username/.mozilla/pluginreg.dat"
if [ -e "$TARGET/home/$cfg_username/.mozilla/$FLL_LIVE_USER" ]; then
[ -e "$TARGET/home/$cfg_username/.mozilla/default" ] || mv "$TARGET/home/$cfg_username/.mozilla/$FLL_LIVE_USER" "$TARGET/home/$cfg_username/.mozilla/default"
perl -pi -e 's/.*general.useragent.*\n?//' "$TARGET/home/$cfg_username/.mozilla/default/*/prefs.js"
fi
OLDHOME="/home/$FLL_LIVE_USER"
NEWHOME="/home/$cfg_username"
PART="$TARGET"
for f in $(find "$PART$NEWHOME" -exec grep -ls "$OLDHOME" {} \;|grep -v $0); do
perl -pi -e "s|$OLDHOME|$NEWHOME|g" "$f"
done
fi
# revert to plain debian .bashrc
cat "$TARGET/etc/skel/.bashrc" > "$TARGET/home/$cfg_username/.bashrc"
# revert kdesu/sudo workaround
rm -f "$TARGET/home/$cfg_username/.kde/share/apps/konsole/su.desktop" \
"$TARGET/home/$cfg_username/.kde/share/apps/konsole/sumc.desktop" \
"$TARGET/home/$cfg_username/.kde/share/config/kdesurc" \
"$TARGET/home/$cfg_username/.kde4/share/config/kdesurc" \
"$TARGET/home/$cfg_username/.trinity/share/config/kdesurc" \
"$TARGET/home/$cfg_username/.su-to-rootrc"
rm -rf "$TARGET/home/$cfg_username/.gconf/apps/gksu"
# revert trinity kdesu workaround to default
[ -e "$TARGET/etc/skel/.trinity/share/config/kdesurc" ] && \
cp "$TARGET/etc/skel/.trinity/share/config/kdesurc" "$TARGET/home/$cfg_username/.trinity/share/config/kdesurc"
# force kde first time configuration
if [ -f /etc/skel/.kde/share/config/kpersonalizerrc ]; then
perl -pi -e 's/FirstLogin=false/FirstLogin=true/g' "$TARGET/etc/skel/.kde/share/config/kpersonalizerrc"
# The users kde should be perfect, unless we just copied from template ...
[ ! -d "/home/$FLL_LIVE_USER/.kde" ] && perl -pi -e 's/FirstLogin=false/FirstLogin=true/g' "$TARGET/home/$cfg_username/.kde/share/config/kpersonalizerrc"
fi
chroot "$TARGET" chown -R "$cfg_username":"$cfg_username" "/home/$cfg_username"
}
# Synopsis: copy_etc_to_target
#
# This function is partly adapted from the Knoppix-Installer
function copy_etc_to_target()
{
send install_step copy_etc_to_target
# UTC=no fix
if [ -f /etc/default/rcS -a -f $TARGET/etc/default/rcS ]; then
cat /etc/default/rcS > $TARGET/etc/default/rcS
fi
cp -a /etc/timezone $TARGET/etc/timezone
cp -a /etc/localtime $TARGET/etc/localtime
cp -a /etc/default/keyboard $TARGET/etc/default/keyboard
cp -a /etc/default/locale $TARGET/etc/default/locale
cp -a /etc/locale.gen $TARGET/etc/locale.gen
#cp -a /etc/console/* $TARGET/etc/console/
#cp -a /etc/environment $TARGET/etc/environment
# create locales
chroot_it locale-gen &>/dev/null
chroot_it dpkg-reconfigure -fnoninteractive keyboard-configuration &>/dev/null
# nvidia autoinstall trigger
chroot_it update-rc.d -f kanotix remove &>/dev/null
rm -f $TARGET/etc/init.d/kanotix
# xorg.conf
debconf-get-selections | grep -e xserver-xorg -e tzdata | chroot_it debconf-set-selections &>/dev/null
#rm -f $TARGET/etc/X11/xorg.conf*
chroot_it dpkg-reconfigure -phigh xserver-xorg &>/dev/null
# Save ALSA sound volume
if [ -e /proc/asound/modules ] && [ -x /usr/sbin/alsactl ]; then
/usr/sbin/alsactl store
if [ -f /var/lib/alsa/asound.state ]; then
cp /var/lib/alsa/asound.state "$TARGET/var/lib/alsa"
fi
fi
# KDM: auto login
kdmrc=$TARGET/etc/kde3/kdm/kdmrc
[ -f $TARGET/etc/kde4/kdm/kdmrc ] && kdmrc=$TARGET/etc/kde4/kdm/kdmrc
if [ -e $kdmrc ]; then
perl -pi -e "s|^[#\s]*(AutoLoginUser).*|\1=$cfg_username|" $kdmrc
[ "$cfg_autologin" = "on" ] && autologin="true" || autologin="false"
perl -pi -e "s|^[#\s]*(AutoLoginEnable).*|\1=$autologin|" $kdmrc
fi
# Crypto
cp -a /etc/crypttab $TARGET/etc/crypttab
# PolicyKit
if [ -e /etc/PolicyKit/PolicyKit.conf -a -e $TARGET/etc/PolicyKit/PolicyKit.conf ]; then
sed '/<!-- .* user in live session -->/d; s/user="'"$FLL_LIVE_USER"'"/user="'"$cfg_username"'"/;' \
< /etc/PolicyKit/PolicyKit.conf > $TARGET/etc/PolicyKit/PolicyKit.conf
fi
}
|