yaberauneya | 192b746 | 2010-02-02 08:23:15 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # A safe wrapper around rm(1) to avoid cleaning out folks' rootfs's or build |
| 4 | # machines by accident. |
| 5 | # |
| 6 | # Copyright (C) 2010, Cisco Systems Inc. |
| 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 the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License along |
| 19 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | # |
| 22 | # Feel free to use this in your standard builds, or just leave it be (it has |
| 23 | # been added to the build tests that should be run before each release to avoid |
| 24 | # build regressions). |
| 25 | # |
Ngie Cooper | 8967f96 | 2017-02-13 22:06:24 -0800 | [diff] [blame] | 26 | # Ngie Cooper, February 2010 |
yaberauneya | 192b746 | 2010-02-02 08:23:15 +0000 | [diff] [blame] | 27 | # |
| 28 | |
| 29 | . "${0%/*}/lib/file_functions.sh" |
| 30 | |
| 31 | opts= |
| 32 | opts_parse_done=0 |
| 33 | |
| 34 | set -e |
| 35 | |
| 36 | while [ $# -gt 0 ] ; do |
| 37 | |
| 38 | if [ $opts_parse_done -eq 0 ] ; then |
| 39 | |
| 40 | case "$1" in |
| 41 | -*) |
| 42 | [ "x$1" = "x--" ] && opts_parse_done=1 |
| 43 | # None of the options to rm(1) are keyed. |
| 44 | opts="$opts $1" |
| 45 | ;; |
| 46 | *) |
| 47 | opts_parse_done=1 |
| 48 | ;; |
| 49 | esac |
| 50 | |
| 51 | fi |
| 52 | |
| 53 | if [ $opts_parse_done -eq 1 ] ; then |
| 54 | |
| 55 | abspath_file=$(_abspath "$1") |
| 56 | |
| 57 | if [ "x$abspath_file" = "x/" ] ; then |
| 58 | |
| 59 | cat <<EOF >&2 |
| 60 | ${0##*/}: ERROR : not removing \`$1' to avoid removing root directory\! |
| 61 | EOF |
| 62 | false |
| 63 | |
| 64 | else |
| 65 | |
| 66 | if [ "x${SIMULATE_RM:-1}" != x1 ] ; then |
| 67 | rm ${opts:--f} "$abspath_file" |
| 68 | fi |
| 69 | |
| 70 | fi |
| 71 | |
| 72 | fi |
| 73 | |
| 74 | shift |
| 75 | |
| 76 | done |