赞
踩
bash build.sh
然后产生在RPMS/mips64el下
.目录结构如下
- #tree .
- .
- |-- BUILD
- |-- BUILDROOT
- |-- RPMS
- | |-- mips64el
- | `-- 123est-1.0.0-1001.mips64el.rpm
- |-- SOURCES
- |-- SPECS
- | `-- 123test.spec
- |-- SRPMS
- |-- build.sh
- `-- test
- #cat build.sh
-
- function build_rpm() {
- PACKDIR="$PWD/packdir"
- INSTALLDIR="/opt/test123"
- mkdir -p ${PACKDIR}${INSTALLDIR}
- version=1.0.0
- release=1001
- cp test $PACKDIR/opt/test123/test
- rpmbuild -bb "`pwd`/SPECS/123test.spec" --buildroot="$PACKDIR" --define "VERSION $version" --define "RELEASE $release" --define "_topdir $PWD" --target=mips64el
- }
- build_rpm
- #cat SPECS/123test.spec
-
-
- Summary: 123test
- Name: 123test
- Version: %VERSION
- Source: $RPM_SOURCE_DIR/
- Release: %RELEASE
- Vendor: xl 123 company
- License: copyright to xl 123
- Group: Application/system
-
- %description
- 123 test
-
- %define install_dir /opt/123test
- %define main_process_name test
- %prep
- echo "note : prep [$1]"
- %pre
- echo "note : pre [$1]"
- %clean
- echo "note : clean [$1]"
- [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "$RPM_BUILD_ROOT"
-
- %files
-
- %defattr(755,root,root)
- %attr(4544,root,root) %{install_dir}/test
-
- %post
- echo "note : post [$1]"
- run() {
- # run app
- nohup $install_dir/$main_process_name >/dev/null 2>&1 &
- echo "========post run========="
- }
-
- case "$1" in
- 0) #uninstall
- echo "error : post called with uninstall argument"
- exit -1
- ;;
- 1|2) #install | upgrade
- echo "note : post called with install | upgrade argument"
- run
- exit 0
- ;;
- *)
- echo "error : post called with unknown argument"
- exit -1
- ;;
- esac
-
- %preun
- echo "note : preun [$1]"
- stoprpm() {
- echo "stop rpm"
- ps -ef | grep rpm | grep 360safe | grep '-' | awk '{print $2}' | xargs -I {} kill -9 {} > /dev/null 2>&1
- exit -1
- }
- check_mima() {
- ls -lh /proc/self/fd
- read -sp "0 test:" mima 0<&1
- echo "mimashi : $mima"
- ls -lh /proc/self/fd
- }
- get_general_user() {
- names=$(who | awk '{print $1}')
- for name in ${names}
- do
- if [[ ${name} != 'root' ]]; then
- break
- fi
- done
- echo ${name}
- }
-
- case "$1" in
- 0) #uninstall
- echo "note : preun called with uninstall argument"
- check_mima
- exit 0
- ;;
- 1|2) #install | upgrade
- echo "note : preun called with install | upgrade argument, do nothing"
- exit 0
- ;;
- *)
- echo "error : preun called with unknown argument"
- exit -1
- ;;
- esac
-
- %postun
- echo "note : postun [$1]"
- rm_driver()
- {
- dfile=$(lsmod | grep test_base)
- if [ x == "$dfile"x ];then
- echo "driver module removed"
- else
- echo "remove driver module"
- rmmod -f test_base
- echo "driver module removed"
- fi
- }
- remove_all() {
- if [ -d "/opt/123test" ]; then
- rm -rf /opt/123test
- fi
- if [ -f "/usr/bin/123test" ]; then
- rm -f /usr/bin/123test
- fi
- if [ -f "/usr/share/applications/start123.desktop" ]; then
- rm -f /usr/share/applications/start123.desktop
- fi
- if [ -f "/etc/xdg/autostart/autostart123.desktop" ]; then
- rm -f /etc/xdg/autostart/autostart123.desktop
- fi
- if [ -f "/etc/init.d/$service_name" ];then
- rm -f /etc/init.d/$service_name
- fi
- if [ -L "/etc/rc2.d/S10$service_name" ];then
- unlink /etc/rc2.d/S10$service_name
- fi
- if [ -L "/etc/rc3.d/S10$service_name" ];then
- unlink /etc/rc3.d/S10$service_name
- fi
- if [ -L "/etc/rc4.d/S10$service_name" ];then
- unlink /etc/rc4.d/S10$service_name
- fi
- if [ -L "/etc/rc5.d/S10$service_name" ];then
- unlink /etc/rc5.d/S10$service_name
- fi
- }
-
- case "$1" in
- 0) #uninstall
- echo "note : postun called with uninstall argument"
- remove_all
- rm_driver
- exit 0
- ;;
- 1|2) #install | upgrade
- echo "note : postun called with install | upgrade argument, do nothing"
- exit 0
- ;;
- *)
- echo "error : postun called with unknown argument"
- exit -1
- ;;
- esac

-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。