don't restore backup binary if busybox has been modified
[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 # Last updated: 08-24-2012 (MM-DD-YYYY)
10
11
12 # Verbose-aware echo
13 ECHO_VERBOSE() {
14   if test $VERBOSE == 1; then 
15     echo -e "$1"; fi
16 }
17
18 # Detect the current environment
19 CHECK_ENV() {
20     if test -d /scratchbox; then
21       ENVIRONMENT="SDK"
22     else
23       PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
24       case $PROD in
25         RX-51)
26           ENVIRONMENT="FREMANTLE"
27           ;;
28         *)
29           # Unsupported, use the least strict environment (SDK)
30           ENVIRONMENT="SDK"
31           ;;
32       esac
33     fi
34 }
35
36 # Check whether I'm running standalone
37 CHECK_STANDALONE() {
38     #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
39     if ! lsof /var/lib/dpkg/lock >> /dev/null; then 
40       echo "error: you're running me as a stand-alone application"
41       echo "  do not do this, I will be called automatically when"
42       echo "  required by busybox-power"
43       exit 1
44     fi
45 }
46
47 # Check whether the user is root
48 CHECK_ROOT() {
49     if test "`$EXECPWR id -u`" -ne 0; then
50       echo "error: you're not running me as root, aborting"
51       echo "  also, DO NOT run me as a stand-alone application"
52       echo "  I will be called automatically when required by"
53       echo "  busybox-power"
54       exit 1
55     fi
56 }