source: pkgtools/installpkg-0.2

Last change on this file was aaba1da, checked in by Paweł Foremski <pjf@…>, 11 years ago

added installpkg from LT 2.0

  • Property mode set to 100755
File size: 2.3 KB
Line 
1#!/bin/bash
2#
3# installpkglocal
4# Simple tool which installs package locally
5#
6# This file is licensed under GNU GPL 2, for full license text see file
7# called "COPYING" in main distribution directory
8#
9
10readonly VARDIR=var/pkg
11
12[ "$1" = "nosu" ] && { NOSU=1; shift; }
13
14[ -z "$1" ] && { echo "Usage: $0 package.pkg.tar.gz [ root_dir ]" >&2; exit 1; }
15[ -f "$1" ] || { echo "$1: no such file" >&2; exit 1; }
16
17[ -z "$NOSU" ] && [ "`id -u`" != 0 ] && {
18        if [ -n "`which su 2>/dev/null`" ]; then
19                echo "You must be root to do that. Using su..." >&2
20                su -c "sh $0 $*"
21                exit $?
22        else
23                echo -n "Warning: no 'su' found, but required. [Enter] to continue, [Ctrl+C] to stop..."
24                read foo
25                NOSU=1
26        fi
27}
28
29cd `dirname $1` || exit 1
30pkgdir=`pwd`
31pkgname=`basename $1`
32pkg="$pkgdir/$pkgname"
33
34case "`basename $0`" in
35        installpkg|installpkg-0.2)
36                title="Installing"
37                call="install"
38                ;;
39        upgradepkg|upgradepkg-0.2)
40                title="Upgrading"
41                call="upgrade"
42        ;;
43        *)
44                echo "Call me as installpkg/upgradepkg"
45                exit 1
46        ;;
47esac
48
49rootdir="${2:-$FB_ROOTDIR}"
50
51echo "Installing $pkgname in $rootdir"
52cd $OLDPWD || exit 1
53cd $rootdir || exit 1
54
55tar -xzf $pkg .PKGINFO 2> /dev/null && {
56        echo -n "Fetching package information: "
57        . .PKGINFO 2>/dev/null
58        echo "$pkgname $pkgver (build $builddate)"
59}
60
61tar -xzf $pkg .INSTALL 2> /dev/null && {
62        if [ "$NOSU" = "1" ]; then
63                echo "WARNING: be sure to run pre_$call() and post_$call() functions from following file:"
64                echo "---------------------------------------------------------------------------------------"
65                cat .INSTALL
66                echo "---------------------------------------------------------------------------------------"
67        else
68                echo "Running pre_$call in chroot `pwd`"
69                /usr/sbin/chroot . /bin/bash .INSTALL pre_$call $pkgver || { echo "Error - aborting" >&2; exit 1; }
70                runpostinstall=1
71        fi
72}
73
74echo "Extracting..."
75tar -xzf $pkg || { echo "Error - aborting" >&2; exit 1; }
76
77[ "$runpostinstall" = 1 ] && {
78        echo "Running post_$call in chroot `pwd`"
79        /usr/sbin/chroot . /bin/bash .INSTALL post_$call $pkgver || echo "WARNING: ERROR" >&2
80}
81
82echo "Registering package in local pkg database"
83mkdir -p "$VARDIR/$pkgname"
84echo "$pkgver" > "$VARDIR/$pkgname/installed"
85cp -f .PKGINFO "$VARDIR/$pkgname/PKGINFO"
86cp -f .FILELIST "$VARDIR/$pkgname/FILELIST"
87
88echo "Cleanup"
89rm -f ./.* 2> /dev/null
90
91echo "Done"
Note: See TracBrowser for help on using the repository browser.