forked from Whitebrim/VSCode-PlaydateTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·226 lines (205 loc) · 6.96 KB
/
setup.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
# Function to check if SDKPATH is valid
validate_sdkpath() {
if [[ ! $TEST && ( ! -f "$SDKPATH/bin/pdc" || ! -d "$SDKPATH/bin/Playdate Simulator.app" ) ]]; then
echo "Error: pdc executable or Playdate Simulator.app not found in $SDKPATH/bin/"
return 1
fi
return 0
}
# Function to update the shell profile
update_shell_profile() {
if [[ -f ~/.zshrc ]]; then
SHELL_PROFILE=~/.zshrc
elif [[ -f ~/.bashrc ]]; then
SHELL_PROFILE=~/.bashrc
elif [[ -f ~/.bash_profile ]]; then
SHELL_PROFILE=~/.bash_profile
fi
if [[ $TEST || $MENU_CHOICE ]]; then
echo -e "\033[1;33mDiff for $SHELL_PROFILE:\033[0m"
diff --color=always $SHELL_PROFILE <(echo -e "$(cat $SHELL_PROFILE)\nexport PLAYDATE_SDK_PATH=$SDKPATH\nexport PATH=\$PATH:$SDKPATH/bin")
fi
if [[ ! $TEST ]]; then
echo "export PLAYDATE_SDK_PATH=$SDKPATH" >> $SHELL_PROFILE
echo "export PATH=\$PATH:$SDKPATH/bin" >> $SHELL_PROFILE
if [[ "$SHELL" == "/bin/zsh" && "$SHELL_PROFILE" == "~/.zshrc" ]]; then
source $SHELL_PROFILE
elif [[ "$SHELL" == "/bin/bash" && "$SHELL_PROFILE" == "~/.bashrc" ]]; then
source $SHELL_PROFILE
fi
fi
}
# Function to update ~/.Playdate/startup.sh
update_startup() {
if [[ $TEST || $MENU_CHOICE ]]; then
echo -e "\033[1;33mDiff for ~/.Playdate/startup.sh:\033[0m"
diff --color=always ~/.Playdate/startup.sh <(sed "s|/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/bin:.*bin|/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/bin:$SDKPATH/bin|" ~/.Playdate/startup.sh)
fi
if [[ ! $TEST ]]; then
sed -i '' "s|/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/bin:.*bin|/usr/local/playdate/gcc-arm-none-eabi-9-2019-q4-major/bin:$SDKPATH/bin|" ~/.Playdate/startup.sh
fi
}
# Function to update ~/.Playdate/config
update_config() {
if [[ $TEST || $MENU_CHOICE ]]; then
echo -e "\033[1;33mDiff for ~/.Playdate/config:\033[0m"
diff --color=always ~/.Playdate/config <(sed "s|SDKRoot.*|SDKRoot\t$SDKPATH|" ~/.Playdate/config)
fi
if [[ ! $TEST ]]; then
sed -i '' "s|SDKRoot.*|SDKRoot\t$SDKPATH|" ~/.Playdate/config
fi
}
# Function to display help information
display_help() {
cat << EOF
Usage: ./setup.sh [OPTION] [SDK_PATH]
Set up the environment for the Playdate SDK.
Available options:
-a, --all Update all configurations (PATH, config, startup.sh)
-p, --path Update only the PATH variable
-c, --config Update only the config file
-s, --startup Update only the startup.sh file
-t, --test Test mode (Dry run)
-h, --help Display this help and exit
Example:
./setup.sh -a /path/to/PlaydateSDK
EOF
exit 0
}
# Manual argument parsing
while [[ $# -gt 0 ]]; do
case "$1" in
-a|--All)
ALL=true
SDKPATH="$2"
shift 2
;;
-t|--test)
TEST=true
SDKPATH="$2"
shift 2
;;
-h|--help)
display_help
;;
-*)
# Iterate over each character in the flag (e.g., -cp will check 'c' and 'p')
for (( i=1; i<${#1}; i++ )); do
char="${1:$i:1}"
case "$char" in
p)
PATH_UPDATE=true
;;
c)
CONFIG_UPDATE=true
;;
s)
STARTUP_UPDATE=true
;;
*)
echo "Invalid option: -$char" >&2
echo "Use -h or --help for usage information."
exit 1
;;
esac
done
SDKPATH="$2"
shift 2
;;
*)
echo "Invalid argument: $1" >&2
exit 1
;;
esac
done
# If no flags are provided, show the menu
if [[ -z $ALL && -z $PATH_UPDATE && -z $CONFIG_UPDATE && -z $STARTUP_UPDATE && -z $TEST ]]; then
echo "1. Update \$PATH"
echo "2. Update config + startup.sh"
echo "3. Update All"
echo "4. Test (Dry run)"
read -p "Please select an option: " choice
case $choice in
1)
read -p "Please enter the path to the SDK: " SDKPATH
PATH_UPDATE=true
MENU_CHOICE=true
;;
2)
read -p "Please enter the path to the SDK: " SDKPATH
CONFIG_UPDATE=true
STARTUP_UPDATE=true
MENU_CHOICE=true
;;
3)
read -p "Please enter the path to the SDK: " SDKPATH
ALL=true
MENU_CHOICE=true
;;
4)
read -p "Please enter the path to the SDK: " SDKPATH
TEST=true
;;
*)
echo "Invalid choice"
exit 1
;;
esac
if [[ ! $TEST ]]; then
read -p "Are you sure you want to update with the provided SDK path? [Y/n]: " confirm
if [[ $confirm != "Y" && $confirm != "y" ]]; then
echo "Update canceled."
exit 0
fi
echo "Updating..."
fi
fi
# Validate the SDK path
validate_sdkpath
if [ $? -ne 0 ]; then
exit 1
fi
# Perform the updates based on the flags or menu choice
if [[ $ALL || $PATH_UPDATE || $TEST || $MENU_CHOICE ]]; then
update_shell_profile
fi
if [[ $ALL || $CONFIG_UPDATE || $TEST || $MENU_CHOICE ]]; then
update_config
fi
if [[ $ALL || $STARTUP_UPDATE || $TEST || $MENU_CHOICE ]]; then
update_startup
fi
if [[ $TEST ]]; then
echo "Done! Ran test successfully for path: $SDKPATH"
elif [[ $PATH_UPDATE ]]; then
echo -e "Done! Updated \$PATH successfully for path: $SDKPATH.\nPATH is now $PATH"
elif [[ $CONFIG_UPDATE && $STARTUP_UPDATE ]]; then
echo -e "Done! Updated config and startup successfully for path: $SDKPATH."
echo -e "config:"
cat ~/.Playdate/config
echo -e "\nstartup.sh:"
cat ~/.Playdate/startup.sh
elif [[ $CONFIG_UPDATE && $PATH_UPDATE ]]; then
echo -e "Done! Updated config and startup successfully for path: $SDKPATH.\nPATH is now $PATH"
echo -e "config:"
cat ~/.Playdate/config
elif [[ $STARTUP_UPDATE && $PATH_UPDATE ]]; then
echo -e "Done! Updated config and startup successfully for path: $SDKPATH.\nPATH is now $PATH"
echo -e "startup.sh:"
cat ~/.Playdate/startup.sh
elif [[ $STARTUP_UPDATE ]]; then
echo -e "Done! Updated startup successfully for path: $SDKPATH."
echo -e "\nstartup.sh:"
cat ~/.Playdate/startup.sh
elif [[ $CONFIG_UPDATE ]]; then
echo -e "Done! Updated config successfully for path: $SDKPATH."
echo -e "config:"
cat ~/.Playdate/config
elif [[ $ALL || ( $PATH_UPDATE && $CONFIG_UPDATE && $STARTUP_UPDATE ) ]]; then
echo -e "Done! Updated \$PATH successfully for path: $SDKPATH.\nPATH is now $PATH"
echo -e "config:"
cat ~/.Playdate/config
echo -e "\nstartup.sh:"
cat ~/.Playdate/startup.sh
fi