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