-
Notifications
You must be signed in to change notification settings - Fork 1
/
skin-repair.sh
executable file
·82 lines (72 loc) · 1.83 KB
/
skin-repair.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
#!/bin/bash
# CHECK IF ANDROID_SDK_ROOT IS SET AND NON-EMPTY
if [ -z "$ANDROID_SDK_ROOT" ]; then
echo "Need to set ANDROID_SDK_ROOT"
echo "See https://developer.android.com/studio/command-line/variables.html#android_sdk_root for help"
exit 1
fi
# ANDROID VARIABLE
ANDROID_SKINS_DIRECTORY=$ANDROID_SDK_ROOT/skins
AVDMANAGER=$ANDROID_SDK_ROOT/tools/bin/avdmanager
# LIST AVAILABLE AVDS
AVDS=($($AVDMANAGER list avd | grep -w "Name:" | awk '{print $2}'))
if [ -z "$AVDS" ]
then
echo -e "No AVDs found."
exit 1
fi
COUNTER=0
for AVD in "${AVDS[@]}"
do
echo "[$COUNTER] $AVD"
COUNTER=$((COUNTER+1))
done
# USER SELECTS AVD-ID
AVD_ID="${#AVDS[@]}"
while [[ ! "$AVD_ID" =~ ^[0-9]+$ ]] || [[ ! "$AVD_ID" -lt "${#AVDS[@]}" ]]; do
echo -e "Please select the AVD number: \c"
read AVD_ID
done
AVD="${AVDS[$AVD_ID]}"
# LIST AVAILABLE SKINS
SKINS=($(ls $ANDROID_SKINS_DIRECTORY))
if [ -z "$SKINS" ]
then
echo -e "No Skins found."
exit 1
fi
COUNTER=0
for SKIN in "${SKINS[@]}"
do
echo "[$COUNTER] $SKIN"
COUNTER=$((COUNTER+1))
done
# USER SELECTS SKIN-ID
SKIN_ID="${#SKINS[@]}"
while [[ ! "$SKIN_ID" =~ ^[0-9]+$ ]] || [[ ! "$SKIN_ID" -lt "${#SKINS[@]}" ]]; do
echo -e "Please select the Skin number: \c"
read SKIN_ID
done
SKIN="${SKINS[$SKIN_ID]}"
# LINES TO APPEND
declare -a APP=("skin.name=$SKIN"
"skin.path=$ANDROID_SKINS_DIRECTORY/$SKIN"
"hw.gpu.enabled=yes"
"hw.gpu.mode=auto"
"hw.ramSize=1536"
"showDeviceFrame=yes"
"skin.dynamic=yes"
"hw.keyboard=yes"
)
# GET PATH OF AVD
AVD_PATH=$($AVDMANAGER list avd | grep -A 2 -w $AVD | grep Path | awk '{print $2}')
if [ -z "$AVD_PATH" ]; then
echo "AVD Path not found"
exit 1
fi
# APPEND LINES IF NOT EXIST
CONF_FILE=$AVD_PATH/config.ini
for line in "${APP[@]}"
do
grep -q -F "$line" $CONF_FILE || echo "$line" >> $CONF_FILE
done