-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-installation-archive
executable file
·70 lines (52 loc) · 1.69 KB
/
create-installation-archive
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
set -eo pipefail
source /data/usr/share/makepkg/util/message.sh || source /usr/share/makepkg/util/message.sh
colorize
#
# Functions
#
fail() {
error "$1" && exit 1
}
use_sudo=0
sudo() {
if [[ $EUID > 0 ]] ; then
if [[ $use_sudo -eq 1 ]]; then
/data/usr/bin/sudo "$@"
else
/system/bin/su -p -c "$@"
fi
else
"$@"
fi
}
#
# Sanity checks
#
msg "Checking your envirnment..."
[[ -z "$ANDROID_ROOT" ]] && fail "This script is expected to run on an android device!"
pacman -Qq install-scripts &> /dev/null || fail "You need to install install-scripts from extra repo!"
if /data/usr/bin/sudo --version &> /dev/null ; then
msg "Sudo detected!"
use_sudo=1
elif /system/bin/su --help | grep -e "MagiskSU" -e "KernelSU" &> /dev/null ; then
msg "MagiskSU/KernelSU detected!"
elif [[ $EUID > 0 ]] ; then
fail "Only MagiskSU/KernelSU is supported for now!"
fi
msg "Building chroot..."
mkdir -p workingdir
sudo chown root:root workingdir
sudo pacstrap -c workingdir base vim sudo
msg "Initializing dirs..."
sudo rm -r workingdir/data/local workingdir/{dev,proc,sys} # Handled by Android
sudo chmod 0771 workingdir/data
sudo mkdir -m 700 workingdir/data/home/{shell,root}
sudo chown root:root workingdir/data/home/root
sudo chown shell:shell workingdir/data/home/shell
sudo touch workingdir/data/.pfa-root
sudo chcon u:object_r:system_data_root_file:s0 workingdir/data
msg "Creating compressed installation archive..."
sudo env LANG=C bsdtar --options zstd:compression-level=9 --xattrs --acls --zstd -cf "installation-archive-$(date --rfc-3339=date).tar.zst" -C workingdir/data/ .
msg "Removing chroot..."
sudo rm -rf workingdir
msg "Success!"