What is required to create a new ipk package that can be installed using opkg from the standard openwrt repos?

I wrote a script (that Ive shared on the forums here a few times) for setting up and controlling an on-router plex media server instance. It should work for any devices with an ARMv7 or ARMv8 CPU and a USB port (for an external HDD) and sufficient RAM (it uses up ~100 MB).

Everything required for this is implemented in the init script (to be placed at /etc/init.d/plexmediaserver)...this is the only thing that needs to be "installed" to make things work (well not quite...a few other openwrt packages are needed too: unzip curl squashfs-tools-mksquashfs). The init script will then setup UCI variables and allows control via service plexmediaserver start/stop and allows for auto-starting on boot via service plexmediaserver enable/disable. It also allows for updating to a new plex version via service plexmediaserver update.

I dont think it will be a particuarly complicated package to set up...install the init script, define a few dependent packages and its good to go. Im just not sure of the specifics....are there any good guides for this sort of thing?

You’ll probably want to use this wiki guide as a base. A good reference I found was looking at the Adblock Makefile package from the package repo.

2 Likes

Right, adblock is pretty much as simple Makefile as it can be...

I made a script I use to create my ipk. It's a bit rough but it does the job.

#!/bin/bash 
# 
# File:   make_ipk.sh

set +x

pkey=GsIZtZfX2xM1Sh
sig=RQRCSpAABCA+29B+GsIZtZfX2xM1ShBaJhwfGL8GWH4YY4PgWR5verskITNkQtPIU4nmbjX+6BetiQn1VPtU07ZpT0uRaXVaLzncdafRZiM5+kyFmSPT59wS28R8Jcid9OH0Rxbk

myhome=

while getopts "v:d:" opt;
do
    case "${opt}" in
        v) version=${OPTARG};;
        d) directory=${OPTARG};;
    esac
done

if [ -z "$version" ]
then
      echo "Version not set, use parameter -v <version>"
      exit 1;
fi

if [ -z "$directory" ]
then
      echo "Output path for ipk not set, use parameter -d <path>"
      exit 1;
fi

# Remove the directory if it already exists
if [ -d "$directory" ] 
then 
	rm -r $directory
fi

mkdir $directory
cd $directory
mkdir -p usr/sbin
mkdir -p usr/libexec
mkdir -p etc/myapp/scripts
mkdir -p etc/myapp/certs
mkdir -p etc/opkg

cp -rf /home/chris/NetBeansProjects/myapp/dist/Release/GNU_OpenWRT-Linux/myapp usr/sbin/
cp -rf /home/chris/source/files/www www
cp -rf /home/chris/source/files/etc/myapp/site etc/myapp
cp -rf /home/chris/source/files/etc/myapp/scripts etc/myapp
cp -rf /home/chris/source/files/etc/myapp/certs etc/myapp
cp -rf /home/chris/source/files/usr/libexec usr


# copy certificates
cp /home/chris/source/files/etc/myapp/certs/ca.crt etc/myapp/certs
cp /home/chris/source/files/etc/myapp/certs/client.crt etc/myapp/certs
cp /home/chris/source/files/etc/myapp/certs/client.key etc/myapp/certs


mkdir CONTROL

echo "Package: myapp" >> CONTROL/control
echo "Version:  $version" >> CONTROL/control
echo "Description: myapp Sample" >> CONTROL/control
echo "Section: extras" >> CONTROL/control
echo "Priority: optional" >> CONTROL/control
echo "Maintainer: admin@myapp.com" >> CONTROL/control
echo "License: CLOSED" >> CONTROL/control
echo "Architecture: mipsel_24kc" >> CONTROL/control
echo "OE: myapp" >> CONTROL/control
echo "Homepage: www.myapp.com" >> CONTROL/control
echo "Depends: libc, libuci, libubus, libubox, libsqlite3, libgcrypt, libgnutls" >> CONTROL/control

echo "#!/bin/sh" >> CONTROL/preinst
echo "#Add your scripts here" >> CONTROL/preinst
echo "" >> CONTROL/preinst

chmod +x CONTROL/preinst

echo "#!/bin/sh" >> CONTROL/postinst
echo "#Add your scripts here" >> CONTROL/postinst
echo "" >> CONTROL/postinst
echo "uci set system.@system[0].log_remote='0'" >> CONTROL/postinst
echo "uci commit system" >> CONTROL/postinst
echo "uci set myapp.@main[0].version=\$version" >> CONTROL/postinst
echo "fi" >> CONTROL/postinst
echo "uci commit myapp" >> CONTROL/postinst
echo "" >> CONTROL/postinst
echo "/etc/init.d/myapp restart" >> CONTROL/postinst

chmod +x CONTROL/postinst

echo "#!/bin/sh" >> CONTROL/prerm
echo "#Add your scripts here" >> CONTROL/prerm
echo "" >> CONTROL/prerm
chmod +x CONTROL/prerm

echo "#!/bin/sh" >> CONTROL/postrm
echo "#Add your scripts here" >> CONTROL/postrm
echo "" >> CONTROL/postrm
chmod +x CONTROL/postrm

~/source/scripts/ipkg-build ./

#
#  Now we can create the repository files
#

export PATH="$PATH:/home/chris/source/staging_dir/host/bin"
echo "myapp repository: private key ${pkey}" >> myapp.key
echo "${sig}=" >> myapp.key

mkdir repo
mv *.ipk repo
cd repo
~/source/scripts/ipkg-make-index.sh  . 2>/dev/null > Packages.manifest
grep -vE '^(Maintainer|LicenseFiles|Source|Require)' Packages.manifest > Packages
gzip -9nc Packages > Packages.gz
usign -S -m Packages -s ../myapp.key

rm Packages
rm Packages.manifest
rm ../myapp.key