guardianproject / lildebi

UNMAINTAINED please adopt! we can no longer maintain this
https://guardianproject.info/code
GNU General Public License v3.0
229 stars 55 forks source link

"bash: [: : integer expression expected" when launching debian shell #131

Open gerroon opened 10 years ago

gerroon commented 10 years ago

Hi

I just installed the latest from the release page and I am getting bunch of PATH errors

/usr/local/sbin /usr/sbin /sbin

and ldconfig are all missing

thanks

eighthave commented 10 years ago

where do you see that error?

gerroon commented 10 years ago

when I try apt-get install somepackage. This debian img was working fine ;(

My /etc/profile looks fine as far as I can tell

eighthave commented 10 years ago

Are you doing this in Android Terminal Emulator? An ssh session? An adb shell session?

gerroon commented 10 years ago

I did run terminal (after starting debian) Opening terminal form lildebi types bunch of jumble chars on the terminal on my 4.4.4 so I do manually.

su /debian/shell :#/ apt-get install someapp

eighthave commented 10 years ago

Is there any other error? For a workaround, you can do export PATH=/usr/sbin:/sbin:$PATH

gerroon commented 10 years ago

/debian/shell gives me "bash: [: : integer expression expected" same with sh

There is also "tcgetattr: Invalid argument" in Lildebi.

eighthave commented 10 years ago

This looks like the same issue as #116, I guess it is not quite fixed.

gerroon commented 10 years ago

@eighthave This is weird realy, I do not remember having this on previous versions. It seemed to popup in recent versions

eighthave commented 10 years ago

Ok, I was getting this issue too. I looked at my device, and it was in a quasi mounted state. /data/debian was mounted, but none of the bind mounts were, like /data/debian/proc, etc. Rebooting my device got the mounting working properly, after a manual e3fsck. And now /debian/shell no longer tells me "bash: [: : integer expression expected"

gerroon commented 10 years ago

@eighthave That did not help me whatsoever. I think that this issue has been introduced recenty.

I restarted, started debian and started terminal and I get bunch of mambo jumbo including "anproject.lildeb/app_bin:$PATH chroot /debian /bin/bash -l" @=^sk48 : : integer expression expected"

bear in mind this is happening in android termianl not debian chroot terminal.

Then there is no /debian. I have to stop it and restart debian a second time to get the /debian showup so I can run the shell

eighthave commented 10 years ago

As you can see from all those commits, I was working on this issue. I fixed up /debian/shell a lot. You can try it now by getting it from the commits above, or here:

#!/system/bin/sh 

export TERM=linux
export HOSTNAME=debian
export HOME=/root
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/system/xbin:/system/bin
app_bin=/data/data/info.guardianproject.lildebi/app_bin
export USER=root

username=`$app_bin/whoami`
id=`$app_bin/id -u`
if [ "$id" -eq 0 ]; then
# try using the chroot included in LilDebi, otherwise fail over to a possible system one
    PATH=$app_bin SHELL=/bin/bash $app_bin/chroot /debian /bin/bash --login -i \
        || chroot /debian /bin/bash --login -i
elif grep "^${username}:" /debian/etc/passwd > /dev/null; then
    su -c "PATH=$app_bin SHELL=/bin/sh TERMINFO=/lib/terminfo USER=$username \
             $app_bin/chroot /debian /bin/su $username --login"
else
    su -c "HOME=/root PATH=$app_bin SHELL=/bin/bash TERMINFO=/lib/terminfo \
             $app_bin/chroot /debian /bin/bash --login -i"
fi
SDkie commented 10 years ago

@gerroon : which version of lildebi you are using ?

gerroon commented 10 years ago

I do not think that the latest version fixed my issue. I do not understand this ;( I nevber had these path issues prior to the latest versions

eighthave commented 10 years ago

0.5.2 didn't change anything? Can you try a few things and report back:

Run "Open Terminal..."

Run in an adb session:

adb shell
/debian/shell

Run as root in an adb session:

adb shell
su
/debian/shell

Run in an Terminal Emulator:

/debian/shell

Run as root in an Terminal Emulator:

su
/debian/shell
Canar commented 9 years ago

I encounter this problem also. The fix is trivial.

In /etc/profile,

if [ "`id -u`" -eq 0 ]; then

id -u is returning nothing, not even a zero. Don't know why, but that's what's happening. Therefore, when you simply add a zero before the double quote, like so:

if [ 0"`id -u`" -eq 0 ]; then

The problem goes away and you can enjoy your Debian like usual.

eighthave commented 9 years ago

The problem happens when id -u from Android is run, rather than id -u from Debian. id -u does the right thing on some Android ROMs, but not all. /debian/shell sets the PATH before to make sure the Debian id -u is used, but it seems to fail sometimes. That's the part that I don't understand.

Marietto2008 commented 9 years ago

Hello. I have installed Lil Debi on my nexus 10 and I have the same problem. Inside the android terminal I have no /debian/shell file. I would like to edit the file /etc/profile/ but I don't know how to do since I can't install new packages,I can't use the ee or the nano file editor.... what can i do ?

Canar commented 9 years ago

/usr/bin/nano /etc/profile should work

Marietto2008 commented 9 years ago

do you know if there is a way to increase the storage space of my nexus 10 in some way ? because I've tried to install Lil' debi but I've not been able to complete the procedure since I have not enough space. My opinion is to change the internal structure of lil' debi so that it can be installed in one external storage. But how ? and which kind of storage can I use ? thanks.

jkk88 commented 9 years ago

I have the same problem on CM11 Nexus7 and Xperia M also on CM11. I found out that busybox from inside chroot environment doesn't work.

root@localhost:/data/data/info.guardianproject.lildebi/app_bin# ./busybox [1] Segmentation fault ./busybox

and just after starting user shell line "if [ "$id" -eq 0 ]; then" in /etc/profile is issued and doesn't return awaited result. Replacing busybox in $app_bin with working version does made environment working. I have used this one: http://www.busybox.net/downloads/binaries/latest/busybox-armv7l If you don't want to replace busybox - it is enough to put line PATH=/usr/bin before mentioned line or use full path of id i.e /usr/bin/id.

eighthave commented 9 years ago

Something odd is going on here. LilDebi's embedded busybox works fine for me in both the adb shell and when I'm in the Debian chroot.

@jkk88 could you try one thing to get the included busybox working:

adb shell
su
/debian/shell
cd /data/data/info.guardianproject.lildebi/app_bin
echo $LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/vendor/lib:/system/lib
./busybox
jkk88 commented 9 years ago

Hans,

here is output:

root@localhost:~# cd /data/data/info.guardianproject.lildebi/app_bin cd /data/data/info.guardianproject.lildebi/app_bin root@localhost:/data/data/info.guardianproject.lildebi/app_bin# echo $LD_LIBRARY_PATH _PATH$LD_LIBRARY /vendor/lib:/system/lib root@localhost:/data/data/info.guardianproject.lildebi/app_bin# export LD_LIBRARY_PATH=/vendor/lib:/system/lib Y_PATH=/vendor/lib:/system/lib root@localhost:/data/data/info.guardianproject.lildebi/app_bin# ./busybox ./busybox

[1]+ Stopped ./busybox root@localhost:/data/data/info.guardianproject.lildebi/app_bin#

[1]+ Segmentation fault ./busybox root@localhost:/data/data/info.guardianproject.lildebi/app_bin#

Regards

Peter

On Wed, Jan 7, 2015 at 2:49 PM, Hans-Christoph Steiner < notifications@github.com> wrote:

Something odd is going on here. LilDebi's embedded busybox works fine for me in both the adb shell and when I'm in the Debian chroot.

@jkk88 could you try one thing to get the included busybox working:

adb shell su /debian/shell cd /data/data/info.guardianproject.lildebi/app_bin echo $LD_LIBRARY_PATH export LD_LIBRARY_PATH=/vendor/lib:/system/lib ./busybox

— Reply to this email directly or view it on GitHub https://github.com/guardianproject/lildebi/issues/131#issuecomment-69023522 .

eighthave commented 9 years ago

Ok, guess that hunch was wrong... I'm stumped as to why this might happen. Does busybox run under the plain Android shell, i.e.:

adb shell
su
cd /data/data/info.guardianproject.lildebi/app_bin
./busybox ls

Or maybe it needs to use the full path, i.e.

adb shell
su
/data/data/info.guardianproject.lildebi/app_bin/busybox ls
jkk88 commented 9 years ago
C:\data>adb shell
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
?7?[r?[999;999H?[6nshell@tilapia:/ $ su
su
?7?[r?[999;999H?[6nroot@tilapia:/ # cd /data/data/info.guardianproject.lildebi/app_bin
cd /data/data/info.guardianproject.lildebi/app_bin
root@tilapia:/data/data/info.guardianproject.lildebi/app_bin # ./busybox ls
./busybox ls
VERSION                          mkdosfs
[                                mke2fs
[[                               mkfs.ext2
android-permissions_0.1_all.deb  mkfs.vfat
ar                               mknod
ash                              mount
awk                              mv
basename                         nice
bash                             patch
bunzip2                          pidof
busybox                          policy-rc.d
busybox--                        printf
bzcat                            ps
cat                              pwd
cdebootstrap.tar                 readlink
chgrp                            realpath
chmod                            remove-debian-setup.sh
chown                            remove-hard-restart.sh
chroot                           rm
complete-debian-setup.sh         rmdir
configure-downloaded-image.sh    sed
cp                               sh
cpio                             sha1sum
create-debian-setup.sh           sha256sum
cttyhack                         sha3sum
cut                              sha512sum
dd                               shell
debian-archive-keyring.gpg       sleep
dirname                          sort
echo                             start-debian.sh
egrep                            start-debian.sh.O
expr                             stop-debian.sh
fdisk                            sync
fgrep                            tail
fsck                             tar
fstrim                           test
gpgv                             test.sh
grep                             touch
gunzip                           tr
head                             tune2fs
id                               umount
install.conf                     uname
kill                             uniq
lildebi-common                   unlzma
ln                               unmounted-install-tweaks.sh
losetup                          unxz
ls                               wc
lsof                             wget
lzcat                            whoami
lzma                             xz
md5sum                           xzcat
mkdir                            zcat
root@tilapia:/data/data/info.guardianproject.lildebi/app_bin #

C:\data>adb kill-server

C:\data>adb shell
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
?7?[r?[999;999H?[6nshell@tilapia:/ $ su
su
?7?[r?[999;999H?[6nroot@tilapia:/ # /data/data/info.guardianproject.lildebi/app_bin/busybox ls
/data/data/info.guardianproject.lildebi/app_bin/busybox ls
acct                 factory              init.superuser.rc    seapp_contexts
cache                file_contexts        init.trace.rc        sepolicy
config               fstab.grouper        init.usb.rc          storage
d                    init                 mnt                  sys
data                 init.cm.rc           proc                 system
debian               init.environ.rc      property_contexts    ueventd.grouper.rc
default.prop         init.grouper.rc      root                 ueventd.rc
dev                  init.grouper.usb.rc  sbin                 usbdisk
etc                  init.rc              sdcard               vendor
root@tilapia:/ #
root@tilapia:/ # /debian/shell
/debian/shell
bash: [: : integer expression expected
root@localhost:/# ps
ps
  PID TTY          TIME CMD
 4706 pts/1    00:00:00 su
 4707 pts/1    00:00:00 sh
 4823 pts/1    00:00:00 shell
 4826 pts/1    00:00:00 bash
 4841 pts/1    00:00:00 ps
root@localhost:/# ls /proc/4826
ls /proc/4826
attr        comm     fdinfo     mounts      oom_score      sched      statm
auxv        cwd      limits     mountstats  oom_score_adj  schedstat  status
cgroup      environ  maps       net         pagemap        smaps      task
clear_refs  exe      mem        ns          personality    stack      wchan
cmdline     fd       mountinfo  oom_adj     root           stat
root@localhost:/# cat /proc/4826/environ
cat /proc/4826/environ
PATH=/data/data/info.guardianproject.lildebi/app_bin _=/data/data/info.guardianproject.lildebi/app_bin/chroot SHELL=/bin
/bash HOSTNAME=debian EMULATED_STORAGE_SOURCE=/mnt/shell/emulated ANDROID_DATA=/data BOOTCLASSPATH=/system/framework/cor
e.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bo
uncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework2.jar:/system/framew
ork/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/mms-common.jar:/system/framework/android.po
licy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/webviewchromium.jar:/system/f
ramework/telephony-msim.jar LOOP_MOUNTPOINT=/mnt/obb ANDROID_ROOT=/system EMULATED_STORAGE_TARGET=/storage/emulated ANDR
OID_CACHE=/cache LD_LIBRARY_PATH=/vendor/lib:/system/lib ANDROID_STORAGE=/storage MKSH=/system/bin/sh ANDROID_PROPERTY_W
ORKSPACE=9,0 EXTERNAL_STORAGE=/storage/emulated/legacy ANDROID_ASSETS=/system/app TERM=linux RANDOM=6908 ASEC_MOUNTPOINT
=/mnt/asec USER=root HOME=/root ANDROID_BOOTLOGO=1 TERMINFO=/system/etc/terminfo root@localhost:/#

root@localhost:/# /data/data/info.guardianproject.lildebi/app_bin/busybox id
/data/data/info.guardianproject.lildebi/app_bin/busybox id

[1]+  Stopped                 /data/data/info.guardianproject.lildebi/app_bin/busybox id
root@localhost:/#

[1]+  Segmentation fault      /data/data/info.guardianproject.lildebi/app_bin/busybox id
root@localhost:/#

If I connect via ssh, there is another behaviour (PATH is correctly set):

root@localhost:~# ps
  PID TTY          TIME CMD
 5176 pts/2    00:00:00 bash
 5189 pts/2    00:00:00 ps
root@localhost:~# cat /proc/5176/environ
USER=rootLOGNAME=rootHOME=/rootPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11MAIL=/var/mail/rootSHELL=/bin/bashSSH_CLIENT=192.168.2.230 55896 22SSH_CONNECTION=192.168.2.230 55896 192.168.2.144 22SSH_TTY=/dev/pts/2TERM=xtermroot@localhost:~#

I have checked launch script $app_bin/shell and probably all occurence of PATH=$app_bin should be removed.

eighthave commented 9 years ago

So I found a way to make /debian/shell work the old way, requiring root beforehand, on devices that are affected by this issue. On devices where id -u gives the right info, then /debian/shell can be run as non-root.

SDkie commented 9 years ago

When I click on 'Open Terminal' while testing lildebi on cm-11

screenshot_2015-01-25-13-30-00

eighthave commented 9 years ago

is that new behavior with this new commit? It is odd behavior for sure, do you know if it is breaking anything?

SDkie commented 9 years ago

@eighthave : I tried with V0.5.4 from F-Droid, and I also tried building lildebi from source. Its giving me same issue. I tested it on my new Nexus-5, not sure when this is broken.

eighthave commented 9 years ago

@SDkie which issue? the export COLUMNS LINES issue, or "bash: [: : integer expression expected" ?

SDkie commented 9 years ago

When I run app_bin/shell manually from terminal then I am getting "bash: [: : integer expression expected" which is I guess because of "--login" parameter.

But when I click on "Open terminal" I see weird symbols "0;60R", and I am not inside the Debian shell as expected.

The export COLUMNS LINES is done by the default android shell. Nothing to do with lildebi.

On Mon, Feb 2, 2015 at 2:15 PM, Hans-Christoph Steiner < notifications@github.com> wrote:

@SDkie https://github.com/SDkie which issue? the export COLUMNS LINES issue, or "bash: [: : integer expression expected" ?

— Reply to this email directly or view it on GitHub https://github.com/guardianproject/lildebi/issues/131#issuecomment-72422785 .

Kumar Sukhani http://tabforacause.org/?r=11079297

jkk88 commented 9 years ago

I have a little reworked laucher $app_bin/shell, try this one:

#!/system/bin/sh

#set -x

export TERM=linux
export HOSTNAME=debian
export HOME=/root
export app_bin=/data/data/info.guardianproject.lildebi/app_bin
export PATH=$app_bin:/system/xbin:/system/bin
# CHROOTPATH - path for first commands in /etc/profile before PATH set
export CHROOTPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export USER=root

BUSYBOX=$app_bin/busybox

while :; do
for lBusybox in \
    /data/local/bin/busybox \
    /data/local/busybox \
    /system/xbin/busybox \
    /system/bin/busybox \
    /system/sbin/busybox \
    /sbin/busybox
    do
        [ -x $lBusybox ] && BUSYBOX=$lBusybox; break
    done
    break
done

username=`whoami`
id=`id -u`
# make sure we got a valid ID before checking its 0
if [ ! -z "$id" ] && [ `echo "$id" | grep -v '[^0-9]' > /dev/null` ] && [ "$id" -eq 0 ]; then
    # try using the chroot included in LilDebi, otherwise fail over to a possible system one
    PATH=$CHROOTPATH SHELL=/bin/bash $app_bin/chroot /debian /bin/bash --login -i \
    || \
    PATH=$CHROOTPATH SHELL=/bin/bash $BUSYBOX chroot /debian /bin/bash --login -i
elif grep "^${username}:" /debian/etc/passwd > /dev/null; then
    su -c "PATH=$CHROOTPATH SHELL=/bin/sh TERMINFO=/lib/terminfo USER=$username \
        $app_bin/chroot /debian /bin/su $username --login" \
    || \
    su -c "PATH=$CHROOTPATH SHELL=/bin/sh TERMINFO=/lib/terminfo USER=$username \
        $BUSYBOX chroot /debian /bin/su $username --login"
else
#    su -c "HOME=/root PATH=$app_bin SHELL=/bin/bash TERMINFO=/lib/terminfo \
#             $app_bin/chroot /debian /bin/bash --login -i"
    su -c "chroot /debian busybox env -i \
        TERMINFO=/lib/terminfo PATH=$CHROOTPATH \
        HOME=/root TERM=$TERM HOSTNAME=$HOSTNAME \
        /bin/bash --login -i" \
    || \
    su -c "$BUSYBOX chroot /debian $BUSYBOX env -i \
        TERMINFO=/lib/terminfo PATH=$CHROOTPATH \
        HOME=/root TERM=$TERM HOSTNAME=$HOSTNAME \
        /bin/bash --login -i"
fi 
jkk88 commented 9 years ago

I have noticed later that $app_bin/busybox don't contain applet env so if used such construction busybox should be recompiled. For non root user using Term app there is accessible at least /data/data/jackpal.androidterm/app_HOME/bin alongside sytem path which can be added to search path for busybox Maybe to make it cleaner all utilities should be written with full path for ex. $BUSYBOX grep and on beginning of script define configurable full path of busybox

adamjhogan commented 9 years ago

Compiling busybox with env could help us to dynamically unset LD_PRELOAD only when needed. (https://gist.github.com/godlessfather/1436d5fa5ce9e6f48d8b is my hammerhead's env for reference)

adamjhogan commented 9 years ago

@SDkie screenshot_2015-02-09-14-07-43 CM11 on Hummingbird

jkk88 commented 9 years ago

This is working on cm11 very well - using cm11 builtin busybox. Busybox in lildebi need to be recompiled with env applet. You can also try one from here: http://forum.xda-developers.com/showthread.php?t=1929852 and then correct path in line beginning with BUSYBOX=

#!/system/bin/sh

#set -x

BUSYBOX=/system/xbin/busybox
#BUSYBOX=/data/data/info.guardianproject.lildebi/app_bin/busybox

SHELL=/bin/bash
TERM=linux
TERMINFO=/lib/terminfo
USER=root
HOME=/root

echo BUSYBOX=${BUSYBOX}

username=`toolbox id | ${BUSYBOX} sed -E "s/ +.*//;s/.*\(//;s/\)//"` || username=`${BUSYBOX} whoami`
id=`toolbox id | ${BUSYBOX} sed -E  "s/\(.*//;s/uid=//"` || id=`${BUSYBOX} id -u`
# make sure we got a valid ID before checking its 0
if ${BUSYBOX} test -n "$id" && `${BUSYBOX} echo "$id" | ${BUSYBOX} grep -v '[^0-9]' > /dev/null` && \
    ${BUSYBOX} test "$id" -eq 0; then
    ${BUSYBOX} chroot /debian ${BUSYBOX} env -i \
        TERM=${TERM} TERMINFO=${TERMINFO} USER=${username} HOME=${HOME} \
        /bin/bash --login -i
elif ${BUSYBOX} test -n "${username}" && ${BUSYBOX} grep "^${username}:" /debian/etc/passwd > /dev/null; then
    su -c "${BUSYBOX} chroot /debian ${BUSYBOX} env -i \
        TERM=${TERM} TERMINFO=${TERMINFO} USER=${USER} \
        /bin/su ${username} --login"
else
    su -c "${BUSYBOX} chroot /debian ${BUSYBOX} env -i \
        TERM=${TERM} TERMINFO=${TERMINFO} USER=${username} HOME=${HOME} \
        /bin/bash --login -i"
fi
EmmanuelKasper commented 9 years ago

An easy workaroung for this problem (wrong path and "[: : integer expression expected " error ) is to use su instead of bash when chrooting, as

chroot /debian /bin/su -l
eighthave commented 9 years ago

Thanks for the tip. Have you tested it on Android or LilDebi? I thought that bash --login -i was supposed to do the same kind of thing.

SDkie commented 9 years ago

I observe that '--login' parameter giving that error.

On Tue, Feb 10, 2015 at 7:20 PM, Hans-Christoph Steiner < notifications@github.com> wrote:

Thanks for the tip. Have you tested it on Android or LilDebi? I thought that bash --login -i was supposed to do the same kind of thing.

— Reply to this email directly or view it on GitHub https://github.com/guardianproject/lildebi/issues/131#issuecomment-73701481 .

Kumar Sukhani http://tabforacause.org/?r=11079297

jkk88 commented 9 years ago

I observe that '--login' parameter giving that error.

Which error and which version? On wheezy (but tried also on jessie) normal behaviour

root@localhost:~# bash --version
GNU bash, version 4.2.37(1)-release (arm-unknown-linux-gnueabi)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
root@localhost:~# bash --login -i
root@localhost:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

I cannot see any error.

EmmanuelKasper commented 9 years ago

@eighthave I tested the commond on android (4.4 rooted)

chroot /debian /bin/su -l

I guest it would be easy to change the command which is started by the terminal emulator