manpp: handle groff \N[dd] escape sequence
[rofl0r-hardcore-utils.git] / filesplitter.sh
bloba602ab6a04e877aa7a4d5248ed1a09640a3c465e
1 #!/bin/sh
3 file="$1"
4 pieces="$2"
6 [ -z "$pieces" ] && {
7 printf "%s file pieces\n" "$0"
8 printf "splits file into 'pieces' pieces.\n"
9 exit 1
12 [ -e "$file" ] || {
13 echo "error: file not exists"
14 exit 1
17 fs=$(wc -c "$file"| cut -d " " -f 1)
19 chunksz=$((fs / pieces))
20 bdone=0
21 md5=$(md5sum "$file"| cut -d " " -f 1)
22 f=$(basename "$file")
24 script=$(printf "%s.assemble.sh" "$file")
25 echo "#!/bin/sh" > "$script"
26 echo "rm -f \"$f\"" >> "$script"
27 for i in `seq $pieces` ; do
28 of=$(printf "%s.part.%.4d" "$file" "$i")
29 bytes="$chunksz"
30 if [ "$i" = "$pieces" ] ; then bytes=$((fs - ((pieces-1)*chunksz) )) ; fi
31 dd if="$file" of="$of" bs=1 skip="$bdone" count="$bytes" >/dev/null 2>&1
32 bdone=$((bdone + bytes))
33 ofs=$(basename "$of")
34 echo "cat \"$ofs\" >> \"$f\"" >> "$script"
35 echo created "$of".
36 done
37 cat << EOF >> "$script"
38 test \$(md5sum "$f" | cut -d " " -f 1) = $md5 || {
39 echo "md5 mismatch!"
40 exit 1
42 echo "successfully recreated $f"
43 EOF
44 chmod +x "$script"
45 echo "created $script".