12-20-2012, 01:25 AM | #1 | |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Checking for required libs. Exporting Binaries "easily"
Have you ever wished you could just export a binary and it's supporting libs. Or at the very least some likely candidate supporting libs.
well I did (and so did Brian...) For the 2 3 4 Touch and Paperwhite (INSIDE A DEBIAN) (or even on your desktop via a qemu-arm-static chroot) Code:
#!/bin/bash
FAILS=""
MAINEXPORTDIR="/export"
TESTUSRLIB="/kindle/usr/lib/"
TESTLIB="/kindle/lib/"
# fail on missing victim
if [ -z ${@} ]
then
echo "hmm I need a victim... usage: filechecker <binary_file>"
exit 1
fi
# fail on missing victim
if [ ! -e ${@} ]
then
echo "hmm I cannot find: ${@} - you sure? check the file exists."
exit 1
fi
BINARY=$(basename ${@})
EXPORTDIR="${MAINEXPORTDIR}""/""${BINARY}"
mkdir -p $EXPORTDIR/bin
mkdir -p $EXPORTDIR/lib
mkdir -p $EXPORTDIR/kindle-lib
cd $EXPORTDIR
# copy the binary we are interested in
cp -f ${@} "${EXPORTDIR}/bin/${BINARY}"
echo "copying ${@} to ${EXPORTDIR}/bin/${BINARY}"
echo "finding all dependencies and copying them to $EXPORTDIR/lib"
echo "this will take a couple seconds, please wait..."
ldd ${@} | awk ' /=> \// {print $3}' | xargs -I '{}' cp -v '{}' $EXPORTDIR/lib > /dev/null
echo "Done. Now going to see if any of these libraries are already on the Kindle Touch (5.3.7)..."
find $EXPORTDIR/lib -type f | while read filename
filename=$( basename $filename 2>/dev/null)
do
echo
echo "checking $EXPORTDIR/lib/$filename.."
if [ -f "$TESTUSRLIB""$filename" ]; then
if cmp --quiet $TESTUSRLIB$filename $EXPORTDIR/lib/$filename ; then
echo "$EXPORTDIR/lib/$filename is the same as my Kindle version - deleting!"
rm $EXPORTDIR/lib/$filename
fi
fi
if [ -f "$TESTLIB""$filename" ]; then
if cmp --quiet $TESTLIB$filename $EXPORTDIR/lib/$filename ; then
echo "$EXPORTDIR/lib/$filename is the same as my Kindle version - deleting"
rm $EXPORTDIR/lib/$filename
fi
fi
done
#no need to have this at all ??
if [ -f $EXPORTDIR/lib/libc.so.6 ]; then
echo
echo "*** removing unneeded libc.so.6.."
rm $EXPORTDIR/lib/libc.so.6
fi
#remove empty lib dir
if [[ "$(ls -1 $EXPORTDIR/lib | wc -l)" == "0" ]] ; then
rmdir $EXPORTDIR/lib
else
echo
echo "$EXPORTDIR/lib has: `ls -1 $EXPORTDIR/lib | wc -l` files:"
ls -1 $EXPORTDIR/lib
echo
fi
touch $EXPORTDIR/README
echo "Directories created in $EXPORTDIR. kindle-lib has newer versions of Kindle libraries." | tee $EXPORTDIR/README
echo "These are normally not needed. Run the program like this:" | tee $EXPORTDIR/README
echo "cd $EXPORTDIR/bin; LD_LIBRARY_PATH=../lib:\$LD_LIBRARY_PATH ./$BINARY" | tee $EXPORTDIR/README
Quote:
Everyone likes a good bash improvement thread. feel free to pick holes. THIS VERSION WAS PROVIDED BY BRIAN IT EXPECTS TO LIVE INSIDE A DEBIAN With the kindle libs bind mounted like: mount --bind /usr/lib /mnt/us/debian/kindle/usr/lib mount --bind /lib /mnt/us/debian/kindle/lib Last edited by twobob; 10-29-2013 at 07:20 PM. Reason: # now improved to catch sub-dependencies |
|
12-20-2012, 03:33 AM | #2 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
notes: I use bash rather than ash for this. (bash is available for the 3 and the 5)
if you get /mnt/us/bin/filechecker: line 42: syntax error: Bad substitution you need to check your bash is being correctly referenced. ah c'mon everyone likes bashing other peoples rubbishy scripting Chip in! it should be methodised at the very least. : ) No? : D ISSUES FOR THE 3: The sub-string substitution needs reworking for the really ancient busy box on the 3. I am enclosing egrep full version to facilitate this rewrite. The ancient busybox find does not support iname Either: I have enclosed a binary build of find that should do that job. invoke it directly to bypass busybox like /mnt/us/wherever/find /location/to/search -iname '*'"$file"'*' OR: change the ln -s link, or add an alias, or something to get it referencing find and bash. worst case. overwrite them. not recommended. Last edited by twobob; 10-13-2013 at 03:28 PM. |
Advert | |
|
12-20-2012, 04:00 AM | #3 |
Just a Noob
Posts: 145
Karma: 162610
Join Date: Aug 2011
Device: Kindle 3
|
@twobob
Awesome work, mate. |
12-20-2012, 05:18 AM | #4 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Working on the 3 version now
Spoiler:
Done see below Last edited by twobob; 12-20-2012 at 05:49 AM. |
12-20-2012, 05:45 AM | #5 | |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Confirmed as working on the 3...
okay... using the files from post two. (bash and find are the biggies)
no changes in the code. on a 3 (let's give it a tough one) [root@kindle root]# filechecker /mnt/us/usr/bin/matchbox-desktop Quote:
over-ride, not overwrite (although I overwrote my various find and egrep calls with the bins just to see if it would blow the device up and it seems fine) but really just invoke it by path or something. but - at a pinch - you can just overwrite /bin/bash and /usr/bin/find WARNING!! They are symbolic links that point to busybox RENAME THEM TO name.old (like /bin/bash.old) before you attempt to replace them or you will overwrite your busybox... : ) Nice Last edited by twobob; 08-31-2013 at 10:04 AM. |
|
Advert | |
|
12-20-2012, 07:28 AM | #6 | ||
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
debian extraction for dummies.
so.. and why did I want this?
on kindle 5: first mount debian [root@kindle bin]# mount -o loop=/dev/loop/debian,noatime -t ext3 /mnt/base-us/debian.ext3 /mnt/debian (just mount the ext3 file, not even chroot - that's all that is required) Let's extract something - err.. debian's wget! [root@kindle root]# filechecker /mnt/debian/usr/bin/wget Quote:
[root@kindle bin] # cd /mnt/us/export/wget/bin; LD_LIBRARY_PATH=../lib:$LD_LIBRARY_PATH ./wget --help Quote:
NOTE: THIS IS NOT A MAGIC BULLET. all manner of shared files may be missing. This only identifies the libs... But it's a start. Last edited by twobob; 12-20-2012 at 07:56 AM. |
||
12-20-2012, 08:07 AM | #7 | |||
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
Lets do one more and see what might go wrong.
I will do debians file (apt-get install file inside debian if you don't have it) (mount the ext.3 if it isn't already) [root@kindle bin]# mount -o loop=/dev/loop/debian,noatime -t ext3 /mnt/base-us/debian.ext3 /mnt/debian okay good to go [root@kindle bin]# filechecker /mnt/debian/usr/bin/file Quote:
[root@kindle bin]# cd /mnt/us/export/file/bin; LD_LIBRARY_PATH=../lib:$LD_LIBRARY_PATH ./file ./file Quote:
let's just hack the resources on to the root (they are tiny) [root@kindle bin]# mntroot rw [root@kindle bin]# mkdir -p /usr/share/misc/magic/ [root@kindle bin]# cp /mnt/debian/usr/share/misc/magic.mgc /usr/share/misc/magic.mgc [root@kindle bin]# mntroot ro and test it again [root@kindle bin]# cd /mnt/us/export/file/bin; LD_LIBRARY_PATH=../lib:$LD_LIBRARY_PATH ./file ./file Quote:
not too tricky all in. no doubt there will be cases where walking the required resource tree would be nice. parse a strace log maybe? : D sed would have been a better solution for accessing the resources on the FAT drive. patching the file binary to accept the new location Anyways - hope this helps other forgetful developers. HOW DO I MAKE INSTALL??? on my system (where my PATH includes /mnt/us/usr/bin and /mnt/us/usr/lib by default) to do a "make install" I would just [root@kindle bin]# cp -r /mnt/us/export/file/* /mnt/us/usr/ where file is the name of the exported application. You could do something similar Last edited by twobob; 12-20-2012 at 01:31 PM. |
|||
12-20-2012, 08:44 AM | #8 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Reads like a generally useful tool for anyone that wants to "extended-purpose" a Kindle.
Nice job. |
03-11-2013, 05:02 AM | #9 | |
Evangelist
Posts: 456
Karma: 1287375
Join Date: Jan 2013
Location: West Gardiner, Maine
Device: Touch (5.3.7)
|
Quote:
This whole business of exporting sure looks fun to me. |
|
03-11-2013, 09:44 PM | #10 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
there are plenty of options...
probably the easiest/most flexible is: add Code:
if [ -e "/mnt/us/.bashrc" ]; then . /mnt/us/.bashrc fi simply stuff your additions in the FAT .bashrc (that you then create) I do that generally. I would add that this is not a completely bullet-proof solution to exporting. just a best-start tool to save some time. There may be resources that are missed, even libs from time to time seem to be missed. But in the main it does the job I need. Last edited by twobob; 03-11-2013 at 09:50 PM. |
03-12-2013, 12:12 AM | #11 |
Evangelist
Posts: 456
Karma: 1287375
Join Date: Jan 2013
Location: West Gardiner, Maine
Device: Touch (5.3.7)
|
Thanks! I know everyone has a personal setup, would you be willing to post your /mnt/us/.bashrc as a starting point? Do you just adjust path and libraries? Do you have any cool functions in there? Anyone else reading have anything to add?
|
03-12-2013, 01:22 AM | #12 |
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Tır
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
|
pretty certain I have posted it around and about before.
With the forthcoming advent of kual-system I will refrain from giving system advice until I can be certain what that will ultimately bring. In essence include user libs and bins would be the first application of such a file as-is right now. Something along the lines of: export LD_LIBRARY_PATH=\ /mnt/us/usr/lib/arm-linux-gnueabi:\ /mnt/us/lib:\ /mnt/us/usr/lib:\ /usr/lib:\ /lib export PATH=/mnt/us/usr/local/bin:\ /mnt/us/usr/bin:\ /mnt/us/usr/games:\ /mnt/us/bin:\ /mnt/us/usr/sbin:\ /mnt/us/sbin:\ /usr/local/bin:\ /usr/bin:\ /bin:\ /usr/sbin:\ /sbin Obviously that is total overkill but you get the picture. Last edited by twobob; 03-12-2013 at 01:25 AM. |
03-12-2013, 02:51 AM | #13 |
Evangelist
Posts: 456
Karma: 1287375
Join Date: Jan 2013
Location: West Gardiner, Maine
Device: Touch (5.3.7)
|
Thank you for making it so easy for me, I appreciate your time!
|
03-12-2013, 08:04 AM | #14 | |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
As twobob wrote, there is an active project underway to bring system resources into the USB storage extensions/* tree. When that happens, nearly all of those paths will change (and a lot of the support work disappear). In fact, there is a whole lot of things "in progress" to extend "KUAL support" - We (twobob and I) have not given up answering questions, just been otherwise busy. |
|
09-02-2013, 11:46 PM | #15 | |
Evangelist
Posts: 456
Karma: 1287375
Join Date: Jan 2013
Location: West Gardiner, Maine
Device: Touch (5.3.7)
|
Quote:
|
|
Tags |
bash, export, k5 tools, kindle, kindle tools, tools |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Feature Request: configurable space setting for "Insert blank line" in "Look & Feel" | therealjoeblow | Calibre | 15 | 07-25-2011 03:14 PM |
"White Spaces Are Required"...PLEASE HELP! | UntreedReads | ePub | 12 | 07-22-2010 03:47 PM |
Checking in public library books and "Borrowed" status | Lucybelle | Sony Reader | 2 | 03-24-2010 01:42 AM |