forked from neobht/uird
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuirdinsert
More file actions
executable file
·75 lines (66 loc) · 1.8 KB
/
uirdinsert
File metadata and controls
executable file
·75 lines (66 loc) · 1.8 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
#!/bin/bash
### Add, replace, remove files from UIRD
### $0 UIRD.cpio.xz - interactive mode
### $0 UIRD.cpio.xz myfile::/usr/bin/file - add or replace /usr/bin/file in UIRD by myfile
### $0 UIRD.cpio.xz ::/usr/bin/file - remove /usr/bin/file
### $0 UIRD.cpio.xz ::/usr/bin/file myfile::/usr/bin/file - more than one actions
unset UIRD
unset INTERACTIVE
cmdline="$@"
echo_exit() {
echo -e "$1"
echo "exitcode: $2"
exit $2
}
run (){
echo "$@"
$@
}
[ "$1" ] || cat $0 |egrep '^### '
[ "$1" ] || exit
[ -f "$1" ] || echo_exit "$1 not a filem must be uird" ${LINENO}
UIRD="$(realpath $1)"
shift
[ "$1" ] || INTERACTIVE='yes'
TMPD=$(mktemp -d)
trap "rm -rf $TMPD" EXIT
pushd $TMPD >/dev/null
xz -dc $UIRD | cpio -i -d -H newc --no-absolute-filenames
popd >/dev/null
NEWUIRD=${UIRD}.$(date +%M%S)
if [ "$INTERACTIVE" ] ; then
echo -e "\n\t$UIRD
unpacket to:
\t$TMPD
modify and push ENTER to pack it to:
\t$NEWUIRD
"
read qqq
else
while [ $1 ] ; do
IF=$(realpath $(echo $1 |cut -f1 -d ':') 2>/dev/null)
OF=$(echo $1 |cut -f3 -d ':')
if [ "$IF" ] ; then
mkdir -p "${TMPD}/$(dirname $OF)"
if [ -d "$IF" ] ; then
run cp -fax "$IF" ${TMPD}${OF}/
elif [ -f "$IF" ] ; then
run cp -fp "$IF" ${TMPD}${OF}
fi
else
if [ -d "$OF" ] ; then
run rm -rf ${TMPD}${OF}
elif [ -f "$OF" ] ; then
run rm -f ${TMPD}${OF}
fi
fi
shift
unset IF OF
done
fi
echo "Modified: $(date -R)" >> ${TMPD}/uird_version
echo "$0 $cmdline" >> ${TMPD}/uird_version
pushd $TMPD >/dev/null
find . |cpio -o -H newc |xz --check=crc32 --x86 --lzma2 > "$NEWUIRD"
popd >/dev/null
echo "$NEWUIRD"