-
Notifications
You must be signed in to change notification settings - Fork 0
/
androlinux_xorg.sh
113 lines (90 loc) · 4.35 KB
/
androlinux_xorg.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/system/bin/sh
# This step will stop android UI
setprop ctl.stop media & setprop ctl.stop zygote & setprop ctl.stop surfaceflinger & setprop ctl.stop drm
#export PATH=$bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin:/bin:/usr/local/sbin:/usr/games:$PATH
#export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/system/xbin/bb:/data/local/bin:$PATH
#export TERM=linux
mkdir -p /data/linux
chroot_path="/data/linux"
#export HOME=/root
export HOSTNAME=localhost
#export DISPLAY=:0
# Change the path with your root file system (it can be any distro, doesn't matter)
#mount /storage/sdcard1/14.04.1_rootfs.img $chroot_path
mount /data/14.04.1_rootfs.img $chroot_path
start_mount() {
if [ ! -f "$chroot_path/proc/uptime" ]; then
busybox mount /proc $chroot_path/proc
fi
if [ ! -f "$chroot_path/dev/random" ]; then
busybox mount /dev $chroot_path/dev
busybox mount /dev/pts $chroot_path/dev/pts
busybox mount /dev/cpuctl $chroot_path/dev/cpuctl
ln -n /dev/graphics/fb0 /dev/fb0
fi
if [ ! -d "$chroot_path/sys/kernel" ]; then
busybox mount /sys $chroot_path/sys
fi
# Strictly for testing, must remove in production
if [ ! -d "$chroot_path/mnt/android/system/etc" ]; then
busybox mount -o rw,remount /system
busybox mount /system $chroot_path/mnt/android/system
busybox mount -o rw,remount /data
busybox mount /data $chroot_path/mnt/android/data
busybox mount -o rw,remount /
busybox mount / $chroot_path/mnt/android/root
fi
}
stop_mount() {
sleep 2
umount $chroot_path/dev/pts
umount $chroot_path/dev/cpuctl
umount $chroot_path/dev
umount $chroot_path/sys
umount $chroot_path/proc
umount $chroot_path/mnt/android/system
umount $chroot_path/mnt/android/root
umount $chroot_path/mnt/android/data
umount $chroot_path
busybox mount -o ro,remount /system
busybox mount -o ro,remount /
}
setup() {
busybox sysctl -w net.ipv4.ip_forward=1
busybox chroot $chroot_path /bin/bash -c "ln -s /run/shm /dev/shm"
busybox chroot $chroot_path /bin/bash -c "echo '127.0.0.1 localhost' > /etc/hosts"
busybox chroot $chroot_path /bin/bash -c "echo 'shm /dev/shm tmpfs nodev,nosuid,noexec 0 0' > /etc/fstab"
busybox chroot $chroot_path /bin/bash -c "chmod a+rw /dev/null"
busybox chroot $chroot_path /bin/bash -c "chmod a+rw /dev/ptmx"
busybox chroot $chroot_path /bin/bash -c "chmod 1777 /tmp"
busybox chroot $chroot_path /bin/bash -c "chmod 1777 /dev/shm"
busybox chroot $chroot_path /bin/bash -c "chmod +s /usr/bin/sudo"
busybox chroot $chroot_path /bin/bash -c "mkdir /var/run/dbus"
busybox chroot $chroot_path /bin/bash -c "chown messagebus.messagebus /var/run/dbus"
busybox chroot $chroot_path /bin/bash -c "chmod 755 /var/run/dbus"
busybox chroot $chroot_path /bin/bash -c "dpkg-divert --local --rename --add /sbin/initctl"
busybox chroot $chroot_path /bin/bash -c "ln -s /bin/true /sbin/initctl"
busybox chroot $chroot_path /bin/bash -c "service ssh start"
busybox chroot $chroot_path /bin/bash -c "dbus-daemon --system --fork > /dev/null 2>&1"
busybox chroot $chroot_path /bin/bash -c "chown -R student.student /home/student"
busybox chroot $chroot_path /bin/bash -c "rm /tmp/.X* > /dev/null 2>&1"
busybox chroot $chroot_path /bin/bash -c "rm -rf /tmp/*"
busybox chroot $chroot_path /bin/bash -c "rm /tmp/.X11-unix/X* > /dev/null 2>&1"
busybox chroot $chroot_path /bin/bash -c "rm /var/run/dbus/pid > /dev/null 2>&1"
busybox chroot $chroot_path /bin/bash -c "groupadd -g 3003 android_inet"
}
destroy() {
busybox chroot $chroot_path /bin/bash -c "service ssh stop"
busybox chroot $chroot_path /bin/bash -c "service wicd stop"
busybox chroot $chroot_path /bin/bash -c "service networking stop"
for pid in `lsof | busybox grep $chroot_path | busybox sed -e's/ / /g' | busybox cut -d' ' -f2`; do busybox kill -9 $pid >/dev/null 2>&1; done
}
# stop_mount # Just in case if something still mounted
start_mount
setup
chroot $chroot_path /bin/su -l student -c 'startx'
sleep 2
destroy
stop_mount
setprop ctl.start media & setprop ctl.start zygote & setprop ctl.start surfaceflinger & setprop ctl.start drm
# mount -o rw,remount /dev/block/mtdblock9 /system