add (un)installation support for Harmattan
[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       if test -e /proc/component_version; then
22         PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
23       else
24         PROD=$(/usr/bin/sysinfoclient --get /component/product | $EXECPWR awk '{ print $3 }')
25       fi
26
27       case $PROD in
28         RX-51)
29           ENVIRONMENT="FREMANTLE"
30           ;;
31         RM-680|RM-696)
32           ENVIRONMENT="HARMATTAN"
33           ;;
34         *)
35           # Unsupported, use the least strict environment (SDK)
36           ENVIRONMENT="SDK"
37           ;;
38       esac
39     fi
40 }
41
42 # Check whether the user is root
43 CHECK_ROOT() {
44     if test "`$EXECPWR id -u`" -ne 0; then
45       echo "error: you're not running me as root"
46       exit 1
47     fi
48 }
49
50 # Get the version string of the package providing /bin/busybox
51 GETBBVERSION() {
52     # XXX We assume the package "busybox" provides /bin/busybox
53     /usr/bin/dpkg -s busybox | $EXECPWR awk '/^Version:/ {print $2}'
54 }
55
56 # Get the current device mode in Harmattan. Returns "open" or "normal"
57 GETDEVICEMODE() {
58     /usr/bin/accli -I | $EXECPWR awk '/^Current mode:/ {print $3}'
59 }
60
61 # Get the enforcement status of aegis' source origin check. Returns "1" when
62 # the check is active, otherwise "0"
63 GETORIGINCHECK_STATUS() {
64     /usr/sbin/aegisctl | $EXECPWR sed 's/,.*//' | $EXECPWR grep "s" | $EXECPWR wc -l
65 }
66