|
| 1 | +# UPK DEB Packaging Guide |
| 2 | + |
| 3 | +This guide explains how to build a DEB package for UPK (Ubuntu Package Kit) using PyInstaller to create a standalone executable. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The packaging process creates a Python package and packages it into a DEB file that can be installed on Ubuntu/Debian systems. This approach has several advantages: |
| 8 | + |
| 9 | +- **Small package size**: Only includes source code and metadata (~30KB) |
| 10 | +- **System integration**: Uses system Python and dependencies |
| 11 | +- **Easy installation**: Users can install with `sudo dpkg -i upk-{version}.deb` |
| 12 | +- **CLI-optimized**: No desktop integration (suitable for command-line tools) |
| 13 | +- **Maintainable**: Standard Python package structure |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- Python 3.10 or higher |
| 18 | +- pip |
| 19 | +- dpkg-deb (usually pre-installed on Ubuntu/Debian) |
| 20 | + |
| 21 | +## Building the DEB Package |
| 22 | + |
| 23 | +### Quick Start |
| 24 | + |
| 25 | +1. Make the build script executable: |
| 26 | + ```bash |
| 27 | + chmod +x build.sh |
| 28 | + ``` |
| 29 | + |
| 30 | +2. Run the build script: |
| 31 | + ```bash |
| 32 | + ./build.sh |
| 33 | + ``` |
| 34 | + |
| 35 | +3. Install the package: |
| 36 | + ```bash |
| 37 | + sudo dpkg -i upk-{version}.deb |
| 38 | + ``` |
| 39 | + |
| 40 | +### What the Build Script Does |
| 41 | + |
| 42 | +1. **Copies source files** to the proper Python package structure |
| 43 | +2. **Creates a wrapper script** that executes the Python module |
| 44 | +3. **Creates the DEB package structure** with proper directory layout |
| 45 | +4. **Generates package metadata** including control file and documentation |
| 46 | +5. **Builds the final DEB package** using dpkg-deb |
| 47 | + |
| 48 | +## Package Contents |
| 49 | + |
| 50 | +The resulting DEB package includes: |
| 51 | + |
| 52 | +- **Executable**: `/usr/bin/upk` - The main UPK application |
| 53 | +- **Documentation**: `/usr/share/doc/upk/` - Package documentation and license |
| 54 | +- **Post-installation script**: Handles setup tasks after installation |
| 55 | + |
| 56 | +## Package Dependencies |
| 57 | + |
| 58 | +### Runtime Dependencies |
| 59 | +- `python3 (>= 3.10)` - Python interpreter (for compatibility) |
| 60 | +- `python3-click (>= 8.1.0)` - Command-line interface library |
| 61 | +- `python3-rich (>= 13.0.0)` - Rich text formatting library |
| 62 | + |
| 63 | +### Recommended Packages |
| 64 | +- `apt` - APT package manager |
| 65 | +- `snapd` - Snap package manager |
| 66 | +- `flatpak` - Flatpak package manager |
| 67 | +- `pacstall` - Pacstall package manager |
| 68 | +- `am` - AppMan package manager |
| 69 | + |
| 70 | +## Installation |
| 71 | + |
| 72 | +### Install the Package |
| 73 | +```bash |
| 74 | +sudo dpkg -i upk-{version}.deb |
| 75 | +``` |
| 76 | + |
| 77 | +### Fix Missing Dependencies (if needed) |
| 78 | +```bash |
| 79 | +sudo apt install -f |
| 80 | +``` |
| 81 | + |
| 82 | +### Verify Installation |
| 83 | +```bash |
| 84 | +upk --help |
| 85 | +``` |
| 86 | + |
| 87 | + |
| 88 | +## Uninstallation |
| 89 | + |
| 90 | +```bash |
| 91 | +sudo dpkg -r upk |
| 92 | +``` |
| 93 | + |
| 94 | +## Package Structure |
| 95 | + |
| 96 | +``` |
| 97 | +upk-debian/ |
| 98 | +├── DEBIAN/ |
| 99 | +│ ├── control # Package metadata |
| 100 | +│ ├── postinst # Post-installation script |
| 101 | +│ └── postrm # Post-removal script |
| 102 | +├── usr/ |
| 103 | +│ ├── bin/ |
| 104 | +│ │ └── upk # Main executable |
| 105 | +│ └── share/ |
| 106 | +│ └── doc/ |
| 107 | +│ └── upk/ # Documentation |
| 108 | +│ ├── changelog.Debian |
| 109 | +│ ├── copyright |
| 110 | +│ └── README.Debian |
| 111 | +``` |
| 112 | + |
| 113 | +## Troubleshooting |
| 114 | + |
| 115 | +### Build Script Issues |
| 116 | + |
| 117 | +**PyInstaller not found**: The script automatically creates a virtual environment and installs PyInstaller. |
| 118 | + |
| 119 | +**Missing dependencies**: The script installs click and rich dependencies in the virtual environment. |
| 120 | + |
| 121 | +**Permission errors**: Ensure you're not running as root during the build process. |
| 122 | + |
| 123 | +### Installation Issues |
| 124 | + |
| 125 | +**Missing dependencies**: Run `sudo apt install -f` to install missing dependencies. |
| 126 | + |
| 127 | +**Architecture mismatch**: The package is built for amd64 architecture. For other architectures, you'll need to build on the target system. |
| 128 | + |
| 129 | +### Runtime Issues |
| 130 | + |
| 131 | +**Executable not found**: Ensure the package was installed correctly with `which upk`. |
| 132 | + |
| 133 | +**Missing system tools**: Install recommended packages for full functionality: |
| 134 | +```bash |
| 135 | +sudo apt install apt snapd flatpak pacstall |
| 136 | +``` |
| 137 | + |
| 138 | +## Customization |
| 139 | + |
| 140 | +### Package Metadata |
| 141 | + |
| 142 | +Edit the following in `build.sh`: |
| 143 | + |
| 144 | +- **Maintainer information**: Update the maintainer name and email in the control file |
| 145 | +- **Package version**: Modify the version number |
| 146 | +- **Description**: Update the package description |
| 147 | +- **Dependencies**: Adjust dependencies based on your requirements |
| 148 | + |
| 149 | +### Build Configuration |
| 150 | + |
| 151 | +- **PyInstaller options**: Modify PyInstaller flags in the build command |
| 152 | +- **Included files**: Update the `--add-data` flags to include additional files |
| 153 | +- **Package structure**: Modify the directory structure as needed |
| 154 | + |
| 155 | +## Development |
| 156 | + |
| 157 | +### Testing the Build Process |
| 158 | + |
| 159 | +1. Clean previous builds: |
| 160 | + ```bash |
| 161 | + rm -f upk-{version}.deb dist/upk build/ -rf |
| 162 | + ``` |
| 163 | + |
| 164 | +2. Rebuild: |
| 165 | + ```bash |
| 166 | + ./build.sh |
| 167 | + ``` |
| 168 | + |
| 169 | +3. Test installation in a clean environment or virtual machine |
| 170 | + |
| 171 | +### Debugging |
| 172 | + |
| 173 | +- **PyInstaller warnings**: Check the build output for any warnings |
| 174 | +- **Package contents**: Use `dpkg-deb --contents upk-{version}.deb` to verify contents |
| 175 | +- **Installation logs**: Check system logs during installation |
| 176 | + |
| 177 | +## Security Considerations |
| 178 | + |
| 179 | +- The executable is self-contained and doesn't require additional Python packages |
| 180 | +- The post-installation script runs with root privileges during installation |
| 181 | +- All dependencies are bundled, reducing attack surface from external packages |
| 182 | + |
| 183 | +## Performance |
| 184 | + |
| 185 | +- **Package size**: ~30KB (source code only) |
| 186 | +- **Startup time**: Standard Python startup time |
| 187 | +- **Memory usage**: Standard Python memory usage |
| 188 | +- **Dependencies**: Uses system-installed packages |
| 189 | + |
| 190 | +## Support |
| 191 | + |
| 192 | +For issues with the DEB package: |
| 193 | + |
| 194 | +1. Check the troubleshooting section above |
| 195 | +2. Verify your system meets the requirements |
| 196 | +3. Test with a clean installation |
| 197 | +4. Report issues with build output and system information |
| 198 | + |
| 199 | +## License |
| 200 | + |
| 201 | +The DEB packaging scripts and documentation are provided under the same license as the main UPK project. |
0 commit comments