-
Notifications
You must be signed in to change notification settings - Fork 85
/
target_new_environment
executable file
·78 lines (68 loc) · 2.06 KB
/
target_new_environment
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
#!/bin/bash -e
#author: mike.maietta
function pp {
printf "\n%s\n" "$@"
}
pp "This script is meant to re-target a non-Clover device's environment." "Do not attempt to run this on a Clover device."
URL=""
TARGET=""
DEVICE=""
DATABASE="/data/data/com.android.providers.settings/databases/settings.db"
DEVICES=(`adb devices | tail -n +2 | perl -nle 'print $& if m{.+(?=\Wdevice)}'`)
DEVICE_COUNT=${#DEVICES[@]}
if [ $DEVICE_COUNT -eq 0 ]; then
echo "No Android devices detected"
exit
fi
if [ $DEVICE_COUNT -eq 1 ]; then
DEVICE=${DEVICES[0]}
else
pp "Please select a connected device"
for (( i = 1; i <= $DEVICE_COUNT; i++ )); do
echo "$i) ${DEVICES[ $((i - 1)) ]}"
done
echo -n "#? "
read INPUT
if [ $INPUT -gt $DEVICE_COUNT ] & [ $INPUT -lt 1 ]; then
pp "Invalid input"
exit
fi
DEVICE="${DEVICES[ $((INPUT - 1)) ]}"
fi
pp "Selected device:" "${DEVICES}"
pp "Please select your desired target environment:"
select environment in "Prod-US" "Prod-EU" "Sandbox" "Localhost"; do
case $environment in
Prod-US )
URL="https://api.clover.com/"
TARGET="prod"
break;;
Prod-EU )
URL="https://api.eu.clover.com/"
TARGET="prod_eu"
break;;
Sandbox )
URL="https://apisandbox.dev.clover.com/"
TARGET="dev"
break;;
Localhost )
MYIP=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | head -n1)
URL="http://$MYIP"
TARGET="local"
break;;
esac
done
pp "Updating target to ${URL}"
COMMAND=`adb -s "$DEVICE" shell "
sqlite3 -header -line ${DATABASE} \
\"delete from secure where name = 'clover_cloud_url';
delete from secure where name = 'clover_target';
insert into secure (name, value) values ('clover_cloud_url','${URL}');
insert into secure (name, value) values ('clover_target','${TARGET}');\""`
# COMMAND_RESULT=`echo "$COMMAND" | tail -1`
if echo "$COMMAND" | grep "/system/bin/sh: sqlite3: not found"; then
pp "Unable to update device target. sqlite3 is not accessible on the device."
else
pp "You will need to 'Add Account' via Settings to set up your device"
adb -s "$DEVICE" shell pm clear com.clover.engine
fi