summaryrefslogtreecommitdiffstats
path: root/tools/tools/upgrade/move_aout_libs.sh
blob: 7d9600ffbb609f9f1a66fc0d254d9c9da869dd05 (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
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
#!/bin/sh
#
#	$Id: move_aout_libs.sh,v 1.4 1999/02/01 12:45:03 jkh Exp $
# 
# Search for a.out libraries and move them to an aout subdirectory of
# the elf library directory.
#
# The arguments are the directories to search.
#
libdirs="$*"

# Create a temporary tool to get the timestamp of libraries. No, I don't
# want to use perl or whatever.
create_get_time_stamp ( )
{
	echo "#include <stdio.h>" > /tmp/get_time_stamp.c
	echo "#include <sys/stat.h>" >> /tmp/get_time_stamp.c
	echo "int main(int argc, char *argv[]) {" >> /tmp/get_time_stamp.c
	echo "int ierr; struct stat fs;" >> /tmp/get_time_stamp.c
	echo "if ((ierr = stat(argv[1],&fs)) == 0)" >> /tmp/get_time_stamp.c
	echo "printf(\"%ld\n\",(long) fs.st_mtime);" >> /tmp/get_time_stamp.c
	echo "return (ierr); }" >> /tmp/get_time_stamp.c
	gcc -o /tmp/get_time_stamp /tmp/get_time_stamp.c
	rm /tmp/get_time_stamp.c
	return
}

# Move an a.out library to the aout subdirectory of the elf directory.
move_file ( ) 
{
	if test -d $dir/aout; then
	else
		echo "Creating directory $dir/aout"
		mkdir $dir/aout
		ldconfig -m $dir/aout
	fi
	fname=${file#$dir/}
	if test -f $dir/aout/$fname; then
		if test -x /tmp/get_time_stamp; then
		else
			create_get_time_stamp
		fi
		t1=`/tmp/get_time_stamp $dir/aout/$fname`
		t2=`/tmp/get_time_stamp $file`
		if test $t1 -gt $t2; then
			echo $file is older than $dir/aout/$fname
			answer=""
			while test "$answer" != "y" -a "$answer" != "n"; do
				read -p "OK to delete the older file? (y/n) " answer
			done
			if test $answer = "y"; then
				echo Deleting $file
				chflags noschg $file
				rm $file
			else
				echo "You need to move $file out of $dir because that's an elf directory"
			fi
		else
			echo $dir/aout/$fname is older than $file
			answer=""
			while test "$answer" != "y" -a "$answer" != "n"; do
				read -p "OK to overwrite the older file? (y/n) " answer
			done
			if test $answer = "y"; then
				echo Overwriting $dir/aout/$fname with $file
				chflags noschg $file
				mv $file $dir/aout/$fname
				ldconfig -R
			else
				echo "You need to move $file out of $dir because that's an elf directory"
			fi
		fi
	else
		echo Move $fname from $dir to $dir/aout
		chflags noschg $file
		mv $file $dir/aout/$fname
		ldconfig -R
	fi
	return
}

# Given a list of files in a directory, find those that are a.out
# libraries and move them.
move_if_aout ( ) 
{
	# Check each library
	for file in $files
	do
		# Don't touch symbolic links yet. It's not clear how
		# they should be handled.
		if test -h $file; then
		else
			# Check that this is a normal file.
			if test -f $file; then
				# Identify the file by magic
				filemagic=`file $file`

				# Check if the file is an a.out library
				if expr "$filemagic" : ".*$aoutmagic"; then
					# Move the a.out library
					move_file
				fi
			fi
		fi
	done
	return
}

# Only search the directories specified.
for dir in $libdirs
do
	# Make sure the directory exists, or ldconfig will choke later.
	mkdir -p $dir $dir/aout

	echo "Searching library directory $dir for a.out libraries..."

	# Get a list of archive libraries.
	files=`ls $dir/*.a 2> /dev/null`

	# a.out archive libraries look like this:
	aoutmagic="current ar archive random library"

	# Move each a.out archive library:
	move_if_aout

	# Get a list of shared libraries
	files=`ls $dir/*.so.*.* 2> /dev/null`

	# a.out shared libraries look like this:
	aoutmagic="FreeBSD/i386 compact demand paged shared library"

	# Move each a.out shared library:
	move_if_aout
done

# If we created the time stamp program, delete it:
if test -x /tmp/get_time_stamp; then
	rm /tmp/get_time_stamp
fi
OpenPOWER on IntegriCloud