[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: user-setup (1.24)



On Wednesday 20 May 2009, Otavio Salvador wrote:
> On Wed, May 20, 2009 at 4:46 PM, Frans Pop <elendil@planet.nl> wrote:
> > No, it's still broken. You're seriously underestimating the
> > complexity here.
>
> I'd love to know what I missed, if you don't mind to explain.

Try a grep for codename. It's a fairly basic check when doing something
like this and should have made you alert.

I'll give you a hint: installation from CD without use of a mirror. In
that case mirror/codename never gets set. Not the most common use case,
but very much a valid one for Lenny+1/2. That's exactly why I said you'd
probably only notice the bug after release: you'd probably never think
(or have time) to test that installation variant, although IMO it's
one of the more essential test cases.

Suggest you do some research based on my hint. You'll learn something.
You should look at least at cdrom-detect and apt-setup.

> Anyway an alternative patch is attached.

That's not what I call KISS. Main problem is that in ~2 years time
someone will have to untangle what exactly is legacy and what is not.

Here's how I would do it. Yes, there is (minor) code duplication, but it
is also 100% clear what is legacy and what's not and cleaning it up is
trivial. It is also much simpler to check the legacy support in the new
version for correctness by doing a 'svn diff -r53753 user-setup-apply'.

This is after my cleanup commit to remove unused OPT var in current code.

Index: user-setup-apply
===================================================================
--- user-setup-apply	(revision 58644)
+++ user-setup-apply	(working copy)
@@ -28,10 +28,26 @@
 	local USER PASSWD
 	USER="$1"
 	PASSWD="$2"
-	if [ "$3" = true ]; then
-		$chroot $ROOT usermod --password=$PASSWD $USER
- 	else
-		$chroot $ROOT chpasswd <<EOF
+
+	local VERSION=$($chroot $ROOT dpkg -s passwd | sed -n '/^Version:/s,^Version: ,,p')
+	if $chroot $ROOT dpkg --compare-versions $VERSION ge 1:4.1.4-1; then
+		# support for versions with PAM support (Squeeze)
+		if [ "$3" = true ]; then
+			$chroot $ROOT usermod --password=$PASSWD $USER
+		else
+			$chroot $ROOT chpasswd <<EOF
 $USER:$PASSWD
 EOF
+		fi
+	else
+		# compatibility support for versions without PAM support (Lenny)
+		local OPTS
+		if [ "$3" = true ]; then
+			OPTS=-e
+		else
+			OPTS=-m
+		fi
+ 		$chroot $ROOT chpasswd $OPTS <<EOF
+$USER:$PASSWD
+EOF
 	fi


Reply to: