-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindSharedFiles
More file actions
executable file
·185 lines (140 loc) · 4.72 KB
/
Copy pathfindSharedFiles
File metadata and controls
executable file
·185 lines (140 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
#
# findSharedFiles.sh
# Rasmus Ory Nielsen, 2002-10-05
# ron #at# ron #dot# dk
#
#------------------------------------------------------------------------------
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#------------------------------------------------------------------------------
#
# Version 0.1
#
# I have made this little bash script that finds files shared between different
# spells (because this is a bad thing).
# Example: You install spell A and spell B. A and B both install file
# /path/foo.
# When you dispel either of them, the other spell is possibly broken.
#
# The script is a bit slow, depending on the number of installed spells. On my
# workstation with gnome2 and kde it takes about 3 minutes to run (Athlon 800).
# I know it can be done smarter, but it was the easiest way to get the job
# done. So feel free to make a better algorithm.
#
# On my machine it gives me a total of 493 shared files. The major part of
# them is docs/manuals, but there's still a bunch of files that could give
# problems (if they not allready do).
#
# Sample output (grepped with grep '/bin/'):
# /bin/groups:shadow
# /bin/groups:sh-utils
# /bin/kill:util-linux
# /bin/kill:procps
# /usr/bin/c++filt:binutils
# /usr/bin/c++filt:gcc
# /usr/bin/pspell-config:aspell
# /usr/bin/pspell-config:pspell
# /usr/bin/uptime:sh-utils
# /usr/bin/uptime:procps
# /usr/bin/xdvi:xdvi
# /usr/bin/xdvi:teTeX
#
#------------------------------------------------------------------------------
# Files
installedFiles=/tmp/installedFiles.txt
installedFilesRaw=/tmp/installedFilesRaw.txt
noDuplicatesFile=/tmp/noDuplicatesFile.txt
# Read in the config file
source /etc/sorcery/config
# How to use the thing
function usage() {
cat <<EOF
Usage : findSharedFiles.sh [OPTION]
Create a list of installed files that are shared between different spells.
-h, --help print this help page
-n, --nice print a nice header before each shared file
-c, --compact print all spells for one file in same lines
The output is lines on the form:
/path/to/file:spell
Example:
/bin/kill:util-linux
/bin/kill:procps
It tells us that both util-linux AND procps have installed the file /bin/kill.
Output is sent to STDOUT.
EOF
}
# Parse command line arguments
parseArguments() {
let numShift=0;
# loop through remaining arguments
while true; do
case $1 in
-h|--help) usage; exit;;
-n|--nice) NICE="y"; let numShift++; shift 1;;
-c|--compact) COMPACT="y"; let numShift++; shift 1;;
*) return $numShift;;
esac
done
}
# Make lists of all installed files
findInstalledFiles() {
# get installed spells
SPELLS=$(gaze installed | cut -d: -f1)
# remove files if they exist
[ -e $installedFiles ] && rm $installedFiles
[ -e $installedFilesRaw ] && rm $installedFilesRaw
# loop through the spell list
for spell in $SPELLS; do
# print all installed files and directories
gaze install $spell >> $installedFilesRaw
# print all installed files (and directories) on the form 'file:spell'
for line in $(gaze install $spell); do
echo "${line}:${spell}" >> $installedFiles
done
done
}
# Remove duplicate lines
removeDuplicates() {
# find duplicates (both files and directories) and remove them
cat $installedFilesRaw | sort | uniq -d > $noDuplicatesFile
}
# Print the lines with shared files to STDOUT
printSharedFiles() {
# read duplicates into an array
noDuplicatesFile=( $(cat "$noDuplicatesFile" | tr '\n' ' ') )
# loop through the array
for line in ${noDuplicatesFile[@]}; do
# skip this line if it is a directory
[[ -d $line ]] && continue
# print the spell names which installs this file
if [[ -n "$NICE" ]] && [[ "$NICE" == "y" ]]; then
echo -e "${BOLD}Shared file: ${FILE_COLOR}$line${DEFAULT_COLOR}"
fi
if [[ $COMPACT == y ]]; then
echo "$line: $(grep "^$line:" $installedFiles |cut -d: -f2 |tr \\n ' ')"
else
grep "^$line:" $installedFiles
fi
done
}
# Do the thing
parseArguments $*
findInstalledFiles
removeDuplicates
printSharedFiles