Skip to content

Instantly share code, notes, and snippets.

@n0b0dy
Created September 29, 2013 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0b0dy/6748342 to your computer and use it in GitHub Desktop.
Save n0b0dy/6748342 to your computer and use it in GitHub Desktop.
#!/bin/sh
#sshkeper 0.1 stub
stubid='11e147c678fd44fada054745e31d7492'
enc='openssl enc -e -base64 -aes-256-cfb'
dec='openssl enc -d -base64 -aes-256-cfb'
compression='z' #
prefix="$HOME/.ssh"
self="$0"
selfpkg(){
action=$1
tar -C "$prefix" "-$action" "-$compression" -vf- "$2"
}
stubline(){
i=0 #число строк в stub
# вычисления числа строк
while read line
do
i=`expr $i + 1`
if test "$line" = "#$stubid"; then break; fi
done < $self
echo $i
}
# помощь
usage(){
cat << EOH >&2
Usage:
$self [options]"
Application Options:
-p path prefix
-x extract
-u update
-c create
-d diff
-t list
-h help
Version id: $stubid
Licence: MIT
EOH
}
if test "$#" -eq 0 ; then usage;exit 1;fi
set -- $(getopt xctdp:h "$@")
while test $# -gt 0
do
case "$1" in
-x) extflag=y;;
-c) createflag=y;;
-t) listflag=y;;
-d) diffflag=y;;
-p) prefix="$2";shift;;
-h) usage "$0";;
--) shift;break;;
-*) usage "$0";;
*) break;;
esac
shift
done
line=`stubline`
offset=`head -n $line "$self" | wc -c | tr -d " "`
if test "$createflag" = "y" ; then
selfpkg c '.' 2>/dev/null | eval $enc | dd of="$self" obs="$offset" seek=1 2>/dev/null
fi
if test "$extflag" = "y" ; then
dd if="$self" ibs="$offset" skip=1 2>/dev/null | eval "$dec" | selfpkg x
fi
if test "$listflag" = "y" ; then
dd if="$self" ibs="$offset" skip=1 2>/dev/null | eval "$dec" | selfpkg t
fi
if test "$diffflag" = "y" ; then
dd if="$self" ibs="$offset" skip=1 2>/dev/null | eval "$dec" | selfpkg d
fi
exit 0
#stub id
#11e147c678fd44fada054745e31d7492
H4sIAKh+R1IAAwMAAAAAAAAAAAA=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment