6d532b69a79f1ecd129d03816f79e6a7723db8e1
[busybox-power] / debian / scripts / functions
1 #!/bin/sh
2 # This file contains functions that are used in multiple other scripts, i.e.
3 # shared functions. The purpose of centralising these, is to deduplicate code
4 # and increase maintainability
5 #
6 # By Dennis Groenen <tj.groenen@gmail.com>
7 # GPLv3 licensed
8 #
9
10 # Verbose-aware echo
11 ECHO_VERBOSE() {
12   if test $VERBOSE == 1; then 
13     echo -e "$1"; fi
14 }
15
16 # Detect the current environment
17 CHECK_ENV() {
18     if test -d /scratchbox; then
19       ENVIRONMENT="SDK"
20     else
21       PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
22       case $PROD in
23         RX-51)
24           ENVIRONMENT="FREMANTLE"
25           ;;
26         *)
27           # Unsupported, use the least strict environment (SDK)
28           ENVIRONMENT="SDK"
29           ;;
30       esac
31     fi
32 }
33
34 # Check whether I'm running standalone
35 CHECK_STANDALONE() {
36     #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
37     if ! lsof /var/lib/dpkg/lock >> /dev/null; then 
38       echo "error: you're running me as a stand-alone application"
39       echo "  do not do this, I will be called automatically when"
40       echo "  required by busybox-power"
41       exit 1
42     fi
43 }
44
45 # Check whether the user is root
46 CHECK_ROOT() {
47     if test "`$EXECPWR id -u`" -ne 0; then
48       echo "error: you're not running me as root, aborting"
49       echo "  also, DO NOT run me as a stand-alone application"
50       echo "  I will be called automatically when required by"
51       echo "  busybox-power"
52       exit 1
53     fi
54 }
55
56 # Get the version string of the package providing /bin/busybox
57 GETBBVERSION() {
58     # XXX We assume the package "busybox" provides /bin/busybox
59     /usr/bin/dpkg -s busybox | awk '/^Version:/ {print $2}'
60 }