added Vector_zeroEnd() function
[util-vserver.git] / util-vserver / scripts / vprocunhide
1 #!/bin/bash
2 #
3 # Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 #  
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
8 #  
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #  
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
20 test -e "$UTIL_VSERVER_VARS" || {
21     echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
22     exit 1
23 }
24 . "$UTIL_VSERVER_VARS"
25 . "$_LIB_FUNCTIONS"
26
27 function showHelp()
28 {
29     echo $\
30 "Usage: vprocunhide
31
32 Return values:
33     0  ...  no errors
34     1  ...  configuration error
35     2  ...  some files where changes but there occured errors on other ones
36     3  ...  operation failed on every file
37
38 Report bugs to <$PACKAGE_BUGREPORT>."
39     exit 0
40 }
41
42 function showVersion()
43 {
44     echo \
45 $"vprocunhide $PACKAGE_VERSION -- unhides /proc entries
46 This program is part of $PACKAGE_STRING
47
48 Copyright (C) 2004 Enrico Scholz
49 This program is free software; you may redistribute it under the terms of
50 the GNU General Public License.  This program has absolutely no warranty."
51     exit 0
52 }
53
54
55 while test "$1"; do
56     case "$1" in
57         --help)         showHelp;;
58         --version)      showVersion;;
59     esac
60 done
61
62 findFile UNHIDEFILE \
63     "$CONFDIR"/.defaults/apps/vprocunhide/files \
64     "$PKGLIBDEFAULTDIR"/vprocunhide-files
65
66 ok=1
67 passed=
68 while read filename; do
69     params=()
70
71     case "$filename" in
72         (\#*)   continue;;
73         (-*)    params=( --admin         --hide ); filename=${filename#-};;
74         (~*)    params=( --admin --watch --hide ); filename=${filename#~};;
75         (:*)    params=(         --watch --hide ); filename=${filename#:};;
76         (!*)    params=(                 --hide ); filename=${filename#!};;
77         (+*)    params=(                --!hide ); filename=${filename#+};;
78         (*)     params=(                --!hide );;
79     esac
80         
81     case "$filename" in
82         (*/)    params=( "${params[@]}" -R );;
83         (*)     ;;
84     esac
85
86     set -- $filename
87     test -e "$1" || continue
88     
89     $_SETATTR -x "${params[@]}" "$@" && passed=1 || ok=
90 done <"$UNHIDEFILE"
91
92 test "$ok"     && exit 0 || \
93 test "$passed" && exit 2 || \
94 exit 3