mirror of
https://github.com/QSCTech/zjunet.git
synced 2026-01-22 19:54:48 +08:00
add postinst & prerm for build/openwrt
This commit is contained in:
parent
bf0f4262a4
commit
f5a1b9aaaa
@ -30,12 +30,20 @@ Command Line Scripts for ZJU (VPN / WLAN / DNS)
|
||||
|
||||
## Install
|
||||
|
||||
### From source
|
||||
|
||||
```bash
|
||||
git clone https://github.com/QSCTech/zjunet.git
|
||||
cd zjunet
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
## Openwrt
|
||||
|
||||
Install xl2tpd:
|
||||
|
||||
https://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/packages/
|
||||
|
||||
## Dev
|
||||
|
||||
QSCer 可以直接向这个 repo push 而不用发 pull request。
|
||||
|
||||
22
build/openwrt/build.sh
Executable file
22
build/openwrt/build.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
# lib
|
||||
mkdir -p ./debian/usr/lib/zjunet
|
||||
cp ../../lib/* ./debian/usr/lib/zjunet
|
||||
|
||||
# bin
|
||||
mkdir -p ./debian/usr/bin
|
||||
echo '/usr/lib/zjunet/zjunet.sh "$@"' >> ./debian/usr/bin/zjunet
|
||||
chmod +x ./debian/usr/bin/zjunet
|
||||
|
||||
# contorl file
|
||||
mkdir -p debian/DEBIAN
|
||||
find ./debian -type d | xargs chmod 755
|
||||
cp control/* debian/DEBIAN
|
||||
|
||||
# dpkg-deb
|
||||
dpkg-deb --build debian
|
||||
mv debian.deb zjunet_0.1-1_all.deb
|
||||
|
||||
# remove debian/
|
||||
rm -rf ./debian
|
||||
9
build/openwrt/control/control
Normal file
9
build/openwrt/control/control
Normal file
@ -0,0 +1,9 @@
|
||||
Package: zjunet
|
||||
Version: 0.1-1
|
||||
Section: base
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
Depends: xl2tpd (>= 1.3.1), curl
|
||||
Maintainer: Zeno Zeng <zenoofzeng@gmail.com>
|
||||
Description: Command Line Scripts for ZJU
|
||||
This script provides a VPN / WLAN / NEXTHOP for ZJUer.
|
||||
4
build/openwrt/control/postinst
Executable file
4
build/openwrt/control/postinst
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
|
||||
. ${IPKG_INSTROOT}/lib/functions.sh
|
||||
default_postinst $0 $@
|
||||
3
build/openwrt/control/prerm
Executable file
3
build/openwrt/control/prerm
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
. ${IPKG_INSTROOT}/lib/functions.sh
|
||||
default_prerm $0 $@
|
||||
@ -1,223 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Author: Oliver Kurth <oliver.kurth@innominate.com>
|
||||
#
|
||||
# Description:
|
||||
# builds an opkg package from a source tarball using opkg-build. Idea stolen
|
||||
# from Debian dpkg-buildpackage.
|
||||
#
|
||||
# - unpack the source tarball.
|
||||
# - cd to the source distribution, change whatever you need to make the
|
||||
# package compile and work on the ipaq.
|
||||
# - create a directory 'opkg'
|
||||
# - put all files which go to the 'CONTROL' directory of the root of the
|
||||
# installed package into opkg.
|
||||
# - the version (Version field in control) should match the version of the
|
||||
# source tarball, optionally with a digit (eg. -1) appended.
|
||||
# - additionally, put a file there called 'rules' which is a shell script
|
||||
# accepting arguments 'build', 'install' and 'clean'. It can be a
|
||||
# Makefile starting with the line '#!/usr/bin/make -f'
|
||||
# * the build target does things like ./configure and make.
|
||||
# * the install target installs to a temporary directory (make
|
||||
# DESTDIR=/tmp/package) and removes unnecessary items (eg. man pages)
|
||||
# * clean cleans ;-)
|
||||
#
|
||||
# You should run this with fakeroot (1) or as root.
|
||||
# If all went well, you will find a diff file and an *.opk file in the
|
||||
# directory above.
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPTDIR=/usr/local/bin
|
||||
|
||||
SCRIPTNAME=`basename $0`
|
||||
|
||||
opkg_extract_value() {
|
||||
sed -e "s/^[^:]*:[[:space:]]*//"
|
||||
}
|
||||
|
||||
required_field() {
|
||||
field=$1
|
||||
|
||||
value=`grep "^$field:" < $CONTROL/control | opkg_extract_value`
|
||||
if [ -z "$value" ]; then
|
||||
echo "opkg-build: Error: $CONTROL/control is missing field $field" ;
|
||||
PKG_ERROR=1
|
||||
fi
|
||||
echo $value
|
||||
}
|
||||
|
||||
pkg_appears_sane_control() {
|
||||
local pkg_dir=$1
|
||||
|
||||
local owd=`pwd`
|
||||
cd $pkg_dir
|
||||
|
||||
if [ ! -f "$CONTROL/control" ]; then
|
||||
echo "opkg-build: Error: Control file $pkg_dir/$CONTROL/control not found."
|
||||
cd $owd
|
||||
return 1
|
||||
fi
|
||||
|
||||
pkg=`required_field Package`
|
||||
version=`required_field Version | sed 's/.*://;'`
|
||||
arch=`required_field Architecture`
|
||||
required_field Maintainer >/dev/null
|
||||
required_field Description >/dev/null
|
||||
|
||||
if echo $pkg | grep '[^a-z0-9.+-]'; then
|
||||
echo "opkg-build: Error: Package name $name contains illegal characters, (other than [a-z0-9.+-])"
|
||||
PKG_ERROR=1;
|
||||
fi
|
||||
|
||||
local bad_fields=`sed -ne 's/^\([^[:space:]][^:[:space:]]\+[[:space:]]\+\)[^:].*/\1/p' < $CONTROL/control | sed -e 's/\\n//'`
|
||||
if [ -n "$bad_fields" ]; then
|
||||
bad_fields=`echo $bad_fields`
|
||||
echo "opkg-build: Error: The following fields in $CONTROL/control are missing a ':'"
|
||||
echo " $bad_fields"
|
||||
echo "opkg-build: This may be due to a missing initial space for a multi-line field value"
|
||||
PKG_ERROR=1
|
||||
fi
|
||||
|
||||
cd $owd
|
||||
return $PKG_ERROR
|
||||
}
|
||||
|
||||
pkg_appears_sane_scripts() {
|
||||
local pkg_dir=$1
|
||||
|
||||
local owd=`pwd`
|
||||
cd $pkg_dir
|
||||
|
||||
for script in $CONTROL/preinst $CONTROL/postinst $CONTROL/prerm $CONTROL/postrm; do
|
||||
if [ -f $script -a ! -x $script ]; then
|
||||
echo "opkg-build: Error: package script $script is not executable"
|
||||
PKG_ERROR=1
|
||||
fi
|
||||
done
|
||||
|
||||
cd $owd
|
||||
return $PKG_ERROR
|
||||
}
|
||||
|
||||
pkg_dir_abs=`pwd`
|
||||
pkg_dir_base=`basename ${pkg_dir_abs}`
|
||||
|
||||
pkg_dir=.
|
||||
|
||||
[ -d ./CONTROL ] && CONTROL=./CONTROL
|
||||
[ -d ./opkg ] && CONTROL=./opkg
|
||||
if [ -z "$CONTROL" ]; then
|
||||
echo "${SCRIPT_NAME}: Error: Directory $pkg_dir has no opkg or CONTROL subdirectory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! pkg_appears_sane_control $pkg_dir && pkg_appears_sane_control $pkg_dir; then
|
||||
echo "Please fix the above errors and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Package = $pkg"
|
||||
echo "Version = $version"
|
||||
version_up=`echo ${version} | sed "s/\-[0-9]\+//"`
|
||||
echo "Upstream Version = $version_up"
|
||||
pkg_upname=${pkg}-${version_up}
|
||||
echo "Package Name = $pkg_upname"
|
||||
pkg_tarball=${pkg_upname}.tar.gz
|
||||
echo "Tarball Name = $pkg_tarball"
|
||||
|
||||
if [ ! -x ${CONTROL}/rules ]; then
|
||||
echo "${CONTROL}/rules not found or not executable."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# unpack upstream tarball and make diff
|
||||
#
|
||||
if [ -e ../${pkg_tarball} ] ; then
|
||||
(
|
||||
set +e
|
||||
|
||||
cd ..
|
||||
|
||||
rm -rf ${pkg_upname}.tmp
|
||||
rm -rf ${pkg_upname}.orig
|
||||
|
||||
mkdir ${pkg_upname}.tmp
|
||||
cd ${pkg_upname}.tmp
|
||||
echo "unpacking source tarball ${pkg_tarball}"
|
||||
tar zxf ${pkg_dir_abs}/../${pkg_tarball}
|
||||
dir=`find . -maxdepth 1 -name "*" -type d`
|
||||
cnt=`echo $dir | wc -l`
|
||||
if [ ${cnt} != 1 ] ; then
|
||||
echo "Arrghh !!!!"
|
||||
echo "upstream package contains more than one top level directory"
|
||||
echo "giving up..."
|
||||
exit 1
|
||||
fi
|
||||
mv ${dir} ${pkg_upname}.orig
|
||||
mv ${pkg_upname}.orig ..
|
||||
cd ..
|
||||
echo "creating diff"
|
||||
diff -uNr ${pkg_upname}.orig ${pkg_dir_base} > ${pkg}-${version}.diff
|
||||
rm -f ${pkg}-${version}.diff.gz
|
||||
echo "gzipping ${pkg}-${version}.diff"
|
||||
gzip ${pkg}-${version}.diff
|
||||
|
||||
echo "Removing temporary source directorys"
|
||||
rm -rf ${pkg_upname}.tmp
|
||||
rm -rf ${pkg_upname}.orig
|
||||
)
|
||||
fi
|
||||
|
||||
# build package
|
||||
if ! ${CONTROL}/rules build; then
|
||||
echo "Build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# install it to tmp directory
|
||||
if ! ${CONTROL}/rules install; then
|
||||
echo "Install failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# copy contents of control directory
|
||||
mkdir /tmp/${pkg}/CONTROL
|
||||
|
||||
files_required="control"
|
||||
files_optional="preinst postinst prerm postrm"
|
||||
|
||||
for i in ${files_required} ; do
|
||||
file=${CONTROL}/$i
|
||||
|
||||
if [ -e ${file} ] ; then
|
||||
cp $file /tmp/${pkg}/CONTROL
|
||||
else
|
||||
echo "required file ${file} missing"
|
||||
fi
|
||||
done
|
||||
|
||||
for i in ${files_optional} ; do
|
||||
file=${CONTROL}/$i
|
||||
|
||||
if [ -e ${file} ] ; then
|
||||
cp $file /tmp/${pkg}/CONTROL
|
||||
fi
|
||||
done
|
||||
|
||||
# build the opk package
|
||||
owd=`pwd`
|
||||
cd ..
|
||||
opkg-build /tmp/${pkg} || exit 1
|
||||
|
||||
rm -rf /tmp/${pkg}
|
||||
|
||||
cd $owd
|
||||
if ! ${CONTROL}/rules clean; then
|
||||
echo "Clean failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Yep. That's it!
|
||||
exit 0
|
||||
Loading…
x
Reference in New Issue
Block a user