Programming on the NAS
Learn to program on your QNAP NAS in BASIC, Pascal, Go and Bash. Each language has 30 short lessons, from one printed line to a small finished tool, and bigger projects: menus, a game, a greeting at sign-in and a summary of the NAS. You write a program over SSH and run it on the NAS. TurboShell has BASIC, Free Pascal, Bash and the editors; Go comes from Bucket & Code.
BASIC
30 lessons · 6 projects
The lessons use yabasic, a BASIC without line numbers. The interpreter reads your file and runs it at once, so there is nothing to compile.
Pascal
30 lessons · 6 projects
The lessons use Free Pascal. fpc compiles your file into one program that starts by itself and needs no other file.
Go
30 lessons · 6 projects
Go compiles a program into one static file. You build it in Bucket & Code with the Go runtime and run it on any QNAP NAS with the same type of processor.
Bash
30 lessons · 6 projects
Bash is the shell you type into. A script is a file of the same commands, with variables, conditions and loops.
Projects
Longer programs that draw a menu, play a game, greet you at sign-in or show the state of the NAS. Each page shows the screen as the program drew it on a test NAS.
BASIC
- A menu with boxes in yabasicA yabasic program draws a framed menu with a highlighted bar and opens boxes with the NAS's memory, volumes, uptime and load. You learn to read keys with inkey$ and to draw frames and colours with escape codes.
- A greeting screen in yabasicA yabasic program greets you by the hour and shows the NAS model, uptime, load, the free space of each data volume and a tip of the day in a framed banner. You learn to print frames and colours with plain print, to read the date and to pick a tip with your own random numbers.
- A NAS summary on one screen in yabasicA yabasic program shows the CPU with its cores and logical processors, the temperatures, load, memory, every data volume and the traffic of each network port on one framed screen with bars. You learn to read /proc files whole, to count distinct pairs and to pad coloured text.
- Sector hunt: a puzzle game in yabasicA yabasic game hides 14 bad sectors on a disk of 96 and lets you read the good ones by their numbers, with arrows, space and f. You learn two-dimensional arrays, a fill with a stack instead of recursion and random numbers that repeat for the same seed.
- A big clock in yabasicA yabasic program shows the time in large block digits and the date in a frame, new every second until you press q. You learn a bitmap font kept in five strings, inkey$ with a timeout as the tick of a loop and the day of the week from a date.
- Where did the space go? A bar chart in yabasicA yabasic program measures the folders of one level with du, sorts them from the largest and draws a bar chart with their sizes and their share of the total. You learn to read the output of a command, to sort two arrays together and to draw bars in half steps.
Pascal
- A menu bar with drop-down boxes in Free PascalA Free Pascal program draws a desktop with a menu bar, drop-down boxes and dialog boxes with shadows, and fills the dialogs with the NAS's memory, load, processor, volumes and RAID groups. You learn to draw boxes with escape codes, read keys with crt and run commands with POpen.
- A greeting screen with large letters in Free PascalA Free Pascal program prints the word NAS in large block letters, greets you by the hour and lists the model, kernel, uptime, load and memory in a framed table. You learn records and dynamic arrays, reading the date with dateutils and drawing a table with box characters.
- A NAS summary in two columns in Free PascalA Free Pascal program reads the CPU, temperatures, load, memory, data volumes and network ports into records and prints them as framed panels in two columns. You learn records, dynamic arrays of records, var parameters and a layout built from lists of lines.
- Cable run: a moving game in Free PascalA Free Pascal game where you steer a network cable round a frame with the arrow keys; it grows with every data packet it picks up, and the wall or its own body ends the run. You learn a game loop with KeyPressed and Delay, records for coordinates and drawing only the cells that change.
- A temperature chart of the NAS in Free PascalA Free Pascal program asks QNAP's getsysinfo for the system, CPU and disk temperatures and draws them as a vertical bar chart with a scale, coloured green, amber or red by level. You learn to build a chart line by line from the top and to treat an empty disk bay as a value of its own.
- A log viewer with colours and search in Free PascalA Free Pascal program shows a log file a screen at a time, colours warnings amber and errors red, scrolls with the arrow and page keys and jumps to the next error with /. You learn to load a file into a TStringList, keep a window of lines on the screen and search with UpperCase and Pos.
Go
- A framed menu in Go with raw keysA Go program puts the terminal into raw mode, draws a framed menu with ANSI escapes and opens boxes with the NAS's memory, volumes, uptime and load. You learn raw keys without extra packages and how to give the terminal back its settings.
- A login greeting with text/templateA Go program fills a text/template with the facts of the NAS (greeting, model, uptime, CPU, load, free space, tip of the day) and frames the result. You learn templates with your own functions and a struct as their data.
- A NAS summary on screen and as JSONA Go program collects the CPU, temperature, memory, data volumes and network ports of the NAS into structs and prints them as a screen with bars, or with -json as JSON. You learn structs with json tags, the flag package and one source of facts for two outputs.
- Packet catcher: a game with goroutinesIn this Go game packets fall down the screen and you catch them with a switch moved by the arrow keys; three missed packets end the game. You learn goroutines, channels and select, with one goroutine for the clock and one for the keys.
- A status page of the NAS with net/httpA Go program serves the model, uptime, CPU, load, memory and data volumes of the NAS as a web page that reloads every 5 seconds, so you can watch it from any browser on your network. You learn net/http, html/template and a clean stop on Ctrl+C.
- Find duplicate files with a pool of workersA Go program finds duplicate files in a folder of the NAS. It compares sizes first, hashes only the files that share a size with SHA-256 in a pool of goroutines, and shows each group with the space its extra copies take. You learn worker pools, channels and sync.WaitGroup.
Bash
- A framed menu in pure BashA Bash script draws a menu in a double frame, moves a highlighted bar with the arrow keys and opens boxes with the NAS's memory, volumes, uptime and load. You learn cursor moves, colours and key reading without any extra tool.
- A greeting at the SSH loginA Bash script greets you by the time of day and shows the NAS model, uptime, CPU, load, the free space of the data volumes and a tip of the day in one framed banner. You learn to frame text with escapes and how to show it at every SSH login on QTS.
- A live dashboard of the NASA Bash script redraws the CPU, load, temperatures, memory, data volumes and network rates of the NAS every 2 seconds until you press q. You learn to wait for a key with a timeout and to compute a rate from two readings of a counter.
- Blink: a memory game with drive-bay LEDsIn this Bash game the four drive-bay LEDs of a drawn NAS light up in a sequence that grows by one each round, and you repeat it with the keys 1 to 4. You learn timed drawing, seeded random numbers and how to ignore keys typed at the wrong moment.
- Copy a folder with a progress barA Bash script copies a folder block by block and shows a progress bar, the bytes copied, the speed and the time left, with an optional speed limit. You learn traps for Ctrl+C, redrawing lines in place and reading keys while a job runs.
- A backup wizard with dialogA Bash script uses dialog to show a checklist of the NAS's share folders, a confirmation, a progress gauge and a summary of what rsync would copy. You learn dialog's boxes, its colour file and how to feed a gauge from a loop.
All projects with their sample data and the test runner (57 KB)