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 : autofs4.sh 23f08c3bdfSopenharmony_ci# USAGE : autofs4.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# 33f08c3bdfSopenharmony_ci# CODE COVERAGE: 26.8% - fs/autofs4 (Total Coverage) 34f08c3bdfSopenharmony_ci# 35f08c3bdfSopenharmony_ci# 24.1% - fs/autofs4/expire.c 36f08c3bdfSopenharmony_ci# 33.3% - fs/autofs4/init.c 37f08c3bdfSopenharmony_ci# 24.0% - fs/autofs4/inode.c 38f08c3bdfSopenharmony_ci# 29.9% - fs/autofs4/root.c 39f08c3bdfSopenharmony_ci# 0.0% - fs/autofs4/symlink.c 40f08c3bdfSopenharmony_ci# 29.1% - fs/autofs4/waitq.c 41f08c3bdfSopenharmony_ci# 42f08c3bdfSopenharmony_ci############################################################## 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci############################################################## 46f08c3bdfSopenharmony_ci# 47f08c3bdfSopenharmony_ci# Make sure that uid=root is running this script. 48f08c3bdfSopenharmony_ci# Validate the command line argument as a block special device. 49f08c3bdfSopenharmony_ci# Make sure that autofs package has been installed. 50f08c3bdfSopenharmony_ci# Make sure that autofs module is built into the kernel or loaded. 51f08c3bdfSopenharmony_ci# 52f08c3bdfSopenharmony_ci############################################################## 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ciif [ $UID != 0 ] 55f08c3bdfSopenharmony_cithen 56f08c3bdfSopenharmony_ci echo "FAILED: Must have root access to execute this script" 57f08c3bdfSopenharmony_ci exit 1 58f08c3bdfSopenharmony_cifi 59f08c3bdfSopenharmony_ci 60f08c3bdfSopenharmony_ciif [ $# != 1 ] 61f08c3bdfSopenharmony_cithen 62f08c3bdfSopenharmony_ci echo "FAILED: Usage $0 <disk_partition>" 63f08c3bdfSopenharmony_ci exit 1 64f08c3bdfSopenharmony_cielse 65f08c3bdfSopenharmony_ci disk_partition=$1 66f08c3bdfSopenharmony_ci if [ ! -b $disk_partition ] 67f08c3bdfSopenharmony_ci then 68f08c3bdfSopenharmony_ci echo "FAILED: Usage $0 <block special disk_partition>" 69f08c3bdfSopenharmony_ci exit 1 70f08c3bdfSopenharmony_ci fi 71f08c3bdfSopenharmony_ci mkfs -t ext2 $disk_partition >/dev/null 2>&1 72f08c3bdfSopenharmony_cifi 73f08c3bdfSopenharmony_ci 74f08c3bdfSopenharmony_cirpm -q -a | grep autofs >/dev/null 2>&1 75f08c3bdfSopenharmony_ciif [ $? != 0 ] 76f08c3bdfSopenharmony_cithen 77f08c3bdfSopenharmony_ci echo "FAILED: autofs package is not installed" 78f08c3bdfSopenharmony_ci exit 1 79f08c3bdfSopenharmony_cifi 80f08c3bdfSopenharmony_ci 81f08c3bdfSopenharmony_cigrep autofs /proc/filesystems >/dev/null 2>&1 82f08c3bdfSopenharmony_ciif [ $? != 0 ] 83f08c3bdfSopenharmony_cithen 84f08c3bdfSopenharmony_ci echo "FAILED: autofs module is not built into the kernel or loaded" 85f08c3bdfSopenharmony_ci exit 1 86f08c3bdfSopenharmony_cifi 87f08c3bdfSopenharmony_ci 88f08c3bdfSopenharmony_ci 89f08c3bdfSopenharmony_ci############################################################## 90f08c3bdfSopenharmony_ci# 91f08c3bdfSopenharmony_ci# Pick the floppy device name from /etc/fstab 92f08c3bdfSopenharmony_ci# Format (mkfs -t ext2) the floppy to ext2 file system 93f08c3bdfSopenharmony_ci# Create the /etc/auto.master 94f08c3bdfSopenharmony_ci# Create the /etc/auto.media 95f08c3bdfSopenharmony_ci# Create /AUTOFS directory. 96f08c3bdfSopenharmony_ci# 97f08c3bdfSopenharmony_ci############################################################## 98f08c3bdfSopenharmony_ci 99f08c3bdfSopenharmony_cifloppy_dev=`grep floppy /etc/fstab | awk '{print $1}'` 100f08c3bdfSopenharmony_ci 101f08c3bdfSopenharmony_ciif [ $floppy_dev != "" ] 102f08c3bdfSopenharmony_cithen 103f08c3bdfSopenharmony_ci /sbin/mkfs -t ext2 $floppy_dev >/dev/null 2>&1 104f08c3bdfSopenharmony_ci if [ $? != 0 ] 105f08c3bdfSopenharmony_ci then 106f08c3bdfSopenharmony_ci echo "FAILED: mkfs -t ext2 $floppy_dev failed" 107f08c3bdfSopenharmony_ci exit 1 108f08c3bdfSopenharmony_ci fi 109f08c3bdfSopenharmony_cifi 110f08c3bdfSopenharmony_ci 111f08c3bdfSopenharmony_ciif [ ! -d /AUTOFS ] 112f08c3bdfSopenharmony_cithen 113f08c3bdfSopenharmony_ci mkdir -m 755 /AUTOFS 114f08c3bdfSopenharmony_cifi 115f08c3bdfSopenharmony_ci 116f08c3bdfSopenharmony_ciecho "/AUTOFS/MEDIA /etc/auto.media " > /etc/auto.master 117f08c3bdfSopenharmony_ciecho "floppy -fstype=ext2 :$floppy_dev" > /etc/auto.media 118f08c3bdfSopenharmony_ci 119f08c3bdfSopenharmony_ci 120f08c3bdfSopenharmony_ci############################################################## 121f08c3bdfSopenharmony_ci# 122f08c3bdfSopenharmony_ci# Verify that "/etc/init.d/autofs start|restart|stop|status|reload" 123f08c3bdfSopenharmony_ci# command works. 124f08c3bdfSopenharmony_ci# 125f08c3bdfSopenharmony_ci# If fails, cleanup and exit. 126f08c3bdfSopenharmony_ci# 127f08c3bdfSopenharmony_ci############################################################## 128f08c3bdfSopenharmony_ci 129f08c3bdfSopenharmony_ci/etc/init.d/autofs start >/dev/null 2>&1 130f08c3bdfSopenharmony_ciif [ $? != 0 ] 131f08c3bdfSopenharmony_cithen 132f08c3bdfSopenharmony_ci rm -rf /etc/auto.master /etc/auto.media /AUTOFS 133f08c3bdfSopenharmony_ci echo "FAILED: "/etc/init.d/autofs start"" 134f08c3bdfSopenharmony_ci exit 1 135f08c3bdfSopenharmony_cifi 136f08c3bdfSopenharmony_ciecho "Resuming test, please wait..." 137f08c3bdfSopenharmony_cisleep 15 138f08c3bdfSopenharmony_ci 139f08c3bdfSopenharmony_ci/etc/init.d/autofs stop >/dev/null 2>&1 140f08c3bdfSopenharmony_ciif [ $? != 0 ] 141f08c3bdfSopenharmony_cithen 142f08c3bdfSopenharmony_ci rm -rf /etc/auto.master /etc/auto.media /AUTOFS 143f08c3bdfSopenharmony_ci echo "FAILED: "/etc/init.d/autofs stop"" 144f08c3bdfSopenharmony_ci exit 1 145f08c3bdfSopenharmony_cielse 146f08c3bdfSopenharmony_ci /etc/init.d/autofs start >/dev/null 2>&1 147f08c3bdfSopenharmony_cifi 148f08c3bdfSopenharmony_cisleep 15 149f08c3bdfSopenharmony_ci 150f08c3bdfSopenharmony_ci/etc/init.d/autofs restart >/dev/null 2>&1 151f08c3bdfSopenharmony_ciif [ $? != 0 ] 152f08c3bdfSopenharmony_cithen 153f08c3bdfSopenharmony_ci /etc/init.d/autofs stop >/dev/null 2>&1 154f08c3bdfSopenharmony_ci rm -rf /etc/auto.master /etc/auto.media /AUTOFS 155f08c3bdfSopenharmony_ci echo "FAILED: "/etc/init.d/autofs restart"" 156f08c3bdfSopenharmony_ci exit 1 157f08c3bdfSopenharmony_cifi 158f08c3bdfSopenharmony_ciecho "Resuming test, please wait..." 159f08c3bdfSopenharmony_cisleep 15 160f08c3bdfSopenharmony_ci 161f08c3bdfSopenharmony_ci/etc/init.d/autofs status >/dev/null 2>&1 162f08c3bdfSopenharmony_ciif [ $? != 0 ] 163f08c3bdfSopenharmony_cithen 164f08c3bdfSopenharmony_ci /etc/init.d/autofs stop >/dev/null 2>&1 165f08c3bdfSopenharmony_ci rm -rf /etc/auto.master /etc/auto.media /AUTOFS 166f08c3bdfSopenharmony_ci echo "FAILED: "/etc/init.d/autofs status"" 167f08c3bdfSopenharmony_ci exit 1 168f08c3bdfSopenharmony_cifi 169f08c3bdfSopenharmony_ci 170f08c3bdfSopenharmony_ci/etc/init.d/autofs reload >/dev/null 2>&1 171f08c3bdfSopenharmony_ciif [ $? != 0 ] 172f08c3bdfSopenharmony_cithen 173f08c3bdfSopenharmony_ci /etc/init.d/autofs stop >/dev/null 2>&1 174f08c3bdfSopenharmony_ci rm -rf /etc/auto.master /etc/auto.media /AUTOFS 175f08c3bdfSopenharmony_ci echo "FAILED: "/etc/init.d/autofs reload"" 176f08c3bdfSopenharmony_ci exit 1 177f08c3bdfSopenharmony_cifi 178f08c3bdfSopenharmony_ci 179f08c3bdfSopenharmony_ci 180f08c3bdfSopenharmony_ci############################################################## 181f08c3bdfSopenharmony_ci# 182f08c3bdfSopenharmony_ci# Tryout some error code paths by: 183f08c3bdfSopenharmony_ci# (1) Write into automount directory 184f08c3bdfSopenharmony_ci# (2) Remove automount parent directory 185f08c3bdfSopenharmony_ci# (3) Automount the floppy disk 186f08c3bdfSopenharmony_ci# (4) Hit automounter timeout by sleep 60; then wakeup with error 187f08c3bdfSopenharmony_ci# condition. 188f08c3bdfSopenharmony_ci# 189f08c3bdfSopenharmony_ci############################################################## 190f08c3bdfSopenharmony_ci 191f08c3bdfSopenharmony_cimkdir /AUTOFS/MEDIA/mydir >/dev/null 2>&1 192f08c3bdfSopenharmony_cirm -rf /AUTOFS >/dev/null 2>&1 193f08c3bdfSopenharmony_ci 194f08c3bdfSopenharmony_cimkdir /AUTOFS/MEDIA/floppy/test 195f08c3bdfSopenharmony_cicp /etc/auto.master /etc/auto.media /AUTOFS/MEDIA/floppy/test 196f08c3bdfSopenharmony_cisync; sync 197f08c3bdfSopenharmony_ciecho "Resuming test, please wait..." 198f08c3bdfSopenharmony_cisleep 60 199f08c3bdfSopenharmony_cimkdir /AUTOFS/MEDIA/mydir >/dev/null 2>&1 200f08c3bdfSopenharmony_cirm -rf /AUTOFS >/dev/null 2>&1 201f08c3bdfSopenharmony_ci 202f08c3bdfSopenharmony_ci 203f08c3bdfSopenharmony_ci############################################################## 204f08c3bdfSopenharmony_ci# 205f08c3bdfSopenharmony_ci# Add an entry to the /etc/auto.master and reload. 206f08c3bdfSopenharmony_ci# 207f08c3bdfSopenharmony_ci############################################################## 208f08c3bdfSopenharmony_ci 209f08c3bdfSopenharmony_ciecho "/AUTOFS/DISK /etc/auto.disk " >> /etc/auto.master 210f08c3bdfSopenharmony_ciecho "disk -fstype=ext2 :$disk_partition " > /etc/auto.disk 211f08c3bdfSopenharmony_ci/etc/init.d/autofs reload >/dev/null 2>&1 212f08c3bdfSopenharmony_ciecho "Resuming test, please wait..." 213f08c3bdfSopenharmony_cisleep 30 214f08c3bdfSopenharmony_ci 215f08c3bdfSopenharmony_cimkdir /AUTOFS/DISK/disk/test 216f08c3bdfSopenharmony_cicp /etc/auto.master /etc/auto.media /AUTOFS/DISK/disk/test 217f08c3bdfSopenharmony_cisync; sync 218f08c3bdfSopenharmony_ciecho "Resuming test, please wait..." 219f08c3bdfSopenharmony_cisleep 60 220f08c3bdfSopenharmony_ci 221f08c3bdfSopenharmony_cicd /AUTOFS/DISK/disk/test 222f08c3bdfSopenharmony_ciumount /AUTOFS/DISK/disk/ >/dev/null 2>&1 223f08c3bdfSopenharmony_ciif [ $? = 0 ] 224f08c3bdfSopenharmony_cithen 225f08c3bdfSopenharmony_ci /etc/init.d/autofs stop >/dev/null 2>&1 226f08c3bdfSopenharmony_ci rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS 227f08c3bdfSopenharmony_ci echo "FAILED: unmounted a busy file system!" 228f08c3bdfSopenharmony_ci exit 1 229f08c3bdfSopenharmony_cifi 230f08c3bdfSopenharmony_cicd 231f08c3bdfSopenharmony_ci 232f08c3bdfSopenharmony_ciumount /AUTOFS/DISK/disk/ >/dev/null 2>&1 233f08c3bdfSopenharmony_ciif [ $? != 0 ] 234f08c3bdfSopenharmony_cithen 235f08c3bdfSopenharmony_ci /etc/init.d/autofs stop >/dev/null 2>&1 236f08c3bdfSopenharmony_ci rm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS 237f08c3bdfSopenharmony_ci echo "FAILED: Could not unmount automounted file system" 238f08c3bdfSopenharmony_ci exit 1 239f08c3bdfSopenharmony_cifi 240f08c3bdfSopenharmony_ci 241f08c3bdfSopenharmony_ci# 242f08c3bdfSopenharmony_ci# Mount the disk partition somewhere else and then reference automount 243f08c3bdfSopenharmony_ci# point for disk partition. 244f08c3bdfSopenharmony_ci# 245f08c3bdfSopenharmony_cimount -t ext2 $disk_partition /mnt/ 246f08c3bdfSopenharmony_cils -l /AUTOFS/DISK/disk 247f08c3bdfSopenharmony_ciumount /mnt 248f08c3bdfSopenharmony_ci 249f08c3bdfSopenharmony_ci 250f08c3bdfSopenharmony_ci####################################################### 251f08c3bdfSopenharmony_ci# 252f08c3bdfSopenharmony_ci# Just before exit, stop autofs and cleanup. 253f08c3bdfSopenharmony_ci# 254f08c3bdfSopenharmony_ci####################################################### 255f08c3bdfSopenharmony_ci 256f08c3bdfSopenharmony_ci/etc/init.d/autofs stop >/dev/null 2>&1 257f08c3bdfSopenharmony_cirm -rf /etc/auto.master /etc/auto.media /etc/auto.disk /AUTOFS 258f08c3bdfSopenharmony_ciecho "PASSED: $0 passed!" 259f08c3bdfSopenharmony_ciexit 0 260