Skip to content
This repository was archived by the owner on Jan 24, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assets/install-xfce.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/data/data/info.guardianproject.lildebi/app_bin/sh

# get full debug output
set -x

apt-get update
apt-get install -y fakeroot libc-bin dpkg x11-xserver-utils xfce4-panel xfdesktop4 xfwm4 xfce4-session thunar xfconf xfce4-settings tango-icon-theme apt synaptic apt-xapian-index xterm locales fonts-droid libgl1-mesa-swx11

# copy the start script to root home folder
cp /data/data/info.guardianproject.lildebi/app_bin/start-xfce.sh /root/
74 changes: 74 additions & 0 deletions assets/kill-debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/data/data/info.guardianproject.lildebi/app_bin/sh
#
# see lildebi-common for arguments, the args are converted to vars there. The
# first arg $1 is the "app payload" directory, where the included scripts are
# kept.

# many phones don't even include 'test', so set the path to our
# busybox tools first, where we provide all the UNIX tools needed by
# this script
export PATH=$1:$PATH

test -e $1/lildebi-common || exit 1
. $1/lildebi-common

echo -n "Asking all processes to terminate..."
# first send TERM
for root in /proc/*/root; do
if [ ! -r "$root" ] || [ ! "`readlink "$root"`" = "$mnt" ]; then
continue
fi
pid="${root#/proc/}"
pid="${pid%/root}"
kill -TERM "$pid" 2>/dev/null || true
done
# /debian/shell starts outside of the chroot, so it must be killed separately
for pid in `ps | grep '/[d]ebian/shell' | cut -b1-5`; do
kill -TERM $pid
done
sleep 1
echo "done"
# then send KILL to force the rest to die
echo "Killing remaining processes:"
for root in /proc/*/root; do
if [ ! -r "$root" ] || [ ! "`readlink "$root"`" = "$mnt" ]; then
continue
fi
pid="${root#/proc/}"
pid="${pid%/root}"
echo "$pid `readlink $(dirname $root)/exe`"
kill -KILL "$pid" 2>/dev/null || true
done
for pid in `ps | grep '/[d]ebian/shell' | cut -b1-5`; do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion: use grep '/debian/shell' /proc/*/comm instead of parsing ps output.

echo "$pid /debian/shell"
kill -KILL $pid
done
echo "done"

echo -n "Unmounting everything..."
# sort reverse so it gets the nested mounts first
for mount in `cut -d ' ' -f 2 /proc/mounts | grep $mnt/ | sort -r`; do
$busybox_path/umount -f $mount
done

if [ x"$install_on_internal_storage" = xno ]; then
umount -d $mnt || /system/bin/umount $mnt || echo "Failed to unmount $mnt!"
fi
echo "done"

attached=`find_attached_loopdev`
if [ ! -z $attached ]; then
echo -n "Deleting loopback device..."
$losetup -d $attached
echo "done"
fi

echo ""
echo "Debian chroot stopped and unmounted."
if [ -e $sha1file ]; then
echo -n "Calculating new SHA1 checksum of $install_path..."
$app_bin/sha1sum $install_path > $sha1file
chmod 0600 $sha1file
cp $sha1file `dirname $install_path`
echo "Done!"
fi
17 changes: 17 additions & 0 deletions assets/start-xfce.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/data/data/info.guardianproject.lildebi/app_bin/sh

# get full debug output
set -x

export PATH=/usr/sbin:/usr/bin:/sbin:/bin:/system/sbin:/system/bin:/system/xbin
export DISPLAY=127.0.0.1:0
rm -f /var/run/dbus/pid
dbus-daemon --system &
sleep 1
dbus-launch --exit-with-session xfce4-session &

# NOTES:
# Before running this script
# 1) install https://play.google.com/store/apps/details?id=x.org.server application
# 2) open this application and select the display configuration
# 3) After that you can run this script or set it as post-start script in Lil'Debi application
16 changes: 15 additions & 1 deletion src/info/guardianproject/lildebi/LilDebiAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ public void stopDebian() {
.show();
}

public void killDebian() {
if (wl.isHeld())
wl.release();

command = new String(NativeHelper.app_bin + "/chroot "
+ NativeHelper.mnt + " /bin/bash -c \""
+ NativeHelper.preStopScript + "\"; ./kill-debian.sh "
+ NativeHelper.getArgs());
commandThread = new CommandThread();
commandThread.start();
Toast.makeText(context, R.string.stopping_debian, Toast.LENGTH_LONG)
.show();
}

public void removeDebianSetup() {
command = "./delete-all-debian-setup.sh " + NativeHelper.getArgs();
commandThread = new CommandThread();
Expand Down Expand Up @@ -146,4 +160,4 @@ public void update(String val) {
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/info/guardianproject/lildebi/MediaEjectReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.Context;
import android.content.Intent;

// This receiver tries to stopDebian when sdcard is present
// This receiver tries to killDebian when sdcard is present
public class MediaEjectReceiver extends BroadcastReceiver {

private LilDebiAction action;
Expand All @@ -13,7 +13,7 @@ public void onReceive(Context context, Intent intent) {
if (!NativeHelper.installInInternalStorage) {
if (NativeHelper.isStarted()) {
action = new LilDebiAction(context, null);
action.stopDebian();
action.killDebian();
}
LilDebi.sdcardUnmounted();
}
Expand Down
4 changes: 2 additions & 2 deletions src/info/guardianproject/lildebi/MediaUnmountedReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.Context;
import android.content.Intent;

// This receiver tries to stopDebian when sdcard is not present
// This receiver tries to killDebian when sdcard is not present
public class MediaUnmountedReceiver extends BroadcastReceiver {

private LilDebiAction action;
Expand All @@ -14,7 +14,7 @@ public void onReceive(Context context, Intent intent) {
// installed after SDcard is unmounted
if (!NativeHelper.isInstalled() && NativeHelper.isStarted()) {
action = new LilDebiAction(context, null);
action.stopDebian();
action.killDebian();
}
if (!NativeHelper.installInInternalStorage)
LilDebi.sdcardUnmounted();
Expand Down
3 changes: 3 additions & 0 deletions src/info/guardianproject/lildebi/NativeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ public static void unzipDebiFiles(Context context) {
chmod(0755, new File(app_bin, "configure-downloaded-image.sh"));
chmod(0755, new File(app_bin, "start-debian.sh"));
chmod(0755, new File(app_bin, "stop-debian.sh"));
chmod(0755, new File(app_bin, "kill-debian.sh"));
chmod(0755, new File(app_bin, "install-xfce.sh"));
chmod(0755, new File(app_bin, "start-xfce.sh"));
chmod(0755, new File(app_bin, "shell"));
chmod(0755, new File(app_bin, "test.sh"));
chmod(0755, new File(app_bin, "gpgv"));
Expand Down