rpmconf-matt: Switch from dnf-download-signed (which I forgot to
[utils/utils.git] / ftx
1 #!/bin/bash
2 # ftx <file>: file tree extract
3 set -e
4
5 function skip {
6         read -n $1 trash
7 }
8
9 function ftx_sub {
10         if [ -h "$1" ] || [ -a "$1" ]; then
11                 echo "File already exists!" 1>&2
12                 return 1
13         fi
14         read -n 1 type
15         case $type in
16         f|x)
17                 skip 1 # space
18                 read length
19                 head -c "$length" >"$1"
20                 if [ $type == x ]; then
21                         setexec + "$1"
22                 fi
23                 skip 1 # newline
24                 ;;
25         {)
26                 skip 1 # newline
27                 mkdir -- "$1"
28                 (
29                 cd -- "$1"
30                 while read -n 1 what && [ $what == '+' ]; do
31                         skip 1 # space
32                         read -d ' ' length
33                         read -d '' -n $length name
34                         skip 1 # space
35                         ftx_sub "$name"
36                 done
37                 skip 1 # newline
38                 )
39                 ;;
40         l)
41                 skip 1 # space
42                 read -d ' ' length
43                 read -d '' -n $length target
44                 skip 1 # newline
45                 ln -s -- "$target" "$1"
46                 ;;
47         esac
48 }
49
50 ftx_sub "$1"