1f08c3bdfSopenharmony_ci#!/bin/bash
2f08c3bdfSopenharmony_ci
3f08c3bdfSopenharmony_ci
4f08c3bdfSopenharmony_ci##############################################################
5f08c3bdfSopenharmony_ci#
6f08c3bdfSopenharmony_ci#  Copyright (c) International Business Machines  Corp., 2003
7f08c3bdfSopenharmony_ci#
8f08c3bdfSopenharmony_ci#  This program is free software;  you can redistribute it and/or modify
9f08c3bdfSopenharmony_ci#  it under the terms of the GNU General Public License as published by
10f08c3bdfSopenharmony_ci#  the Free Software Foundation; either version 2 of the License, or
11f08c3bdfSopenharmony_ci#  (at your option) any later version.
12f08c3bdfSopenharmony_ci#
13f08c3bdfSopenharmony_ci#  This program is distributed in the hope that it will be useful,
14f08c3bdfSopenharmony_ci#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
15f08c3bdfSopenharmony_ci#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
16f08c3bdfSopenharmony_ci#  the GNU General Public License for more details.
17f08c3bdfSopenharmony_ci#
18f08c3bdfSopenharmony_ci#  You should have received a copy of the GNU General Public License
19f08c3bdfSopenharmony_ci#  along with this program;  if not, write to the Free Software
20f08c3bdfSopenharmony_ci#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21f08c3bdfSopenharmony_ci#
22f08c3bdfSopenharmony_ci#  FILE        : autofs1.sh
23f08c3bdfSopenharmony_ci#  USAGE       : autofs1.sh <disk_partition>
24f08c3bdfSopenharmony_ci#
25f08c3bdfSopenharmony_ci#  DESCRIPTION : A script that will test autofs on Linux system.
26f08c3bdfSopenharmony_ci#  REQUIREMENTS:
27f08c3bdfSopenharmony_ci#                1) System with a floppy device with a floppy disk in it.
28f08c3bdfSopenharmony_ci#                2) A spare (scratch) disk partition of 100MB or larger.
29f08c3bdfSopenharmony_ci#
30f08c3bdfSopenharmony_ci#  HISTORY     :
31f08c3bdfSopenharmony_ci#      06/11/2003 Prakash Narayana (prakashn@us.ibm.com)
32f08c3bdfSopenharmony_ci#      08/01/2005 Michael Reed (mreed10@us.ibm.com)
33f08c3bdfSopenharmony_ci#      - Added an check to see if a directory exists
34f08c3bdfSopenharmony_ci#      - This prevents unnessary failures
35f08c3bdfSopenharmony_ci#      - Correction to an echo statement
36f08c3bdfSopenharmony_ci#      - Added an additional error message if a floppy disk is not present
37f08c3bdfSopenharmony_ci#
38f08c3bdfSopenharmony_ci#  CODE COVERAGE:
39f08c3bdfSopenharmony_ci#                41.46% - fs/autofs/dirhash.c
40f08c3bdfSopenharmony_ci#                33.33% - fs/autofs/init.c
41f08c3bdfSopenharmony_ci#                27.70% - fs/autofs/inode.c
42f08c3bdfSopenharmony_ci#                38.16% - fs/autofs/root.c
43f08c3bdfSopenharmony_ci#                 0.00% - fs/autofs/symlink.c
44f08c3bdfSopenharmony_ci#                43.40% - fs/autofs/waitq.c
45f08c3bdfSopenharmony_ci#
46f08c3bdfSopenharmony_ci##############################################################
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci
49f08c3bdfSopenharmony_ci##############################################################
50f08c3bdfSopenharmony_ci#
51f08c3bdfSopenharmony_ci# Make sure that uid=root is running this script.
52f08c3bdfSopenharmony_ci# Validate the command line argument as a block special device.
53f08c3bdfSopenharmony_ci# Make sure that autofs package has been installed.
54f08c3bdfSopenharmony_ci# Make sure that autofs module is built into the kernel or loaded.
55f08c3bdfSopenharmony_ci#
56f08c3bdfSopenharmony_ci##############################################################
57f08c3bdfSopenharmony_ci
58f08c3bdfSopenharmony_ciif [ $UID != 0 ]
59f08c3bdfSopenharmony_cithen
60f08c3bdfSopenharmony_ci	echo "FAILED: Must have root access to execute this script"
61f08c3bdfSopenharmony_ci	exit 1
62f08c3bdfSopenharmony_cifi
63f08c3bdfSopenharmony_ci
64f08c3bdfSopenharmony_ciif [ $# != 1 ]
65f08c3bdfSopenharmony_cithen
66f08c3bdfSopenharmony_ci	echo "FAILED: Usage $0 <disk_partition>"
67f08c3bdfSopenharmony_ci        echo "Example: $0 /dev/hdc1"
68f08c3bdfSopenharmony_ci	exit 1
69f08c3bdfSopenharmony_cielse
70f08c3bdfSopenharmony_ci	disk_partition=$1
71f08c3bdfSopenharmony_ci	if [ ! -b $disk_partition ]
72f08c3bdfSopenharmony_ci	then
73f08c3bdfSopenharmony_ci		echo "FAILED: Usage $0 <block special disk_partition>"
74f08c3bdfSopenharmony_ci		exit 1
75f08c3bdfSopenharmony_ci	fi
76f08c3bdfSopenharmony_ci	mkfs -t ext2 $disk_partition
77f08c3bdfSopenharmony_cifi
78f08c3bdfSopenharmony_ci
79f08c3bdfSopenharmony_cirpm -q -a | grep autofs
80f08c3bdfSopenharmony_ciif [ $? != 0 ]
81f08c3bdfSopenharmony_cithen
82f08c3bdfSopenharmony_ci	echo "FAILED: autofs package is not installed"
83f08c3bdfSopenharmony_ci	exit 1
84f08c3bdfSopenharmony_cifi
85f08c3bdfSopenharmony_ci
86f08c3bdfSopenharmony_cigrep autofs /proc/filesystems
87f08c3bdfSopenharmony_ciif [ $? != 0 ]
88f08c3bdfSopenharmony_cithen
89f08c3bdfSopenharmony_ci	echo "FAILED: autofs module is not built into the kernel or loaded"
90f08c3bdfSopenharmony_ci	exit 1
91f08c3bdfSopenharmony_cifi
92f08c3bdfSopenharmony_ci
93f08c3bdfSopenharmony_ci
94f08c3bdfSopenharmony_ci##############################################################
95f08c3bdfSopenharmony_ci#
96f08c3bdfSopenharmony_ci# Pick the floppy device name from /etc/fstab
97f08c3bdfSopenharmony_ci# Format (mkfs -t ext2) the floppy to ext2 file system
98f08c3bdfSopenharmony_ci# Create the /etc/auto.master
99f08c3bdfSopenharmony_ci# Create the /etc/auto.media
100f08c3bdfSopenharmony_ci# Create /AUTOFS directory.
101f08c3bdfSopenharmony_ci#
102f08c3bdfSopenharmony_ci##############################################################
103f08c3bdfSopenharmony_ci
104f08c3bdfSopenharmony_cifloppy_dev=`grep floppy /etc/fstab | awk '{print $1}'`
105f08c3bdfSopenharmony_ci
106f08c3bdfSopenharmony_ciecho "Found floppy device:$floppy_dev"
107f08c3bdfSopenharmony_ci
108f08c3bdfSopenharmony_ciif [ $floppy_dev != "" ]
109f08c3bdfSopenharmony_cithen
110f08c3bdfSopenharmony_ci	/sbin/mkfs -t ext2 $floppy_dev
111f08c3bdfSopenharmony_ci	if [ $? != 0 ]
112f08c3bdfSopenharmony_ci	then
113f08c3bdfSopenharmony_ci		echo "FAILED: mkfs -t ext2 $floppy_dev failed"
114f08c3bdfSopenharmony_ci		echo "Insert a disk into the floppy drive"
115f08c3bdfSopenharmony_ci		exit 1
116f08c3bdfSopenharmony_ci	fi
117f08c3bdfSopenharmony_cifi
118f08c3bdfSopenharmony_ci
119f08c3bdfSopenharmony_ciif [ ! -d /AUTOFS ]
120f08c3bdfSopenharmony_cithen
121f08c3bdfSopenharmony_ci	mkdir -m 777 /AUTOFS
122f08c3bdfSopenharmony_cifi
123f08c3bdfSopenharmony_ci
124f08c3bdfSopenharmony_ciecho "/AUTOFS/MEDIA	/etc/auto.media" > /etc/auto.master
125f08c3bdfSopenharmony_ciecho "floppy	-fstype=ext2	:$floppy_dev" > /etc/auto.media
126f08c3bdfSopenharmony_ci
127f08c3bdfSopenharmony_ci
128f08c3bdfSopenharmony_ci##############################################################
129f08c3bdfSopenharmony_ci#
130f08c3bdfSopenharmony_ci# Verify that "/etc/init.d/autofs start|restart|stop|status|reload"
131f08c3bdfSopenharmony_ci# command works.
132f08c3bdfSopenharmony_ci#
133f08c3bdfSopenharmony_ci# If fails, cleanup and exit.
134f08c3bdfSopenharmony_ci#
135f08c3bdfSopenharmony_ci##############################################################
136f08c3bdfSopenharmony_ci
137f08c3bdfSopenharmony_ci/etc/init.d/autofs start
138f08c3bdfSopenharmony_ciif [ $? != 0 ]
139f08c3bdfSopenharmony_cithen
140f08c3bdfSopenharmony_ci	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
141f08c3bdfSopenharmony_ci	echo "FAILED: "/etc/init.d/autofs start""
142f08c3bdfSopenharmony_ci	exit 1
143f08c3bdfSopenharmony_cifi
144f08c3bdfSopenharmony_ciecho "Resuming test, please wait..."
145f08c3bdfSopenharmony_cisleep 15
146f08c3bdfSopenharmony_ci
147f08c3bdfSopenharmony_ci/etc/init.d/autofs stop
148f08c3bdfSopenharmony_ciif [ $? != 0 ]
149f08c3bdfSopenharmony_cithen
150f08c3bdfSopenharmony_ci	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
151f08c3bdfSopenharmony_ci	echo "FAILED: "/etc/init.d/autofs stop""
152f08c3bdfSopenharmony_ci	exit 1
153f08c3bdfSopenharmony_cielse
154f08c3bdfSopenharmony_ci	/etc/init.d/autofs start
155f08c3bdfSopenharmony_cifi
156f08c3bdfSopenharmony_ciecho "Resuming test, please wait..."
157f08c3bdfSopenharmony_cisleep 15
158f08c3bdfSopenharmony_ci
159f08c3bdfSopenharmony_ci/etc/init.d/autofs restart
160f08c3bdfSopenharmony_ciif [ $? != 0 ]
161f08c3bdfSopenharmony_cithen
162f08c3bdfSopenharmony_ci	/etc/init.d/autofs stop
163f08c3bdfSopenharmony_ci	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
164f08c3bdfSopenharmony_ci	echo "FAILED: "/etc/init.d/autofs restart""
165f08c3bdfSopenharmony_ci	exit 1
166f08c3bdfSopenharmony_cifi
167f08c3bdfSopenharmony_ciecho "Resuming test, please wait..."
168f08c3bdfSopenharmony_cisleep 15
169f08c3bdfSopenharmony_ci
170f08c3bdfSopenharmony_ci/etc/init.d/autofs status
171f08c3bdfSopenharmony_ciif [ $? != 0 ]
172f08c3bdfSopenharmony_cithen
173f08c3bdfSopenharmony_ci	/etc/init.d/autofs stop
174f08c3bdfSopenharmony_ci	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
175f08c3bdfSopenharmony_ci	echo "FAILED: "/etc/init.d/autofs status""
176f08c3bdfSopenharmony_ci	exit 1
177f08c3bdfSopenharmony_cifi
178f08c3bdfSopenharmony_ci
179f08c3bdfSopenharmony_ci/etc/init.d/autofs reload
180f08c3bdfSopenharmony_ciif [ $? != 0 ]
181f08c3bdfSopenharmony_cithen
182f08c3bdfSopenharmony_ci	/etc/init.d/autofs stop
183f08c3bdfSopenharmony_ci	rm -rf /etc/auto.master /etc/auto.media /AUTOFS
184f08c3bdfSopenharmony_ci	echo "FAILED: "/etc/init.d/autofs reload""
185f08c3bdfSopenharmony_ci	exit 1
186f08c3bdfSopenharmony_cifi
187f08c3bdfSopenharmony_ci
188f08c3bdfSopenharmony_ci
189f08c3bdfSopenharmony_ci##############################################################
190f08c3bdfSopenharmony_ci#
191f08c3bdfSopenharmony_ci# Tryout some error code paths by:
192f08c3bdfSopenharmony_ci# (1) Write into automount directory
193f08c3bdfSopenharmony_ci# (2) Remove automount parent directory
194f08c3bdfSopenharmony_ci# (3) Automount the floppy disk
195f08c3bdfSopenharmony_ci# (4) Hit automounter timeout by sleep 60; then wakeup with error
196f08c3bdfSopenharmony_ci#     condition.
197f08c3bdfSopenharmony_ci#
198f08c3bdfSopenharmony_ci##############################################################
199f08c3bdfSopenharmony_ci
200f08c3bdfSopenharmony_ciecho "forcing error paths and conditions..."
201f08c3bdfSopenharmony_ci
202f08c3bdfSopenharmony_cimkdir /AUTOFS/MEDIA/mydir >/dev/null 2>&1
203f08c3bdfSopenharmony_cirm -rf /AUTOFS >/dev/null 2>&1
204f08c3bdfSopenharmony_ci
205f08c3bdfSopenharmony_cimkdir /AUTOFS/MEDIA/floppy/test
206f08c3bdfSopenharmony_cicp /etc/auto.master /etc/auto.media /AUTOFS/MEDIA/floppy/test
207f08c3bdfSopenharmony_cisync; sync
208f08c3bdfSopenharmony_ciecho "Resuming test, please wait..."
209f08c3bdfSopenharmony_cisleep 60
210f08c3bdfSopenharmony_cimkdir /AUTOFS/MEDIA/mydir >/dev/null 2>&1
211f08c3bdfSopenharmony_cirm -rf /AUTOFS >/dev/null 2>&1
212f08c3bdfSopenharmony_ci
213f08c3bdfSopenharmony_ci
214f08c3bdfSopenharmony_ci##############################################################
215f08c3bdfSopenharmony_ci#
216f08c3bdfSopenharmony_ci# Add an entry to the /etc/auto.master and reload.
217f08c3bdfSopenharmony_ci#
218f08c3bdfSopenharmony_ci##############################################################
219f08c3bdfSopenharmony_ci
220f08c3bdfSopenharmony_ciecho "/AUTOFS/DISK	/etc/auto.disk" >> /etc/auto.master
221f08c3bdfSopenharmony_ciecho "disk		-fstype=auto,rw,sync	:$disk_partition " > /etc/auto.disk
222f08c3bdfSopenharmony_ci/etc/init.d/autofs reload
223f08c3bdfSopenharmony_ciecho "Resuming test, please wait..."
224f08c3bdfSopenharmony_cisleep 30
225f08c3bdfSopenharmony_ci
226f08c3bdfSopenharmony_ci
227f08c3bdfSopenharmony_ci
228f08c3bdfSopenharmony_cimkdir /AUTOFS/DISK/disk/test
229f08c3bdfSopenharmony_cicp /etc/auto.master /etc/auto.media /AUTOFS/DISK/disk/test
230f08c3bdfSopenharmony_cisync; sync
231f08c3bdfSopenharmony_ciecho "Resuming test, please wait..."
232f08c3bdfSopenharmony_cisleep 60
233f08c3bdfSopenharmony_ci
234f08c3bdfSopenharmony_ci
235f08c3bdfSopenharmony_ciif [ -e  /AUTOFS/DISK/disk/test ]; then
236f08c3bdfSopenharmony_ci  cd /AUTOFS/DISK/disk/test
237f08c3bdfSopenharmony_ci  umount /AUTOFS/DISK/disk/ >/dev/null 2>&1
238f08c3bdfSopenharmony_ci  if [ $? = 0 ]
239f08c3bdfSopenharmony_ci    then
240f08c3bdfSopenharmony_ci	/etc/init.d/autofs stop
241f08c3bdfSopenharmony_ci	rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
242f08c3bdfSopenharmony_ci	echo "FAILED: unmounted a busy file system!"
243f08c3bdfSopenharmony_ci	exit 1
244f08c3bdfSopenharmony_ci  fi
245f08c3bdfSopenharmony_ci  cd
246f08c3bdfSopenharmony_ci  umount /AUTOFS/DISK/disk/
247f08c3bdfSopenharmony_ciif [ $? != 0 ]
248f08c3bdfSopenharmony_ci  then
249f08c3bdfSopenharmony_ci	/etc/init.d/autofs stop
250f08c3bdfSopenharmony_ci	rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
251f08c3bdfSopenharmony_ci	echo "FAILED: Could not unmount automounted file system"
252f08c3bdfSopenharmony_ci	exit 1
253f08c3bdfSopenharmony_ci  fi
254f08c3bdfSopenharmony_cifi
255f08c3bdfSopenharmony_ci#
256f08c3bdfSopenharmony_ci# Mount the disk partition somewhere else and then reference automount
257f08c3bdfSopenharmony_ci# point for disk partition.
258f08c3bdfSopenharmony_ci#
259f08c3bdfSopenharmony_cimount -t ext2 $disk_partition /mnt/
260f08c3bdfSopenharmony_cils -l /AUTOFS/DISK/disk
261f08c3bdfSopenharmony_ciumount /mnt
262f08c3bdfSopenharmony_ci
263f08c3bdfSopenharmony_ci
264f08c3bdfSopenharmony_ci#######################################################
265f08c3bdfSopenharmony_ci#
266f08c3bdfSopenharmony_ci# Just before exit, stop autofs and cleanup.
267f08c3bdfSopenharmony_ci#
268f08c3bdfSopenharmony_ci#######################################################
269f08c3bdfSopenharmony_ci
270f08c3bdfSopenharmony_ci/etc/init.d/autofs stop
271f08c3bdfSopenharmony_cirm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS
272f08c3bdfSopenharmony_ciecho "PASSED: $0 passed!"
273f08c3bdfSopenharmony_ciexit 0
274