-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·192 lines (138 loc) · 4.56 KB
/
install.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
export STEPS=4
echo --- begin of alpine4droid setup log --- > setup_log.log
log () {
echo [*] $@
echo Alpine4droid: [*] $@ > setup_log.log
}
bind () {
#log BIND: Binding $1 to $2...
su -c "mount -o bind,rw $1 $2"
}
unbind () {
#log UNBIND: Unbinding $1...
su -c "umount $1"
}
before_chroot () {
bind /dev $1/dev
bind /proc $1/proc
bind /sys $1/sys
}
after_chroot () {
unbind $1/dev
unbind $1/proc
unbind $1/sys
}
run_in_chroot () {
before_chroot $1
su -c "chroot $@"
after_chroot $1
}
setup_base () {
su "mkdir $1"
log Downloading image using curl...
curl https://dl-cdn.alpinelinux.org/alpine/v3.17/releases/armv7/alpine-minirootfs-3.17.2-$target.tar.gz --output tmp/target.tar.gz
# Extract chroot container
log Extracting...
su -c "cat tmp/target.tar.gz | tar xz -C $1"
# Write resolv.conf and install openrc
log Settuping base system...
su -c "echo nameserver 1.1.1.1 > $1/etc/resolv.conf"
run_in_chroot $1 /sbin/apk add alpine-base openssh --progress -q
echo PermitRootLogin yes > $1/etc/ssh/sshd_config
run_in_chroot $1 /sbin/rc-update add sshd default
}
set_pass () {
log Step 1 of $STEPS
log Please set password for root
run_in_chroot $1 /usr/bin/passwd
}
log Alpine4droid installer ver 1.1.2
log Preparing...
mkdir tmp 2> /dev/null
rm tmp/target.tar.gz 2> /dev/null
log Getting target arch...
#arch=$(uname -m)
export arch=$(uname -m)
case $arch in
x86_64|amd64)
export target=x86_64;;
i?86)
export target=x86;;
armv7)
export target=armv7;;
aarch64|armv8l)
export target=aarch64;;
esac
log Target: $target
log Please tell where install alpine linux container\(path starts with /data ex: typed: alpine path: /data/alpine\)
read installpath
export instpath=/data/$installpath
log Ok, install path $instpath
# Setup alpine
setup_base $instpath
# Set password
set_pass $instpath
log Step 2 of $STEPS
log Please wait while i setup system...
log Generating ssh keypair...
su -c "mount -t tmpfs run $instpath/run"
mkdir $instpath/run/openrc
touch $instpath/run/openrc/softlevel
run_in_chroot $instpath /sbin/openrc
run_in_chroot $instpath /sbin/rc-service sshd start
run_in_chroot $instpath /sbin/rc-service sshd stop
umount $instpath/run
log Creating dirs..
su -c "mkdir $instpath/system $instpath/apex $instpath/data"
log Creating integrate.sh\(starts container\)
run_in_chroot cat <<EOF > /integrate.sh
# Generated by alpine4droid
bind () {
mount -o bind,rw \$1 \$2
}
bind /dev $instpath/dev
bind /sys $instpath/sys
bind /proc $instpath/proc
bind /apex $instpath/apex
bind /system $instpath/system
bind /data $instpath/data
mount -t devpts devpts $instpath/dev/pts
mount -t tmpfs run $instpath/run
mkdir $instpath/run/openrc
touch $instpath/run/openrc/softlevel
chroot $instpath /sbin/openrc default
EOF
log Creating run.sh\(script to enter container\)
run_in_chroot cat <<EOF > /run.sh
# Generated by alpine4droid
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
chroot $instpath /bin/bash
EOF
su -c "chmod +x $instpath/integrate.sh"
su -c "chmod +x $instpath/run.sh"
log Step 3 of $STEPS
log I install some packages, pls wait
run_in_chroot $instpath /sbin/apk add htop neofetch bash bash-completion --progress -q
log Step 4 of $STEPS
log By default, magisk will run scripts in /data/adb/service.d when late_start\(when you type password after reboot and powering on, android decrypt data and trigger late_start event\)
log If your root can run scripts /data/adb/service.d, you so lucky, because it will automaticly start sshd and other services
log So, to run $instpath/integrate.sh, i will create mini script at /data/adb/service.d/alpine4droid_$installpath.sh to run it
su -c "echo $instpath/integrate.sh > /data/adb/service.d/alpine4droid_installed.sh"
su -c "chmod +x /data/adb/service.d/alpine4droid_$installpath.sh"
log Setup done! Now you need to reboot your phone to start alpine for first time!
log Note: to install packages, run apk add <package1> <package2> ...
log Note 2: You need ssh client to access container, for example, JuiceSSH
log Note 3: Connection data: root@localhost
log Where root - is username
log localhost - is phone
log Note 4: Access alpine linux wiki for more info
log Note 5: Package list for beginners: xfce4
log git
log make
log gcc
log cmake
log python3
log Note 6: If apk add gives error like this : package not found, required by world[package], that means, package name wrong, or you need to compile itself
log Press any key to exit
read
echo --- end of alpine4droid setup log --- > setup_log.log