[early] Improved init script to not activate mdadm and lvm volumes if {lvm,mdadm...
[opensde-nopast.git] / bin / sde-list-files
blobd73dc0e7f3ef184795c7e9037d0c87e572c7c343
1 #!/bin/sh
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: bin/sde-list-files
6 # Copyright (C) 2007 - 2008 The OpenSDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- SDE-COPYRIGHT-NOTE-END ---
16 # This script returns a list of locations in SDEROOT relative form
19 [ -n "$SDEROOT" ] ||
20 export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
22 . $SDEROOT/lib/libsde.in
24 list_usage() {
25 local progname=${0##*/}
26 cat <<EOT
27 Usage: $progname [--absolute] [--roots] [FILES...]
28 EOT
31 shortopts='a'
32 longopts='roots,absolute'
33 options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
34 if [ $? -ne 0 ]; then
35 list_usage
36 exit -1
39 # load new arguments list
40 eval set -- "$options"
42 show_roots=
43 show_absolute_path=
45 while [ $# -gt 0 ]; do
46 case "$1" in
47 --roots) show_roots=1 ;;
48 -a|--absolute) show_absolute_path=1 ;;
50 --) shift; break ;;
51 *) echo_abort 1 "Unknown argument '$1', aborting."
52 esac
53 shift
54 done
56 print_error() { echo "$@" >&2; }
58 # prints an absolute path $SDEROOT relative if wanted
59 print_file() {
60 local file="$1"
62 if [ "$file" = "$SDEROOT" ]; then
63 [ -n "$show_absolute_path" ] || file="."
64 else
65 [ -n "$show_absolute_path" ] || file="${file#$SDEROOT/}"
68 echo "$file"
71 # prints a roota relative path
72 print_file_root() {
73 local file="$1" root="$2" # $file arrives relative
75 if [ "$root" = "." -a -n "$show_absolute_path" ]; then
76 root="$SDEROOT"
79 echo "$root $file"
82 for x; do
84 if [ "$x" = "." ]; then
85 # $PWD, explicitly
86 y="$PWD"
87 elif [ -e "$PWD/$x" ]; then
88 # $PWD relative
89 y="$PWD/$x"
90 elif [ "${x:0:1}" = "/" -a -e "$x" ]; then
91 # absolute
92 y="$x"
93 elif [ -e "$SDEROOT/package"/*/"$x" ]; then
94 # package name
95 y=$( echo "$SDEROOT/package"/*/"$x" )
96 elif [ -e "$SDEROOT/target/$x" ]; then
97 # target name
98 y="$SDEROOT/target/$x"
99 elif [ -e "$SDEROOT/$x" ]; then
100 # $SDEROOT relative
101 y="$SDEROOT/$x"
104 # canonicalize
105 [ -z "$y" ] || y=$( readlink -f "$y" )
107 # analyse
108 if [ -z "$y" ]; then
109 # missing
110 print_error "$x: not found."
111 elif [ "$y" = "$SDEROOT" ]; then
112 # uh, the root itself
113 if [ -n "$show_roots" ]; then
114 print_file_root "." "."
115 else
116 print_file "$SDEROOT"
118 elif ! expr "$y" : "$SDEROOT/*" > /dev/null; then
119 # missing
120 print_error "$x: outside the tree."
121 elif [ -n "$show_roots" ]; then
122 # detect the right VCS roots and split the output accordingly
123 file="${y#$SDEROOT/}"
124 root=.
125 case "$file" in
126 target/*) # targets may be their own svn or git repository
127 root=$( echo "$file" | cut -d/ -f'1,2' )
128 [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root=.
130 package) # package is an standalone git repo
131 root="package" file="." ;;
132 package/*) # each package/* may be it's own svn or git repo
133 root=$( echo "$file" | cut -d/ -f'1,2' )
134 [ -e "$SDEROOT/$root/.svn" -o -e "$SDEROOT/$root/.git" ] || root=package
136 esac
138 # trim filename to be $root relative
139 case "$root" in
140 .) ;;
141 $file) file=. ;;
142 *) file="${file#$root/}"
143 esac
145 print_file_root "$file" "$root"
146 else
147 # just output the list
148 print_file "$y"
150 done