-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_scripts.sh
More file actions
executable file
·76 lines (63 loc) · 2 KB
/
copy_scripts.sh
File metadata and controls
executable file
·76 lines (63 loc) · 2 KB
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
#!/bin/bash
set -e
source ./common.sh
ADB_EXE="${ADB_EXE:-adb}"
SCRIPTS_PATH="android"
CHROOT_PATH="/data/chroot"
echo "ADB_EXE: ${ADB_EXE}"
echo "CHROOT_PATH: ${CHROOT_PATH}"
print_wsl2_warn() {
log_warn "If you are using WSL2, you need to set the ADB_EXE env variable"
log_warn "to the full path of the Windows version of adb (example: /mnt/c/android_platform_tools/adb.exe)"
}
log_info "Checking devices (make sure to only have one device plugged in)"
if ! command -v "${ADB_EXE}" >/dev/null 2>&1; then
log_error "Cannot find adb"
print_wsl2_warn
exit
fi
if ! $ADB_EXE get-state >/dev/null 2>&1; then
log_error "No adb devices are available"
print_wsl2_warn
exit 1
fi
log_info "Restarting adb as root"
if ! $ADB_EXE root >/dev/null 2>&1; then
log_error "Failed to restart adb as root"
exit 1
fi
log_info "Validating environment"
if ! $ADB_EXE shell busybox >/dev/null 2>&1; then
log_error "Could not find or execute busybox"
log_error "Make sure it is installed and is available in the adb shell path"
exit 1
fi
if ! $ADB_EXE shell busybox stat "${CHROOT_PATH}" >/dev/null 2>&1; then
log_error "Could not find ${CHROOT_PATH}"
log_error "Create the directory, copy out/rootfs.img and try again"
exit 1
fi
push_file() {
log_info "Pushing \"$1\" to \"$2\""
# Need to disable errexit temporarily
# The command substitution would trigger errexit on a non 0 exit code
# Also the local is assigned separately because it would eat the exit code
set +e
local result
result=$($ADB_EXE push "$1" "$2" 2>&1)
local status="$?"
set -e
if [ "${status}" != "0" ]; then
log_error "Failed to push \"$1\": ${result}"
exit 1
fi
}
push_file "${SCRIPTS_PATH}/common.sh" "${CHROOT_PATH}/"
push_file "${SCRIPTS_PATH}/mount.sh" "${CHROOT_PATH}/"
push_file "${SCRIPTS_PATH}/login.sh" "${CHROOT_PATH}/"
push_file "${SCRIPTS_PATH}/unmount.sh" "${CHROOT_PATH}/"
log_info "Adjusting permissions"
if ! $ADB_EXE shell busybox chmod +x "${CHROOT_PATH}/*.sh" >/dev/null 2>&1; then
log_error "Could not adjust permissions"
exit 1
fi