| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 4 |
# or more contributor license agreements. See the NOTICE file |
| 5 |
# distributed with this work for additional information |
| 6 |
# regarding copyright ownership. The ASF licenses this file |
| 7 |
# to you under the Apache License, Version 2.0 (the |
| 8 |
# "License"); you may not use this file except in compliance |
| 9 |
# with the License. You may obtain a copy of the License at |
| 10 |
# |
| 11 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
# |
| 13 |
# Unless required by applicable law or agreed to in writing, |
| 14 |
# software distributed under the License is distributed on an |
| 15 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 |
# KIND, either express or implied. See the License for the |
| 17 |
# specific language governing permissions and limitations |
| 18 |
# under the License. |
| 19 |
|
| 20 |
set -x |
| 21 |
|
| 22 |
if [ -z "$1" ]; then |
| 23 |
echo "Missing parameter: volume name" |
| 24 |
exit 1 |
| 25 |
fi |
| 26 |
|
| 27 |
if [ -z "$2" ]; then |
| 28 |
echo "Missing parameter: RAMdisk config file" |
| 29 |
exit 1 |
| 30 |
fi |
| 31 |
|
| 32 |
volume="/Volumes/$1" |
| 33 |
ramconf="$2" |
| 34 |
|
| 35 |
if [ ! -f "${ramconf}" ]; then |
| 36 |
mount | grep "^/dev/disk[0-9][0-9]* on ${volume} (hfs" || { |
| 37 |
echo "Not mounted: ${volume}" |
| 38 |
exit 0 |
| 39 |
} |
| 40 |
echo "Missing RAMdisk config file: ${ramconf}" |
| 41 |
exit 1 |
| 42 |
fi |
| 43 |
|
| 44 |
if [ ! -d "${volume}" ]; then |
| 45 |
echo "Mount point missing: ${volume}" |
| 46 |
exit 1 |
| 47 |
fi |
| 48 |
|
| 49 |
device=$(cat "${ramconf}") |
| 50 |
devfmt=$(echo "${device}" | grep "^/dev/disk[0-9][0-9]*$") |
| 51 |
if [ "${device}" != "${devfmt}" ]; then |
| 52 |
echo "Invalid device name: ${device}" |
| 53 |
exit 1 |
| 54 |
fi |
| 55 |
|
| 56 |
mount | grep "^${device} on ${volume} (hfs" >/dev/null && { |
| 57 |
set -e |
| 58 |
rm "${ramconf}" |
| 59 |
hdiutil detach "${device}" -force |
| 60 |
} |
| 61 |
|
| 62 |
exit 0 |