@@ -134,14 +134,40 @@ setup_repository() {
134134 if command -v git & > /dev/null; then
135135 # Check if directory already exists
136136 if [ -d " $INSTALL_DIR " ]; then
137- # Check if it's a valid raspberry_ninja directory
138- if [ -f " $INSTALL_DIR /publish.py" ]; then
139- SCRIPT_DIR=" $INSTALL_DIR "
140- print_color " $GREEN " " ✓ Found existing installation at: $SCRIPT_DIR "
137+ SCRIPT_DIR=" $INSTALL_DIR "
138+ print_color " $YELLOW " " Directory $INSTALL_DIR already exists. Checking for updates..."
139+
140+ # Check if it's a git repository
141+ if [ -d " $INSTALL_DIR /.git" ]; then
142+ # Pull latest changes
143+ cd " $INSTALL_DIR "
144+ if git pull origin main; then
145+ print_color " $GREEN " " ✓ Updated to latest version"
146+ else
147+ print_color " $YELLOW " " ⚠ Could not update (may have local changes)"
148+ fi
149+ cd - > /dev/null
141150 else
142- print_color " $RED " " ✗ Directory $INSTALL_DIR already exists but doesn't contain Raspberry Ninja"
143- print_color " $RED " " Please remove it or choose a different location"
144- exit 1
151+ print_color " $YELLOW " " ⚠ Not a git repository, using as-is"
152+ fi
153+
154+ # Verify it's a valid installation
155+ if [ -f " $SCRIPT_DIR /publish.py" ]; then
156+ print_color " $GREEN " " ✓ Using existing installation at: $SCRIPT_DIR "
157+ else
158+ print_color " $YELLOW " " ⚠ Directory exists but publish.py not found. Attempting fresh clone..."
159+ # Try to clone into a temp dir and move files
160+ TEMP_DIR=" $( mktemp -d) "
161+ if git clone https://github.com/steveseguin/raspberry_ninja.git " $TEMP_DIR /raspberry_ninja" ; then
162+ cp -r " $TEMP_DIR /raspberry_ninja/" * " $INSTALL_DIR /" 2> /dev/null || true
163+ cp -r " $TEMP_DIR /raspberry_ninja/" .* " $INSTALL_DIR /" 2> /dev/null || true
164+ rm -rf " $TEMP_DIR "
165+ print_color " $GREEN " " ✓ Repository files copied to: $SCRIPT_DIR "
166+ else
167+ rm -rf " $TEMP_DIR "
168+ print_color " $RED " " ✗ Failed to get repository files"
169+ exit 1
170+ fi
145171 fi
146172 else
147173 if git clone https://github.com/steveseguin/raspberry_ninja.git " $INSTALL_DIR " ; then
@@ -189,14 +215,40 @@ setup_repository() {
189215 if command -v git & > /dev/null; then
190216 # Check if directory already exists
191217 if [ -d " $INSTALL_DIR " ]; then
192- # Check if it's a valid raspberry_ninja directory
193- if [ -f " $INSTALL_DIR /publish.py" ]; then
194- SCRIPT_DIR=" $INSTALL_DIR "
195- print_color " $GREEN " " ✓ Found existing installation at: $SCRIPT_DIR "
218+ SCRIPT_DIR=" $INSTALL_DIR "
219+ print_color " $YELLOW " " Directory $INSTALL_DIR already exists. Checking for updates..."
220+
221+ # Check if it's a git repository
222+ if [ -d " $INSTALL_DIR /.git" ]; then
223+ # Pull latest changes
224+ cd " $INSTALL_DIR "
225+ if git pull origin main; then
226+ print_color " $GREEN " " ✓ Updated to latest version"
227+ else
228+ print_color " $YELLOW " " ⚠ Could not update (may have local changes)"
229+ fi
230+ cd - > /dev/null
196231 else
197- print_color " $RED " " ✗ Directory $INSTALL_DIR already exists but doesn't contain Raspberry Ninja"
198- print_color " $RED " " Please remove it or choose a different location"
199- exit 1
232+ print_color " $YELLOW " " ⚠ Not a git repository, using as-is"
233+ fi
234+
235+ # Verify it's a valid installation
236+ if [ -f " $SCRIPT_DIR /publish.py" ]; then
237+ print_color " $GREEN " " ✓ Using existing installation at: $SCRIPT_DIR "
238+ else
239+ print_color " $YELLOW " " ⚠ Directory exists but publish.py not found. Attempting fresh clone..."
240+ # Try to clone into a temp dir and move files
241+ TEMP_DIR=" $( mktemp -d) "
242+ if git clone https://github.com/steveseguin/raspberry_ninja.git " $TEMP_DIR /raspberry_ninja" ; then
243+ cp -r " $TEMP_DIR /raspberry_ninja/" * " $INSTALL_DIR /" 2> /dev/null || true
244+ cp -r " $TEMP_DIR /raspberry_ninja/" .* " $INSTALL_DIR /" 2> /dev/null || true
245+ rm -rf " $TEMP_DIR "
246+ print_color " $GREEN " " ✓ Repository files copied to: $SCRIPT_DIR "
247+ else
248+ rm -rf " $TEMP_DIR "
249+ print_color " $RED " " ✗ Failed to get repository files"
250+ exit 1
251+ fi
200252 fi
201253 else
202254 if git clone https://github.com/steveseguin/raspberry_ninja.git " $INSTALL_DIR " ; then
0 commit comments