dont_curl_this.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. set -x -e -o pipefail
  3. cd $(mktemp -d)
  4. curl -s -L http://prdownloads.sourceforge.net/sbcl/sbcl-2.3.6-x86-64-linux-binary.tar.bz2 > sbcl.tar.bz2
  5. tar -xf sbcl.tar.bz2
  6. SBCL_DIR=$(ls | grep -v sbcl.tar.bz2)
  7. cp "$SBCL_DIR/output/sbcl.core" "$SBCL_DIR/src/runtime/"
  8. cat <<-EOF > ./spell.lisp
  9. (defvar *randomness* (make-random-state t))
  10. (defun split-string (string delimiter)
  11. (loop with len = (length string)
  12. with start = 0
  13. for end = (position delimiter string :start start)
  14. for substr = (if end
  15. (subseq string start end)
  16. (subseq string start))
  17. while end
  18. append (list substr)
  19. do (setf start (1+ end))
  20. until (= end len)))
  21. (defun list-files-in-directory (directory-path)
  22. (let* ((files (directory (merge-pathnames "*.*" (pathname directory-path))))
  23. (directory-pathname (pathname directory-path)))
  24. (mapcar #'(lambda (file)
  25. (merge-pathnames (pathname file) directory-pathname))
  26. files)))
  27. (defun bins-list ()
  28. (apply #'append
  29. (mapcar #'list-files-in-directory
  30. (loop for path in (split-string (sb-ext:posix-getenv "PATH") #\:)
  31. collect (format NIL "~a~c" path #\/)))))
  32. (defun random-bin (bins-list)
  33. (namestring (nth (random (length bins-list) *randomness*) bins-list)))
  34. (defun random-cmd (bins-list)
  35. (let ((number-of-pipes (random 4 *randomness*))
  36. (cmd-str ""))
  37. (if (> number-of-pipes 0)
  38. (progn
  39. (dotimes (i (+ 1 number-of-pipes))
  40. (setq cmd-str (concatenate 'string cmd-str (format NIL "~A | " (random-bin bins-list)))))
  41. (setq cmd-str (concatenate 'string (subseq cmd-str 0 (- (length cmd-str) 3)) (format NIL "~%"))))
  42. (setq cmd-str (concatenate 'string cmd-str (format NIL "~A~%" (random-bin bins-list)))))
  43. cmd-str))
  44. (format T "~a" (random-cmd (bins-list)))
  45. EOF
  46. $SBCL_DIR/src/runtime/sbcl --script spell.lisp