Skip to content

Commit 5f32160

Browse files
ZeroPointEnergybhush9
authored andcommitted
Add halium-chroot script
Simple script that: - Mounts rootfs.img, system.img and /target/data - Opens an interactive shell or executes a non-interactive command in the chroot /target - Umounts everything again
1 parent b2dab37 commit 5f32160

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

halium-chroot

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
#
3+
# This script will:
4+
# - mount rootfs.img, system.img and /data
5+
# - enter an interactive shell in the chroot or execute
6+
# a given command
7+
# - umount rootfs, system and /data
8+
#
9+
# Usage:
10+
#
11+
# To get an interactive shell in the chroot simply enter:
12+
# ./halium-chroot
13+
#
14+
# To directly execute a non-interactive program run:
15+
# ./halium-chroot my-program
16+
#
17+
18+
mount_all()
19+
{
20+
adb shell <<-SHELL
21+
mkdir -p /target
22+
mount /data/rootfs.img /target
23+
mount /data/system.img /target/system
24+
mount --bind /data /target/data
25+
exit
26+
SHELL
27+
}
28+
29+
umount_all()
30+
{
31+
adb shell <<-SHELL
32+
umount -rl /target
33+
exit
34+
SHELL
35+
}
36+
37+
mount_all > /dev/null
38+
39+
CHROOT='TERM=linux HOME=/root PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH chroot /target'
40+
41+
if [ $# -eq 0 ]
42+
then # Interactive shell
43+
if [ $(which tmux) ]
44+
then # with tmux installed
45+
tmux new-session -s halium-adb -d 'adb shell'
46+
sleep 1
47+
tmux send-keys -t halium-adb "${CHROOT} /bin/bash; exit"$'\n'
48+
tmux attach -t halium-adb
49+
else # without tmux installed
50+
echo 'To automatically get an interactive chroot session, install'
51+
echo 'The program "tmux". To enter the chroot environment run:'
52+
echo
53+
echo "${CHROOT} /bin/bash"
54+
echo
55+
adb shell
56+
fi
57+
else # Non-interactive command
58+
adb shell "${CHROOT} /bin/bash -c \"${@}\""
59+
fi
60+
61+
umount_all > /dev/null

0 commit comments

Comments
 (0)