# sdm Script Details
sdm consists of a primary script sdm and several supporting scripts:
* **sdm** — The sdm main program. Collects the command line details and starts the customization process. Also directly handles some commands such as `--burn`, `--shrink`, and `--ppart`.
* **sdm-phase0** — Script run by sdm before nspawn-ing into the IMG file. sdm-phase0 has access to the running Pi system as well as the file system within the IMG file. sdm-phase0 performs several steps:
* Copy files from the running system into the IMG, as specified by command line switches, for use in Phase 1.
* Calls selected Plugins and/or Custom Phase Scripts for Phase 0 if specified.
You can extend what's done in Phase 0 by using a Plugin (preferred) or Custom Phase Script.
* **sdm-phase1** — If `--aptcache` was specified, the IMG is enabled as an apt-cacher-ng client. See apt Cacher NG for details on apt-cacher-ng.
* App installation is accomplished using the Bootset and 1piboot for details. This directory will also be installed onto the SD Card in /usr/local/sdm/1piboot.
If enabled, the custom scripts in 1piboot/0*-*.sh are run when the system first boots, and can perform system tuning improvements. The custom scripts are enabled by the switch `--bootscripts` on either the command line that builds the IMG, or on the `sdm --burn` command when burning a new SD card. The scripts can do anything you want, of course, although having several small focused scripts is probably preferable for your sanity over the long term.
* **sdm-cparse** — Helper script that defines some sdm-internal bash functions.
* **sdm-cportal** — Implements the Captive Portal for `--loadlocal wifi`
* **sdm-cmdsubs** — Implements functions used by sdm to process `--burn`, `--shrink`, and `--ppart` commands
* **sdm-logmsg** — Helper script for the Captive Portal.
* **sdm-customphase** — Custom Phase Script skeleton. Use this as a starting point to build your Custom Phase Script
* **sdm-readparams** — Helper script that reads the sdm configuration file creating bash variables, and sources sdm-cparse to make its functions available. sdm-readparams is copied to /etc/sdm in an IMG being customized, and is called as needed by sdm, Plugins, and Custom Phase Scripts.
* **sdm-apt-cacher** — Configures and installs apt-cacher-ng. This is optional, but highly recommended, especially with slower internet connections. sdm will use this with the `--aptcache` command switch. apt Cacher NG for details.
* **plugins/sdm-plugin-template** — Plugin skeleton. Use this as a starting point to build your Plugin.
* **plugins/*all other files*** — Plugins that can be used with the `--plugin` switch.