Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

hashbang.sh 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. -----BEGIN PGP SIGNED MESSAGE-----
  2. Hash: SHA256
  3. #!/bin/sh
  4. <<\EOF
  5. <!--
  6. Hey, you found the source code!
  7. That is a sign you hopefully know better than to blindly run unknown commands
  8. from the internet and/or are a curious person. We like you already.
  9. What this command will actually do, is set you up with a free "shell" account
  10. on one of our servers, that you can use as you see fit. It will also set you
  11. up with email, IRC, and other things on your shell, so you can keep in touch
  12. and learn/make awesome things with us.
  13. Don't trust us? Good! You probably don't know us (yet) so you shouldn't.
  14. To help address this we GPG sign this shell-setup script so you can verify
  15. it has not been changed by a third party before you run it by doing:
  16. > gpg --verify <(curl https://hashbang.sh)
  17. The safest method of running a script from a source you don't trust is to:
  18. Download locally over SSL
  19. > curl https://hashbang.sh >> hashbang.sh
  20. Verify integrty with GPG (If available)
  21. > gpg --recv-keys 0xD2C4C74D8FAA96F5
  22. > gpg --verify hashbang.sh
  23. Inspect source code
  24. > less hashbang.sh
  25. Run
  26. > chmod +x hashbang.sh
  27. > ./hashbang.sh
  28. As an advanced alternative you can bypass using this script and hit our user
  29. provisioning API directly with an SSH Public Key and desired username:
  30. > curl -d '{"user":"someuser","key":"'"$(cat ~/.ssh/id_rsa.pub)"'"}' -H 'Content-Type: application/json' https://hashbang.sh/user/create
  31. We look forward to seeing you on the other side.
  32. - -->
  33. <!DOCTYPE html>
  34. <html lang="en">
  35. <head>
  36. <title>&lrm;</title>
  37. <meta name="viewport" content="initial-scale = 1, maximum-scale=1, user-scalable = 0"/>
  38. <meta name="apple-mobile-web-app-capable" content="yes"/>
  39. <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
  40. <meta name="HandheldFriendly" content="true"/>
  41. <meta name="MobileOptimized" content="320"/>
  42. <link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
  43. <style type="text/css">
  44. * {
  45. text-indent:-9999px;
  46. -webkit-touch-callout: none;
  47. -webkit-user-select: none;
  48. -khtml-user-select: none;
  49. -moz-user-select: none;
  50. -ms-user-select: none;
  51. user-select: none;
  52. }
  53. html {
  54. background:black;
  55. color:black;
  56. }
  57. body {
  58. display:block;
  59. position:fixed;
  60. top:50%;
  61. left:50%;
  62. margin-top:-160px;
  63. margin-left:-160px;
  64. width:320px;
  65. height:320px;
  66. color:#DDD;
  67. overflow:hidden;
  68. }
  69. h1 {
  70. text-indent:0px;
  71. font-family: 'Montserrat', cursive;
  72. position:absolute;
  73. top:-50px;
  74. left:10px;
  75. right:0px;
  76. line-height:0px;
  77. font-size:280px;
  78. }
  79. a {
  80. color:white;
  81. text-decoration:none;
  82. }
  83. code {
  84. text-indent:0px;
  85. display:block;
  86. position:absolute;
  87. bottom:0px;
  88. left:0px;
  89. right:0px;
  90. text-align:center;
  91. font-size:20px;
  92. }
  93. </style>
  94. </head>
  95. <body>
  96. <script>
  97. window.location="#!"
  98. var link = document.createElement("link");
  99. link.type = "image/png";
  100. link.rel = "icon";
  101. link.href = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQAAAAA3iMLMAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAAYSURBVAjXY2CAAck+EKp/B0II9gMoGwYA4+MJkeae/NUAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTQtMDUtMTdUMTM6MzI6MTMtMDQ6MDB7pieOAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE0LTA1LTE3VDEzOjMxOjQ4LTA0OjAwqyt+rwAAAABJRU5ErkJggg==";
  102. document.getElementsByTagName("head")[0].appendChild(link);
  103. </script>
  104. <h1>#!</h1>
  105. <a href="view-source:https://hashbang.sh"><code>sh <(curl hashbang.sh)</code></a>
  106. </body>
  107. </html>
  108. <!--
  109. EOF
  110. #!/bin/sh
  111. # This script first and foremost attempts to be POSIX compliant.
  112. # Secondly, it attempts to be compatible with as many shell implementations as
  113. # possible to provide an easy gateway for new users.
  114. # If we're using bash, we do this
  115. if [ "x$BASH" != "x" ]; then
  116. shopt -s extglob
  117. set -o posix
  118. fi
  119. checkutil() {
  120. printf " * Checking for $1..."
  121. which $1 >/dev/null
  122. if [ $? -eq 0 ]; then
  123. printf "ok!\n";
  124. return 0;
  125. else
  126. printf "not found!"
  127. return 1
  128. fi
  129. }
  130. # This function can be called with two parameters:
  131. #
  132. # First is obligatory, and is the "question posed".
  133. # For instance, one may ask "is pizza your favorite meal?", to which the
  134. # responder may answer Y (yes) or N (no).
  135. #
  136. # Second parameter is optional, and can be either Y or N.
  137. # The reasoning behind this is to have a default answer to the question,
  138. # resulting in the responder being able to simple press [enter] and skip
  139. # pressing Y or N, giving the default answer instead.
  140. ask() {
  141. while true; do
  142. prompt=""
  143. default=""
  144. if [ "${2}" = "Y" ]; then
  145. prompt="Y/n"
  146. default=Y
  147. elif [ "${2}" = "N" ]; then
  148. prompt="y/N"
  149. default=N
  150. else
  151. prompt="y/n"
  152. default=
  153. fi
  154. # Ask the question
  155. printf "%s [%s] " "$1" "$prompt"
  156. read REPLY
  157. # Default?
  158. if [ -z "$REPLY" ]; then
  159. REPLY=$default
  160. fi
  161. # Check if the reply is valid
  162. case "$REPLY" in
  163. Y*|y*) return 0 ;;
  164. N*|n*) return 1 ;;
  165. esac
  166. done
  167. }
  168. clear;
  169. echo " _ _ __ ";
  170. echo " _| || |_ | | Welcome to #!. This network has three rules:";
  171. echo "|_ __ _|| | ";
  172. echo " _| || |_ | | 1. When people need help, teach. Don't do it for them";
  173. echo "|_ __ _||__| 2. Don't use our resources for closed source projects";
  174. echo " |_||_| (__) 3. Be excellent to each other";
  175. echo " ";
  176. echo " We are a diverse community of people who love teaching, and learning.";
  177. echo " Putting a #! at the beginning of a \"script\" style program tells a ";
  178. echo " computer that it needs to \"do something\" or \"execute\" this file.";
  179. echo " Likewise, we are a community of people that like to \"do stuff\".";
  180. echo " ";
  181. echo " If you like technology, and you want to learn to write your first";
  182. echo " program, learn to use Linux, or even take on interesting challenges";
  183. echo " with some of the best in the industry, you are in the right place.";
  184. echo "";
  185. echo " The following will set you up with a \"shell\" account on one of our";
  186. echo " shared systems. From here you can run IRC chat clients to talk to us,";
  187. echo " access to personal file storage and web hosting, and a wide range of";
  188. echo " development tools. ";
  189. echo " ";
  190. echo " Everything should work perfectly, unless it doesn't";
  191. echo " ";
  192. echo " Please report any issues here: ";
  193. echo " -> https://github.com/hashbang/hashbang.sh/issues/";
  194. echo " ";
  195. printf " If you agree with the above and wish to continue, hit [Enter] ";
  196. read _
  197. clear
  198. echo " ";
  199. echo " ";
  200. echo " -------------------------------------------------------------------- ";
  201. echo " ";
  202. echo " First, your system must be properly configured with the required";
  203. echo " utilities and executables.";
  204. echo " We will perform a short check for those now.";
  205. echo " NOTE: If you see this message, it is likely because something is";
  206. echo " not installed. Check the list below, and install any";
  207. echo " missing applications.";
  208. checkutil expr || exit 1
  209. ( checkutil ssh-keygen && checkutil ssh ) || exit 1
  210. ( checkutil curl || checkutil busybox ) || exit 1
  211. clear;
  212. echo " ";
  213. echo " ";
  214. echo " -------------------------------------------------------------------- ";
  215. echo " ";
  216. echo " To create your account we first need a username.";
  217. echo " ";
  218. echo " A valid username must:";
  219. echo " * be between between 1-31 characters long";
  220. echo " * consist of only 0-9 and a-z (lowercase only)";
  221. echo " * begin with a letter";
  222. echo " ";
  223. echo " Traditional unix usernames are first initial, optional middle initial,";
  224. echo " and the first 6 characters of the last name, but feel free to use ";
  225. echo " whatever you want";
  226. echo " ";
  227. while [ "x$username" = "x" ]; do
  228. printf " Username: ";
  229. read input;
  230. if echo "$input" | grep -E "^[a-z][a-z0-9]{0,30}$" >/dev/null; then
  231. username=$input
  232. else
  233. echo " ";
  234. echo " \"$input\" is not a valid username."
  235. echo " Please read the instructions and try again"
  236. echo " ";
  237. fi
  238. done
  239. echo " ";
  240. echo " -------------------------------------------------------------------- ";
  241. echo " ";
  242. echo " Now we will need an SSH Public Key."
  243. echo " ";
  244. echo " SSH Keys are a type of public/private key system that let you identify ";
  245. echo " yourself to systems like this one without ever sending your password ";
  246. echo " over the internet, and thus by nature we won't even know what it is";
  247. echo " ";
  248. for keytype in id_rsa id_dsa id_ecdsa id_ed25519; do
  249. if [ -e ~/.ssh/$keytype.pub ]; then
  250. if ask " We found a public key in [ ~/.ssh/$keytype.pub ]. Use this key?" Y; then
  251. keyfile="~/.ssh/$keytype.pub"
  252. key=$(cat ~/.ssh/$keytype.pub)
  253. break
  254. fi
  255. fi
  256. done
  257. if [ "x$key" = "x" ]; then
  258. if ask " Do you want us to generate a key for you?" Y; then
  259. ssh-keygen -t rsa -C "#! $username"
  260. keyfile="~/.ssh/id_rsa.pub"
  261. key=$(cat ~/.ssh/id_rsa.pub)
  262. fi
  263. fi
  264. while [ "x$key" = "x" ]; do
  265. echo " ";
  266. echo " Please enter path to SSH Public Key: ";
  267. read keyfile
  268. if [ -f $keyfile ] ; then
  269. ssh-keygen -l -f $keyfile > /dev/null 2>&1
  270. if [ $? -eq 0 ]; then
  271. key=$(cat $keyfile)
  272. else
  273. echo " ";
  274. echo " \"$keyfile\" is not a valid SSH Public Key";
  275. fi
  276. else
  277. echo " ";
  278. echo " \"$keyfile\" does not exist";
  279. fi
  280. done
  281. # Insert functions to allow user to select from multiple hosts here
  282. # hardcoding all users to va1 for now
  283. host="va1"
  284. if [ "x$key" != "x" -a "x$username" != "x" ]; then
  285. echo " ";
  286. echo " -------------------------------------------------------------------- ";
  287. echo " ";
  288. echo " We are going to create an account with the following information";
  289. echo " ";
  290. echo " Username: $username";
  291. echo " Public Key: $keyfile";
  292. echo " Host: $host";
  293. echo " ";
  294. if ask " Does this look correct?" Y ; then
  295. echo " ";
  296. echo " Creating your account...";
  297. echo " ";
  298. if curl -f -H "Content-Type: application/json" \
  299. -d "{\"user\":\"$username\",\"key\":\"$key\",\"host\":\"$host\"}" \
  300. https://hashbang.sh/user/create; then
  301. echo " ";
  302. echo " Account Created!"
  303. echo " ";
  304. else
  305. echo " ";
  306. echo " Account creation failed.";
  307. echo " Something went awfully wrong and we couldn't create an account for you.";
  308. echo " If you think this is a bug, please report it to ";
  309. echo " -> https://github.com/hashbang/hashbang.sh/issues/";
  310. echo " ";
  311. echo " The installer will not continue from here...";
  312. echo " ";
  313. exit 1
  314. fi
  315. if ask " Would you like an alias (shortcut) added to your .ssh/config?" Y ; then
  316. printf "\nHost hashbang\n HostName ${host}.hashbang.sh\n User %s\n IdentityFile %s\n" \
  317. "$username" "$keyfile" \
  318. >> ~/.ssh/config
  319. echo " You can now connect any time by entering the command:";
  320. echo " ";
  321. echo " > ssh hashbang";
  322. else
  323. echo " You can now connect any time by entering the command:";
  324. echo " ";
  325. echo " > ssh ${username}@${host}.hashbang.sh";
  326. fi
  327. echo " ";
  328. fi
  329. if ask " Do you want us to log you in now?" Y; then
  330. ssh ${username}@${host}.hashbang.sh
  331. fi
  332. fi
  333. # exit [n]. if [n] is not specified, then exit shall use the return code of the
  334. # last command.
  335. exit 0
  336. -----BEGIN PGP SIGNATURE-----
  337. Version: GnuPG v2
  338. iQIcBAEBCAAGBQJVBUEaAAoJENLEx02Pqpb1t8MQAILYt9PTMyWC5rqd9E78eCA6
  339. wlv/LLDdbNdLfSyWxGZCQbPzxmb1q0rgQdstm111samUvqQWbHNEVnjI8Ms4AmaI
  340. SmYXgF3e491rWGtf6DBhcoGAHrr1ClmdJHUqgyamdd++mHrWLjSh+WtzbsHrRPTy
  341. xZ2egiJKVydFktsSxQvDk4ruZaRfBDwmSuZ/JGK60oIb5U8dWN3LV9R6gAucAVNp
  342. TsDqJajh9yl/vaB5ebhFrzJaWmSUT/FEU5Ulv48AGJjmSonGZR3fCICaVoKTAqhM
  343. 5SMjD4d9CChKRg3K1JV+SgWBydj59bPMiw2+7tu4RU6S6o+tsTQlMs26E/qwZ7qT
  344. aN65KXVvZX9YGTxjo4V/qAQWlcWHgzJFmzHiQrDv2BUYKU822pJ/d88oGo7I13ZG
  345. DeMXexnKp66W6Bl591zDYqlTGiF8NpZrp7VE2SpkT0BqnuKtN81KVGCYgwA4TOf7
  346. VlEuJRb/Plz1sWcNB9CpYxS/gh886l2lEIa20T+YYu+6Bos9olcR3HA6RiEHC2FE
  347. Fk2z7b67ocprWp9euiMMEBL0/Cx9jBdDdyhM8MQ75YImRKwTnPHdpq5CcJJ5Quwx
  348. c13aIemWlgQU30hQmISiKsU70q0Z+ax3GmdSsdfXRiyRIlqGAbS+GPU9xatp44JA
  349. WxDkrEseYOPiDRlzEh3K
  350. =OvXQ
  351. -----END PGP SIGNATURE-----