Creating Packages for KPM
This tutorial will guide you through the process of creating your own packages for KPM. By creating packages, you can share your applications or scripts with other Kindle users in a standardized way.
Package Structure
A basic KPM package consists of:
- Your application files
- An installation script (
install.sh
) - An uninstallation script (
uninstall.sh
)
KPM packages are typically distributed as ZIP archives containing these components.
Creating a Basic Package
Follow these steps to create a basic package:
1. Create a Directory Structure
my-package/
├── install.sh
├── uninstall.sh
└── your-files/
├── executable
├── data-files
└── etc.
The install.sh
script handles installation of your package, while uninstall.sh
handles removal.
2. Write the Installation Script
Create an install.sh
script that will handle the installation of your package:
#!/bin/sh
# Example install.sh for KPM package
# Make the installation directory within the KPM packages location
mkdir -p /mnt/us/kpm/packages/bin
# Copy your executable to the packages bin directory
cp /mnt/us/kpm/packages/my-package/my-executable /mnt/us/kpm/packages/bin/
# Make it executable
chmod +x /mnt/us/kpm/packages/bin/my-executable
# Copy any additional files needed
mkdir -p /mnt/us/my-package/data
cp -r /mnt/us/kpm/packages/my-package/data/* /mnt/us/my-package/data/
echo "My package installed successfully!"
3. Write the Uninstallation Script
Create an uninstall.sh
script that will handle removal of your package:
#!/bin/sh
# Example uninstall.sh for KPM package
# Remove the executable
rm /mnt/us/kpm/packages/bin/my-executable
# Remove any additional files
rm -rf /mnt/us/my-package
echo "My package uninstalled successfully!"
4. Make Scripts Executable
Make sure both scripts are executable:
chmod +x install.sh uninstall.sh
5. Create the Package Archive
Create a ZIP archive containing your package:
zip -r my-package.zip install.sh uninstall.sh my-executable data/
Adding Your Package to a Repository
To make your package available to other users:
- Host the ZIP file on a web server or GitHub releases
- Create a package list file that includes your package name
- Set up a mirror configuration that points to your package repository
Example mirror configuration format:
https://your-server.com/packages.conf https://your-server.com/packages/{pkg}/{pkg}.zip
Where:
- The first URL is the package list file
- The second URL is the package download format with
{pkg}
as a placeholder
Best Practices
- Keep your package small and focused
- Test your installation and uninstallation scripts thoroughly
- Make sure all files have appropriate permissions
- Use the standard directory structure when possible:
- Executables go in
/mnt/us/kpm/packages/bin/
- Data files go in
/mnt/us/your-package/
- Include a simple README or help command
Example Package
See the hello package for a simple example of a KPM package.
Testing Your Package
To test your package:
- Build it as described above
- Install it on your device:
kpm -U ./my-package_1.0.0.zip
- Test all the functionality
- Uninstall it to make sure removal works correctly:
kpm -R my-package
Publishing Your Package
To share your package with others:
- Host your
.zip
file on a web server or GitHub as well as a package list - Create a repository index file listing your packages
- Share the repository URL so others can add it to their KPM configuration:
kpm add-repository http://your-repo-url.com/
For more detailed information on package creation, see the Package Development Guide.