1 #!/opt/busybox-power/busybox.power sh
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>
16 INSTALLDIR="/opt/busybox-power"
17 EXECPWR="$INSTALLDIR/busybox.power"
18 DISTBIN="/bin/busybox.distrib"
23 INSTBINARY_SHA1=`$EXECPWR sha1sum $EXECPWR | $EXECPWR awk '{ print $1 }'`
24 ORIGBINARY_SHA1=`$EXECPWR sha1sum /bin/busybox | $EXECPWR awk '{ print $1 }'`
26 # Load shared functions
27 source $INSTALLDIR/functions
29 # Check whether the applets file exists
31 if test ! -e $INSTALLDIR/applets; then
32 echo "error: cannot find list of defined applets"
37 # Check whether symlinks have been made before
38 CHECK_SYMLINKSFILE() {
39 if test -e $INSTALLDIR/busybox-power.symlinks; then
40 ECHO_VERBOSE "symlinks are already made, skipping creation"
45 # Backup the original BusyBox binary
47 if test ! -e /bin/busybox; then
48 # Scratchbox does not ship with BusyBox by default
52 if test "$INSTBINARY_SHA1" != "$ORIGBINARY_SHA1"; then
53 $EXECPWR cp -a /bin/busybox $DISTBIN
54 $EXECPWR sha1sum $DISTBIN | $EXECPWR awk '{ print $1 }' \
55 > $INSTALLDIR/busybox.distrib.sha1
56 GETBBVERSION > $INSTALLDIR/busybox.distrib.version
60 # Rollback procedure for Harmattan based devices
61 ROLLBACK_HARMATTAN() {
62 echo -e "\nWarning: an error has occured! Rolling back..."
63 $EXECPWR cp -af $TMPBINBAK /bin/busybox
64 $EXECPWR cp -a $TMPHASHBAK /var/lib/aegis/refhashlist
65 echo "End of roll-back"
69 # Overwrite the installed binary with the enhanced binary
70 # dpkg-divert is disallowed on Harmattan, do not use it there!
74 /usr/sbin/dpkg-divert --local --divert $DISTBIN /bin/busybox
75 $EXECPWR cp -f $EXECPWR /bin/busybox
78 TMPHASHBAK=`$EXECPWR mktemp`
79 TMPBINBAK=`$EXECPWR mktemp`
80 ORIGINCHECK=`GETORIGINCHECK_STATUS`
82 # Useful information for Harmattan-based devices
83 ECHO_VERBOSE "refhashlist backup: $TMPHASHBAK"
84 ECHO_VERBOSE "busybox backup: $TMPBINBAK"
85 ECHO_VERBOSE "instbinary: $INSTBINARY_SHA1"
86 ECHO_VERBOSE "origbinary: $ORIGBINARY_SHA1"
87 ECHO_VERBOSE "device mode: $DEVICEMODE"
88 ECHO_VERBOSE "origincheck: $ORIGINCHECK"
90 if test $ORIGINCHECK -eq 1; then
91 SETORIGINCHECK_STATUS 0; fi
93 $EXECPWR cp -a /bin/busybox $TMPBINBAK || exit 1
94 $EXECPWR cp -a /var/lib/aegis/refhashlist $TMPHASHBAK || exit 1
95 $EXECPWR cp -af $EXECPWR /bin/busybox || ROLLBACK_HARMATTAN
96 $EXECPWR sed -i "s/$ORIGBINARY_SHA1/$INSTBINARY_SHA1/" /var/lib/aegis/refhashlist || ROLLBACK_HARMATTAN
97 /usr/bin/accli -c tcb-sign -F /var/lib/aegis/refhashlist < /var/lib/aegis/refhashlist || ROLLBACK_HARMATTAN
98 /usr/sbin/validator-init
100 if test $ORIGINCHECK -eq 1; then
101 SETORIGINCHECK_STATUS 1; fi
103 $EXECPWR rm $TMPBINBAK
104 $EXECPWR rm $TMPHASHBAK
109 # Create missing symlinks to the enhanced binary
111 # Load defined BusyBox applets
112 source $INSTALLDIR/applets
114 # Get a list of supported applets by busybox-power
115 if test -d /tmp/busybox-power; then
116 $EXECPWR rm -Rf /tmp/busybox-power; fi
117 $EXECPWR mkdir -p /tmp/busybox-power
118 $EXECPWR --install -s /tmp/busybox-power
119 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/applets_supported
120 $EXECPWR rm -Rf /tmp/busybox-power
122 # Prepare file that will keep track of installed symlinks by busybox-power
123 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
124 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
125 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
127 # Walk through all possible destinations
128 for DESTDIR in $DESTINATIONS; do
129 # Enable us to see all entries in $DESTINATION as variables
130 eval "APPLICATIONS=\$$DESTDIR"
132 # Set destination directory accordingly
148 # Keep track of installed symlinks per destination
149 SYMLINKS="$DESTDIR=\""
151 ECHO_VERBOSE "\nSymlinking applets in $DIR"
152 # Walk through all applications from the current destination
153 for APP in $APPLICATIONS; do
154 # The following code is executed for all applets in the current destination
155 if test ! -e $DIR/$APP; then
156 # Check whether the applet is supported by the busybox binary
157 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/applets_supported`; then
158 ECHO_VERBOSE "Symlinking: /bin/busybox -> $DIR/$APP"
159 $EXECPWR ln -s /bin/busybox $DIR/$APP
160 SYMLINKS="$SYMLINKS $APP"
165 # Write out installed symlinks
166 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
169 $EXECPWR rm $INSTALLDIR/applets_supported
173 ECHO_VERBOSE "busybox-power: verbose mode"
174 ECHO_VERBOSE " binary: $EXECPWR"
175 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
176 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
180 if test "$ENVIRONMENT" != "SDK"; then
185 if test $SYMLINK == 1; then