summaryrefslogtreecommitdiffstats
path: root/perl-install/install/share/upgrade/conectiva.10/pre.merge-groups.sh
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2007-04-25 12:26:16 +0000
committerPascal Rigaux <pixel@mandriva.com>2007-04-25 12:26:16 +0000
commit126777bc019a54afb4ec51299f2cf9d2841698aa (patch)
tree97f76e571902ead55ba138f1156a4b4f00b9b779 /perl-install/install/share/upgrade/conectiva.10/pre.merge-groups.sh
parentf1f67448efc714873378dfeb8279fae68054a90a (diff)
downloaddrakx-126777bc019a54afb4ec51299f2cf9d2841698aa.tar
drakx-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.gz
drakx-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.bz2
drakx-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.xz
drakx-126777bc019a54afb4ec51299f2cf9d2841698aa.zip
re-sync after the big svn loss
Diffstat (limited to 'perl-install/install/share/upgrade/conectiva.10/pre.merge-groups.sh')
-rwxr-xr-xperl-install/install/share/upgrade/conectiva.10/pre.merge-groups.sh87
1 files changed, 87 insertions, 0 deletions
diff --git a/perl-install/install/share/upgrade/conectiva.10/pre.merge-groups.sh b/perl-install/install/share/upgrade/conectiva.10/pre.merge-groups.sh
new file mode 100755
index 000000000..b735d2bbe
--- /dev/null
+++ b/perl-install/install/share/upgrade/conectiva.10/pre.merge-groups.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+#
+# cnc2mdv /etc/group file merger
+#
+# What it does:
+#
+# - Adds three new groups:
+# - Check if these groups or its gids already exists;
+# - Remove root from the wheel group.
+#
+
+destfile=${destfile:-/etc/group}
+backupfile=${destfile}.cnc2mdv
+
+# these are the new groups that are introduced by Mandriva
+groups=( usb 43 tape 21 nogroup 65534 )
+
+# error codes
+group_already_exists_=8
+group_already_exists=9
+gid_not_unique=4
+
+sort_groups_by_gid()
+{
+ sort -nt: +2 -3 -o $destfile $destfile #wow
+
+ return 0
+}
+
+
+add_new_groups()
+{
+ for (( i=0; i < ${#groups[@]}; i += 2)); do
+ n=$[$i+1]
+ gid=${groups[$n]}
+ gname=${groups[$i]}
+
+ errors=yes
+ while [ $errors = "yes" ]; do
+ groupadd -g $gid $gname
+ case $? in
+ 0)
+ # ok, no errors, group really added
+ errors=no
+ ;;
+
+ $group_already_exists | $group_already_exists_ )
+ # ok, no problem at all
+ errors=no
+ ;;
+
+ $gid_not_unique)
+ # bleh, increment gid and try again
+ # hum, but if ... 65534?
+ gid=$[$gid+1]
+ ;;
+
+ *)
+ echo "unexpected error during groupadd ($?)"
+ return 1;
+ ;;
+ esac
+ done # while errors
+ done # for
+
+ return 0
+}
+
+
+remove_root_from_wheel()
+{
+ sed -i 's/\(wheel:[^:]*:[^:]*:\)root,*\(.*\)/\1\2/' ${destfile}
+
+ return 0
+}
+
+
+main()
+{
+ add_new_groups &&
+ sort_groups_by_gid &&
+ remove_root_from_wheel
+}
+
+main
+
+# vim:ts=4:sw=4:ai