summaryrefslogtreecommitdiffstats
path: root/zarb-ml/mageia-discuss/attachments/20121130/e5b29adf/attachment.bin
blob: aa9c13873c249b7c218bef66ae8fab1294771448 (plain)
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
#!/bin/sh
# This script is used to save an old configuration allowing
# a new installation. Thus the local hidden files and directories
# cannot interfer with the new installation.
# /home must be a partition (/ home not included in / partition)
# Each user gets a new fresh environment. All old directories and files
# are moved in ~/ancien and nothing is lost.
# The system configuration is copied in /home/frigo, allowing to format /
# Pierre Jarillon - 2009 - License GPL 

ETC=/etc
FRIGO=/home/frigo

date

# -------------------------------------------------------------------------------------
if [ $(basename `pwd`) != 'home' ]
then 
	echo "Error : The pending directory must be home. Use the command : cd /home"; 
	exit 1; 
fi

echo "Ce script is intended to be executed before a new system reinstallation."
echo "It allows to create a new fresh session for each user without any lost."
echo "System datas are saved in $FRIGO and old /home/*/ are moved in /home/*/ancien/"
echo "All sessions using /home must be closed."
echo ""
echo -n "OK to continue? [y/N]: "
read response
if [ -z $response ]; then
	   response=n
fi
echo ""
case $response in
   [OoYy]*) 
   	echo "OK..."
	;;
	*)
          echo "Aborted"
         exit 0 ;;
esac

# -----------------Safe storage location-----------------------------------------------

if [ -d $FRIGO ]; then rm -rf $FRIGO; fi;
mkdir $FRIGO
mkdir $FRIGO/faces

# -------------------------------------------------------------------------------------

ls -1|while read d
do
	if [ ! -d $d ]; then continue; fi
	n=`basename $d` 
	x="x"
	x=`grep ^$n: ../etc/passwd|cut -d: -f1`
	if [ m$x != m$n ] ;then continue ;fi
	g=`grep ^$n: ../etc/passwd|cut -d: -f4`
#	echo $n > $FRIGO/liste
	[ -f /usr/share/faces/$n.png ] && cp /usr/share/faces/$n.png  $FRIGO/faces/
	echo "Traité : $n  groupe : $g"

	date > $n/ladate.$n.txt
	cp -a /etc/skel .
	chown -R $n:$g skel
	mv $n skel/
	mv skel/$n skel/ancien
	mv skel $n
done

# A full copy of /etc in /home/$FRIGO is the best. In fact, few files are used
# If the user uid 500 is saved it is not necessary to ask for it during the install.

# cp -a /etc $FRIGO/

awk -F : '{a=$3+0; if ((a >499)&&(a<10000))print $0}' $ETC/passwd > $FRIGO/passwd
cut -d: -f1 $FRIGO/passwd|while read user; do grep "^$user" $ETC/group >> $FRIGO/group; done
cut -d: -f1 $FRIGO/passwd|while read user; do grep "^$user" $ETC/shadow >> $FRIGO/shadow; done
grep HOSTNAME $ETC/sysconfig/network > $FRIGO/hostname
cp $ETC/hosts $FRIGO/hosts
if [ -d $ETC/ssh ]
then
	mkdir $FRIGO/ssh; cp -p $ETC/ssh/ssh_host_* $FRIGO/ssh/
fi
echo "Done."