Skip to content

Commit 918a988

Browse files
committed
tool to install file magic on a unix system
1 parent 9dd28a0 commit 918a988

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ perl/*.inl
4747
*.out
4848
*.snm
4949
*.toc
50+
latex/xdi.log
51+
latex/xdi.pdf
5052
doc/Poster_XAFS15/XDI_Poster.log

install_magic

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
##################################################
3+
## install magic for recognizing XDI files into
4+
## system magic file
5+
##################################################
6+
## this must be run as root/sudo
7+
##################################################
8+
9+
10+
showhelp () {
11+
echo "
12+
install_magic: append file magic for XDI file to system magic file
13+
14+
install_magic [filename] [-h]
15+
filename specify location of system magic file (default=/etc/magic)
16+
-h show this help
17+
"
18+
}
19+
20+
## ======== identify system file =========================
21+
system_file=/etc/magic
22+
if [ $1 ]; then
23+
system_file=$1
24+
fi
25+
if [ "$system_file" = '-h' ]; then
26+
showhelp
27+
exit 0
28+
fi
29+
tempfile=./system.magic
30+
31+
## ======== sanity checking ==============================
32+
if [ `whoami` != 'root' ]; then
33+
echo "install_magic: this script must be run as root"
34+
exit 0
35+
fi
36+
37+
if [ ! -e $system_file ]; then
38+
echo "install_magic: magic file not found at '$system_file'"
39+
exit 0
40+
fi
41+
42+
## ======== append XDi magic to system file ==============
43+
cp $system_file $tempfile # make a copy of the system magic file
44+
sed -i "/# ----- XDI/,/# ----- XDI/ d" $tempfile # remove any previous definition of an XDI file
45+
cat $tempfile magic > $system_file # concatinate system file with XDI definition
46+
rm $tempfile # remove copy of old system file

magic

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
#----------------------------------------------------------------------------------
2-
# file(1) magic for XAS Data Interchange (XDI) files
3-
#
4-
# Installation: append this file to the end of /etc/magic, or see
5-
# `man 1 file' for details of the file magic system
6-
# on your computer
7-
#
8-
# ----- XDI files
1+
# ----- XDI files: file(1) magic for XAS Data Interchange (XDI) files
92
#
103
0 string #\ XDI/ XAS Data Interchange file
114
>&0 regex [0-9.]+ -- XDI specification %s
5+
# ----- XDI files

0 commit comments

Comments
 (0)