#!/bin/sh set -e TMP=$(umask 077; mktemp -d) echo >&2 " tmp $TMP" Die() { trap - EXIT rm -rf $TMP exit ${1:-$e} }; trap Die HUP EXIT #INT pause() {( echo >&2 -n "Continue? ..." read -sn1 REPLY echo >&2 )} confirm() {( echo >&2 -n "$@ [y/n] " read -n1 REPLY echo >&2 case $REPLY in y|Y) : ;; n|N) exit 1 ;; *) confirm "again" ;; esac )} I=0 if [ -n "$1" ]; then echo >&2 " [thanks] for the file (om nom)." I=1 C="$1" shift 1 fi case $I in 0) echo >&2 "[+] Building/testing internal program now; lucky!" echo >&2 " You should really be more cautious..." echo >&2 " (hehe) -wait for the potential virus..." echo >&2 " ... you believe too much in what you read," echo >&2 " never can you be fully certain of anything..." cat >"$TMP/t.c" <<%EOF #include #include #include #include #include #include void input() { struct stat stdin_stat; fstat(0,&stdin_stat); if (S_ISCHR(stdin_stat.st_mode)) return; /*interactive*/ /*if (S_ISFIFO(stdin_stat.st_mode)) return; /*pipe mode*/ char sti[256]; while (1) { if (fgets(sti, sizeof sti, stdin) ==NULL) break; /**/ printf("%s",sti); } } void files() { FILE *f; f=fopen("____file","w"); mkdir("____dir",0755); } void main() { input(); files(); exit(0); } %EOF ;; 1) cat "$C" >"$TMP/t.c" ;; esac cd $TMP ||{ echo '[error: cannot enter directory] '"$TMP"; Die 1; }>&2 cc -o exe t.c ||: case $I in 0) echo 'ABCDEF' |./exe ||: ;; 1) ./exe "$@" ||: ;; esac e=$? (confirm "program removes tmp. (CTRL-C to abort)") Die $e