LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-06-2009, 04:27 AM   #1
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
mv in -current behaves strange in script


Last night I made a slack box as a Virtual Machine and updated it to -current. When I ran my build script, I noticed very strange behavior in the "mv" command. I will list the script code here, along with the workaround in it. Still I am confused and hope someone from Slack can help shed a light on the behavior. The buildscript is for MLT btw, in red the workaround;

Code:
#!/bin/sh

#
# Global variables
#

CURDIR=`pwd`
BUILDDIR="${CURDIR}/mlt"
TARGETDIR="${CURDIR}/target"
INSTALLDIR="${TARGETDIR}/usr/"
ARCH=${ARCH:-i686}
BUILD=${BUILD:-1}
TAG=${TAG:-_MDG}
PRGNAME=mlt
VERSION="0.4.4"

main()
{
	makedirs
	uncompress
	build
	make_pkg
	cleanup
}

download()
{
	echo "Starting download..."
	wget http://downloads.sourceforge.net/project/mlt/mlt/${VERSION}/mlt-${VERSION}.tar.gz?use_mirror=ovh
	echo "Download complete"
}

uncompress()
{
	if [ -e ${PRGNAME}-${VERSION}.tar.gz ]
	then
		echo "Uncompressing..."
		tar zxf ${PRGNAME}-${VERSION}.tar.gz
		if [ -d ${PRGNAME}-${VERSION} ]
		then
			# when downloaded from stable branch
			# the source directory gets a version number
			# it gets stripped here
			mv ${PRGNAME}-${VERSION} ${PRGNAME}
			if [ -d ${PRGNAME}/${PRGNAME}-${VERSION} ]
			then
				# Something strange happens in Slackware-current
				# where there is a directory placed _between_
				# the current directory and the source directory
				cd ${PRGNAME}
				mv ${PRGNAME}-${VERSION}/* ./
				cd ..
			fi
		fi
	else
		download
	fi
}

makedirs()
{
	echo "Creating dirs..."
	mkdir -p ${SRCDIR} ${BUILDDIR} ${TARGETDIR}
}

build()
{
	cd ${BUILDDIR}
	./configure --prefix=${INSTALLDIR} --enable-gpl --qimage-libdir=/usr/lib/ --qimage-includedir=/usr/include/qt4 --avformat-swscale
	if [ $? -eq 0 ]
	then
		make
		make install
	fi
}

cleanup()
{
	echo "Cleaning up"
	cd ${CURDIR}
	rm -rf ${TARGETDIR} ${BUILDDIR} ${PRGNAME}
}

make_pkg()
{
	mkdir -p ${TARGETDIR}/usr/doc/${PRGNAME}-${VERSION}

	cp -a AUTHORS COPYING INSTALL README ${TARGETDIR}/usr/doc/${PRGNAME}-${VERSION} 
	cat ${CURDIR}/${PRGNAME}.SlackBuild > ${TARGETDIR}/usr/doc/${PRGNAME}-${VERSION}/${PRGNAME}.SlackBuild
	find ${TARGETDIR}/usr/doc/$PRGNAM-$VERSION -type f -exec chmod 644 {} \;

	mkdir -p ${TARGETDIR}/install
	cat ${CURDIR}/slack-desc > ${TARGETDIR}/install/slack-desc

	cd ${TARGETDIR}
	/sbin/makepkg -l y -c n ${CURDIR}/${PRGNAME}-${VERSION}-${BUILD}-${ARCH}${TAG}.tgz

}

main
When I run these commands manually, as a test
Code:
mv <dir> <new name of the dir>
the predictable happens, <dir> gets renamed to <new name of the dir>. In the script I got <new name of the dir>/<dir>; <dir> got moved into a newly created directory.

In 12.2 this behavior did not happen, in -current it does. Anyone with any clues?

Secondly, the manpage of makepkg nor makepkg -h tells how to make the packages in the new format; But that's something minor to me.

Last edited by Ramurd; 08-06-2009 at 04:37 AM. Reason: Too cryptic topic title
 
Old 08-06-2009, 07:24 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Most likely a change because of upgrading to coreutils-7.4 from 6.12. coreutils has been gradually implementing newer POSIX standards for a long while and this may be due to that.
 
Old 08-06-2009, 07:30 AM   #3
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Original Poster
Rep: Reputation: 111Reputation: 111
I could understand that if in script and on prompt behaved similar, but overall a good pointer! What I'm wondering is how this may affect other programs, since mv has a tendency to be used often, mostly in scripts. All those scripts would behave different than expected based on previous behavior.
 
Old 08-06-2009, 09:53 AM   #4
rg3
Member
 
Registered: Jul 2007
Distribution: Fedora
Posts: 527

Rep: Reputation: Disabled
I suspect the problem is not in mv. mv behaves that way when the destination directory exists. In other words, mv old_dir new_dir renames the directory, unless new_dir is already a directory. In that case it moves old_dir into new_dir. You should check the directory does not exist before running mv.
 
Old 08-06-2009, 10:36 AM   #5
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Original Poster
Rep: Reputation: 111Reputation: 111
I know that is the normal behavior, as this is defined in the standard; Now it wasn't so early last night when I ran this, but still pretty certain the directory does not exist prior to running "mv"; Now there is a (small) chance this directory comes to exist during the script; I'll have a look on that.

I ran this script in a new, empty directory; heck, I even kicked the lady out of it ;-) When I run this script again (tonight) I will monitor very closely what directories come to exist and either come back groveling saying I was at fault or still with this big questionmark above my head.
 
Old 08-06-2009, 02:54 PM   #6
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Original Poster
Rep: Reputation: 111Reputation: 111
I have to disappoint here, I need another day or so; getting the next kdenlive package to compile at all took the greater part of the day, and that has priority for me. Will get back on this soon.
 
Old 08-06-2009, 03:24 PM   #7
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
Run the script with the -x flag and paste the relevant bits here.
 
Old 08-07-2009, 01:21 AM   #8
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Original Poster
Rep: Reputation: 111Reputation: 111
ouch, I have to grovel humbly here...

When running with -x I noticed what happens in makedirs, one of the dirs made is ${BUILDDIR}; which happens to be "<path>/mlt", hence mv behaving as it should according to the standards. Still strange I made this beginners mistake and got away with it in 12.2;
Code:
++ pwd
+ CURDIR=/slackbuilds/mlt
+ BUILDDIR=/slackbuilds/mlt/mlt
+ TARGETDIR=/slackbuilds/mlt/target
+ INSTALLDIR=/slackbuilds/mlt/target/usr/
+ ARCH=i686
+ BUILD=1
+ TAG=_MDG
+ PRGNAME=mlt
+ VERSION=0.4.4
+ main
+ makedirs
+ echo 'Creating dirs...'
Creating dirs...
+ mkdir -p /slackbuilds/mlt/mlt /slackbuilds/mlt/target
 
Old 08-07-2009, 08:09 AM   #9
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
Quote:
Originally Posted by Ramurd View Post
ouch, I have to grovel humbly here...

When running with -x I noticed what happens in makedirs, one of the dirs made is ${BUILDDIR}; which happens to be "<path>/mlt", hence mv behaving as it should according to the standards.
Very good - that's *exactly* what I expected to happen (that you would catch the mistake when looking at the -x output). :-)
 
  


Reply

Tags
current, mv, script



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange behavior when killing bash through a script alirezan1 Linux - Newbie 3 03-12-2009 07:29 PM
Very Strange Behavior raysr Mandriva 4 08-31-2004 02:06 PM
Strange Script Behavior Stranger Linux - General 0 02-18-2004 03:30 AM
Strange Behavior andrewb758 Linux - Hardware 5 08-31-2003 02:42 PM
strange behavior abhijit Linux - General 3 07-09-2003 11:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration