2 # A script to replace /bin/busybox and create missing symlinks to its applets.
4 # The target directories for BusyBox' applets are defined in the "applets" file.
5 # This script will only create symbolic links when 1) they do not already exist
6 # in the filesystem, and 2) the BusyBox binary supports the applet. A list of
7 # all made symbolic links is written out to the file "busybox-power.symlinks",
8 # which will be used during uninstallation of busybox-power.
10 # NB The BusyBox binary needs to support the install applet.
12 # By Dennis Groenen <tj.groenen@gmail.com>
15 # Last updated: 08-24-2012 (MM-DD-YYYY)
18 INSTALLDIR="/opt/busybox-power"
19 EXECPWR="$INSTALLDIR/busybox.power"
22 # Load shared functions
23 source $INSTALLDIR/functions
25 # Check whether the applets file exists
27 if test ! -e $INSTALLDIR/applets; then
28 echo "error: cannot find list of defined applets"
33 # Check whether symlinks have been made before
34 CHECK_SYMLINKSFILE() {
35 if test -e $INSTALLDIR/busybox-power.symlinks; then
36 echo "error: symlinks already seem to be made?"
37 echo " this script is not supposed to be ran twice"
42 # Create MD5 hashes of relevant binaries
44 $EXECPWR md5sum $INSTALLDIR/busybox.power | $EXECPWR awk '{ print $1 }' \
45 > $INSTALLDIR/busybox.power.md5
46 $EXECPWR md5sum /bin/busybox | $EXECPWR awk '{ print $1 }' \
47 > $INSTALLDIR/busybox.original.md5
50 # Backup the original BusyBox binary
54 # Scratchbox does not ship with BusyBox by default
55 if test -e /bin/busybox; then
56 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
59 # Check whether busybox-power isn't somehow installed already
60 INSTBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.power.md5`
61 ORIGBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.original.md5`
62 if test "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
63 echo "warning: installed busybox binary matches the binary"
64 echo " that is to be installed"
65 if ! test -e $INSTALLDIR/busybox.original; then
66 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
68 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
74 # Overwrite the installed binary with the enhanced binary
76 $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
79 # Create missing symlinks to the enhanced binary
81 # Load defined BusyBox applets
82 source $INSTALLDIR/applets
84 # Get a list of supported applets by busybox-power
85 if test -d /tmp/busybox-power; then
86 $EXECPWR rm -Rf /tmp/busybox-power; fi
87 $EXECPWR mkdir -p /tmp/busybox-power
88 $EXECPWR --install -s /tmp/busybox-power
89 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/applets_supported
90 $EXECPWR rm -Rf /tmp/busybox-power
92 # Prepare file that will keep track of installed symlinks by busybox-power
93 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
94 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
95 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
97 # Walk through all possible destinations
98 for DESTDIR in $DESTINATIONS; do
99 # Enable us to see all entries in $DESTINATION as variables
100 eval "APPLICATIONS=\$$DESTDIR"
102 # Set destination directory accordingly
118 # Keep track of installed symlinks per destination
119 SYMLINKS="$DESTDIR=\""
121 ECHO_VERBOSE "\nSymlinking applets in $DIR"
122 # Walk through all applications from the current destination
123 for APP in $APPLICATIONS; do
124 # The following code is executed for all applets in the current destination
125 if test ! -e $DIR/$APP; then
126 # Check whether the applet is supported by the busybox binary
127 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/applets_supported`; then
128 ECHO_VERBOSE "Symlinking: /bin/busybox -> $DIR/$APP"
129 $EXECPWR ln -s /bin/busybox $DIR/$APP
130 SYMLINKS="$SYMLINKS $APP"
135 # Write out installed symlinks
136 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
139 $EXECPWR rm $INSTALLDIR/applets_supported
143 ECHO_VERBOSE "busybox-power: verbose mode"
144 ECHO_VERBOSE " binary: $EXECPWR"
145 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
146 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
151 if test "$ENVIRONMENT" != "SDK"; then