├── .gitattributes ├── .gitignore ├── .vscode └── tasks.json ├── LICENSE ├── Makefile ├── README.md ├── build.sh └── srv ├── .init.lua ├── index.html └── redbean.css /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh text eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pid 2 | *.log 3 | definitions 4 | 5 | ### REDBEAN-TEMPLATE 6 | # executables shouldn't be in a public git repo 7 | *.com 8 | *.com.template 9 | 10 | ### Created by https://www.gitignore.io 11 | ### Vim ### 12 | # Swap 13 | [._]*.s[a-v][a-z] 14 | # comment out if you don't need vector files 15 | !*.svg 16 | [._]*.sw[a-p] 17 | [._]s[a-rt-v][a-z] 18 | [._]ss[a-gi-z] 19 | [._]sw[a-p] 20 | 21 | # Session 22 | Session.vim 23 | Sessionx.vim 24 | 25 | # Temporary 26 | .netrwhist 27 | *~ 28 | tmp 29 | .tmp 30 | # Auto-generated tag files 31 | tags 32 | # Persistent undo 33 | [._]*.un~ 34 | 35 | ### Emacs ### 36 | # -*- mode: gitignore; -*- 37 | *~ 38 | \#*\# 39 | /.emacs.desktop 40 | /.emacs.desktop.lock 41 | *.elc 42 | auto-save-list 43 | tramp 44 | .\#* 45 | 46 | # Org-mode 47 | .org-id-locations 48 | *_archive 49 | 50 | # flymake-mode 51 | *_flymake.* 52 | 53 | # eshell files 54 | /eshell/history 55 | /eshell/lastdir 56 | 57 | # elpa packages 58 | /elpa/ 59 | 60 | # reftex files 61 | *.rel 62 | 63 | # AUCTeX auto folder 64 | /auto/ 65 | 66 | # cask packages 67 | .cask/ 68 | dist/ 69 | 70 | # Flycheck 71 | flycheck_*.el 72 | 73 | # server auth directory 74 | /server/ 75 | 76 | # projectiles files 77 | .projectile 78 | 79 | # directory configuration 80 | .dir-locals.el 81 | 82 | # network security 83 | /network-security.data 84 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "redbean init", 6 | "detail": "Fetch redbean, zip and SQLite.", 7 | "type": "shell", 8 | "group": "build", 9 | "command": "./build.sh init", 10 | "windows": { 11 | "command": "wsl ./build.sh init" 12 | }, 13 | "problemMatcher": [] 14 | }, 15 | { 16 | "label": "redbean pack", 17 | "detail": "Pack \"./srv/\" into a new redbean, overwriting the old.", 18 | "type": "shell", 19 | "group": { 20 | "kind": "build", 21 | "isDefault": true 22 | }, 23 | "command": "./build.sh pack", 24 | "windows": { 25 | "command": "wsl ./build.sh pack" 26 | }, 27 | "problemMatcher": [] 28 | }, 29 | { 30 | "label": "redbean run", 31 | "detail": "Pack, then execute with a customizable command.", 32 | "type": "shell", 33 | "group": "build", 34 | "command": "./build.sh run", 35 | "windows": { 36 | "command": "wsl ./build.sh run" 37 | }, 38 | "problemMatcher": [] 39 | }, 40 | { 41 | "label": "redbean clean", 42 | "detail": "Delete all downloaded and generated files", 43 | "type": "shell", 44 | "group": "none", 45 | "command": "./build.sh clean", 46 | "windows": { 47 | "command": "wsl ./build.sh clean" 48 | }, 49 | "problemMatcher": [] 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # /*─────────────────────────────────────────────────────────────────╗ 2 | # │ To the extent possible under law, Jared Miller has waived │ 3 | # │ all copyright and related or neighboring rights to this file, │ 4 | # │ as it is written in the following disclaimers: │ 5 | # │ • http://unlicense.org/ │ 6 | # ╚─────────────────────────────────────────────────────────────────*/ 7 | .PHONY: all clean test log ls log start start-daemon restart-daemon stop-daemon 8 | 9 | # Change redbean to whatever you want 10 | PROJECT=redbean 11 | REDBEAN=${PROJECT}.com 12 | REDBEAN_VERSION=2.2 13 | # leave empty for default, or use one of tiny-, asan-, original-, static-, unsecure-, original-tinylinux- 14 | # asan mode currently not working on M1 Macs 15 | #REDBEAN_MODE= 16 | REDBEAN_MODE=asan- 17 | REDBEAN_DL=https://redbean.dev/redbean-${REDBEAN_MODE}${REDBEAN_VERSION}.com 18 | 19 | SQLITE3=sqlite3.com 20 | SQLITE3_DL=https://redbean.dev/sqlite3.com 21 | ZIP=zip.com 22 | ZIP_DL=https://redbean.dev/zip.com 23 | UNZIP=unzip.com 24 | UNZIP_DL=https://redbean.dev/unzip.com 25 | DEFINITIONS=definitions/redbean.lua 26 | DEFINITIONS_DL=https://raw.githubusercontent.com/jart/cosmopolitan/2.2/tool/net/definitions.lua 27 | 28 | NPD=--no-print-directory 29 | 30 | all: download add 31 | 32 | download: ${REDBEAN} ${SQLITE3} ${ZIP} ${UNZIP} ${DEFINITIONS} 33 | 34 | ${REDBEAN}.template: 35 | curl -s ${REDBEAN_DL} -o $@ -z $@ && \ 36 | chmod +x $@ 37 | 38 | ${REDBEAN}: ${REDBEAN}.template 39 | cp ${REDBEAN}.template ${REDBEAN} 40 | 41 | ${SQLITE3}: 42 | curl -s ${SQLITE3_DL} -o $@ -z $@ 43 | chmod +x ${SQLITE3} 44 | 45 | ${ZIP}: 46 | curl -s ${ZIP_DL} -o $@ -z $@ 47 | chmod +x ${ZIP} 48 | 49 | ${UNZIP}: 50 | curl -s ${UNZIP_DL} -o $@ -z $@ 51 | chmod +x ${UNZIP} 52 | 53 | ${DEFINITIONS}: 54 | mkdir -p definitions 55 | curl -s ${DEFINITIONS_DL} -o $@ -z $@ 56 | 57 | add: ${ZIP} ${REDBEAN} 58 | cp -f ${REDBEAN}.template ${REDBEAN} 59 | cd srv/ && ../${ZIP} -r ../${REDBEAN} `ls -A` 60 | 61 | ls: ${UNZIP} 62 | @./${UNZIP} -vl ./${REDBEAN} | grep -v \ 63 | 'usr/\|.symtab' 64 | 65 | log: ${PROJECT}.log 66 | tail -f ${PROJECT}.log 67 | 68 | start: ${REDBEAN} 69 | ./${REDBEAN} -vv 70 | 71 | start-daemon: ${REDBEAN} 72 | @(test ! -f ${PROJECT}.pid && \ 73 | ./${REDBEAN} -vv -d -L ${PROJECT}.log -P ${PROJECT}.pid && \ 74 | printf "started $$(cat ${PROJECT}.pid)\n") \ 75 | || echo "already running $$(cat ${PROJECT}.pid)" 76 | 77 | restart-daemon: 78 | @(test ! -f ${PROJECT}.pid && \ 79 | ./${REDBEAN} -vv -d -L ${PROJECT}.log -P ${PROJECT}.pid && \ 80 | printf "started $$(cat ${PROJECT}.pid)") \ 81 | || kill -HUP $$(cat ${PROJECT}.pid) && \ 82 | printf "restarted $$(cat ${PROJECT}.pid)\n" 83 | 84 | stop-daemon: ${PROJECT}.pid 85 | @kill -TERM $$(cat ${PROJECT}.pid) && \ 86 | printf "stopped $$(cat ${PROJECT}.pid)\n" && \ 87 | rm ${PROJECT}.pid \ 88 | 89 | clean: 90 | rm -f ${PROJECT}.log ${PROJECT}.pid ${REDBEAN} ${REDBEAN}.template ${SQLITE3} ${ZIP} ${UNZIP} ${DEFINITIONS} 91 | [ "$(ls -A definitions)" ] || rm -rf definitions 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Template for Redbean Projects 2 | 3 | This repo contains two options for managing your project: a shell script, and a 4 | Makefile. 5 | 6 | To make your redbean launch a browser on start, uncomment 7 | `LaunchBrowserOnStart()` in `srv/.init.lua`. 8 | 9 | M1 Mac users should use the default `MODE` instead of `asan-`, this can be set 10 | in the top of your Makefile/build.sh 11 | 12 | ### build.sh 13 | 14 | - `build.sh init`: download Redbean, zip, and sqlite 15 | - `build.sh pack`: put contents of `srv/` into a fresh redbean, overwriting 16 | previously existing bean. 17 | - `build.sh run`: pack and then execute custom command found at top of file 18 | 19 | Stock redbeans are hidden with dots. Executables are excluded in the 20 | `.gitignore`. Since they are *Actually Portable*, you *could* disable this 21 | behavior and commit the executables directly, if you're ok with keeping them in 22 | the git store. Also remember that binaries have a certain risk profile of their 23 | own. 24 | 25 | ### Makefile 26 | 27 | You can also use `make` to do the above. 28 | 29 | - `make` will do `make download` + `make add` 30 | - `make download` will download all of the requirements. 31 | - `make add` zips the contents of `/srv` into your `redbean.com`. 32 | - `make start` or `make start-daemon` will start the webserver (in foreground and background, respectively) 33 | 34 | See also: `make stop-daemon`, `make restart-daemon`, `make log`, `make ls` 35 | 36 | ### Roadmap 37 | 38 | - Build.sh 39 | - **INIT**: `build.sh init [-s for sqlite?]` 40 | - [x] Fetch Redbean, save as read-only stock build. 41 | - [x] Also fetch zip & sqlite 42 | - [ ] make sqlite opt-in 43 | - [ ] *Verify checksums for known versions/generate checksums for new 44 | ones* 45 | - **PACK** (default with no arguments) 46 | - [x] force copy stock redbean to writable file. Zip contents of `srv/` 47 | into zip 48 | - [ ] user-specified actions: if one script named `packer*` exists and is 49 | executable, run it 50 | - [ ] *if sqlite.com and `default.sqlite` exist, force copy 51 | `default.sqlite` to `db.sqlite`* 52 | - **RUN** 53 | - [x] pack and then execute command specified in variable 54 | 55 | ### Notable contributions 56 | 57 | - VSCode integration by [Danny Robinson 58 | (stellartux)](https://github.com/stellartux) 59 | - Makefile by [Jared Miller (shmup)](https://github.com/shmup) 60 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # /*─────────────────────────────────────────────────────────────────╗ 3 | # │ To the extent possible under law, Matthew Pherigo has waived │ 4 | # │ all copyright and related or neighboring rights to this file, │ 5 | # │ as it is written in the following disclaimers: │ 6 | # │ • http://unlicense.org/ │ 7 | # ╚─────────────────────────────────────────────────────────────────*/ 8 | OUT="redbean.com" # Change me! 9 | OUT_CMD="./${OUT}" # called with "build.sh run" 10 | 11 | #OUT_CMD="./${OUT} -SSS" # extra-sandboxed version of redbean 12 | # NOTE: https://redbean.dev/#security 13 | 14 | RB_VERSION="2.2" 15 | 16 | # Use default redbean if on M1 Mac. Else use ASAN 17 | # NOTE(ProducerMatt): This code block exists because of ASAN crashes on M1. 18 | # Once they're fixed we can go back to default ASAN on all systems. 19 | if which arch 2>/dev/null && [ "$(arch)" != "x86_64" ]; then 20 | RB_MODE= # default 21 | else 22 | RB_MODE="asan-" # Memory hardening goodness for bug/exploit prevention 23 | fi 24 | # leave RB_MODE empty for default, or use one of tiny-, asan-, original-, 25 | # static-, unsecure-, original-tinylinux- 26 | 27 | RB_URL="https://redbean.dev/redbean-${RB_MODE}${RB_VERSION}.com" 28 | STOCK=".rb-${RB_MODE}${RB_VERSION}_stock.com" 29 | ZIP_URL="https://redbean.dev/zip.com" 30 | SQLITE_URL="https://redbean.dev/sqlite3.com" 31 | DEFINITIONS_URL="https://raw.githubusercontent.com/jart/cosmopolitan/2.2/tool/net/definitions.lua" 32 | 33 | _Fetch() { 34 | # $1 = target filesystem location 35 | # $2 = URL 36 | echo "Getting $1 from $2" 37 | if command -v wget >/dev/null 2>&1; then 38 | wget -NqcO ".tmp" $2 || exit 39 | elif command -v curl >/dev/null 2>&1; then 40 | curl -so ".tmp" -z ".tmp" $2 || exit 41 | elif command -v fetch >/dev/null 2>&1; then 42 | fetch -mo ".tmp" $2 || exit 43 | else echo "No downloaders!"; exit 1; 44 | fi 45 | mv -f ".tmp" $1 46 | } 47 | _Init () { 48 | u=`umask`; 49 | umask 222; 50 | _Fetch "$STOCK" "$RB_URL"; 51 | _Fetch "zip.com" "$ZIP_URL"; 52 | chmod +x "zip.com" 53 | _Fetch "sqlite.com" "$SQLITE_URL"; 54 | chmod +x "sqlite.com" 55 | mkdir -m 755 -p definitions 56 | _Fetch "definitions/redbean.lua" "$DEFINITIONS_URL" 57 | umask $u; 58 | } 59 | _Pack () { 60 | # TODO: skip if no changed files in srv since last update? 61 | # test if directory exists and has anything in it, if not fail 62 | cp -f $STOCK $OUT 63 | chmod u+w $OUT 64 | chmod +x $OUT 65 | 66 | # NOTE: zip's structure is dependent on the relative paths of the files. 67 | # so calling from the root of the source file's directory is important 68 | # if you want files like `.lua` to be in the right place. 69 | cd srv/ 70 | ../zip.com -r "../$OUT" `ls -A` 71 | cd .. 72 | } 73 | _Clean () { 74 | rm -f zip.com sqlite.com $STOCK $OUT definitions/redbean.lua .tmp 75 | [ "$(ls -A definitions)" ] || rm -rf definitions 76 | } 77 | 78 | case "$1" in 79 | init ) 80 | _Init; 81 | ;; 82 | pack ) 83 | _Pack; 84 | ;; 85 | run ) 86 | _Pack; 87 | exec $OUT_CMD; 88 | ;; 89 | clean ) 90 | _Clean; 91 | ;; 92 | * ) 93 | echo "a builder for redbean projects" 94 | echo "- '$0 init': fetch redbean, zip and sqlite" 95 | echo "- '$0 pack': pack "./srv/" into a new redbean, overwriting the old" 96 | echo "- '$0 run': pack, then execute with a customizable command" 97 | echo "- '$0 clean': delete all downloaded and generated files" 98 | ;; 99 | esac 100 | -------------------------------------------------------------------------------- /srv/.init.lua: -------------------------------------------------------------------------------- 1 | -- https://redbean.dev/#usage 2 | 3 | -- Uncomment this to launch a browser on start 4 | --LaunchBrowser("/") 5 | -------------------------------------------------------------------------------- /srv/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | redbean 4 | 5 | 6 | 7 |

8 | redbean
9 | distributable static web server 10 |

11 | 12 |

13 | Here's what you need to know about redbean: 14 | 15 |

22 | 23 |

24 | redbean is based on αcτµαlly pδrταblε εxεcµταblε 25 | and cosmopolitan. 26 |
27 | redbean is authored by Justine Tunney who's on 28 | GitHub and 29 | Twitter. 30 | -------------------------------------------------------------------------------- /srv/redbean.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-family: sans-serif; 3 | font-size: 14pt; 4 | } 5 | 6 | body { 7 | max-width: 700px; 8 | min-width: 700px; 9 | margin: 0 auto 0 auto; 10 | } 11 | 12 | pre, 13 | code { 14 | font-family: monospace; 15 | font-size: 12pt; 16 | } 17 | 18 | p { 19 | text-align: justify; 20 | } 21 | 22 | .indent { 23 | margin-left: 1em; 24 | } 25 | 26 | h1, 27 | h2 { 28 | margin: 1.5em 0 1.5em 0; 29 | } 30 | 31 | h1 strong { 32 | font-size: 14pt; 33 | } 34 | 35 | footer { 36 | margin-top: 12em; 37 | margin-bottom: 3em; 38 | font-size: 14pt; 39 | } 40 | 41 | .logo { 42 | float: right; 43 | } 44 | --------------------------------------------------------------------------------