Skip to content

Commit bab8f4c

Browse files
committed
Enhance AppAPI script to improve container cleanup and Docker installation process
1 parent 6f417e5 commit bab8f4c

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

addons/appapi.sh

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,21 @@ then
102102
nextcloud_occ_no_check app:disable app_api
103103
fi
104104

105-
# Remove HaRP container if it exists
106-
if docker ps -a --format '{{.Names}}' | grep -q "^appapi-harp$"
105+
# Remove HaRP and ExApp containers
106+
if is_docker_running
107107
then
108-
print_text_in_color "$ICyan" "Removing HaRP container..."
109-
docker rm -f appapi-harp 2>/dev/null || true
108+
# Remove HaRP container (ghcr.io/nextcloud/nextcloud-appapi-harp)
109+
docker_prune_this 'nextcloud-appapi-harp'
110+
111+
# Remove all ExApp containers
112+
DOCKERPS=$(docker ps -a --format '{{.Names}}' | grep '^nc_app_' || true)
113+
if [ -n "$DOCKERPS" ]
114+
then
115+
for container_name in $DOCKERPS
116+
do
117+
docker_prune_this "$container_name"
118+
done
119+
fi
110120
fi
111121

112122
# Remove Apache proxy configuration for ExApps
@@ -175,17 +185,24 @@ fi
175185
# If we get here, we're installing/configuring
176186
install_popup "$SCRIPT_NAME"
177187

178-
# Check if Docker is available
188+
# Install Docker if not available
179189
if ! is_docker_running || [ ! -S /var/run/docker.sock ]
180190
then
181-
msg_box "Docker is not running on this system.
191+
msg_box "Docker is not installed or not running on this system.
182192
183-
AppAPI requires Docker to deploy External Apps. Please install Docker first:
193+
AppAPI requires Docker to deploy External Apps.
184194
185-
curl -fsSL https://get.docker.com | sh
195+
Docker will now be installed automatically."
196+
install_docker
197+
198+
# Verify Docker is now running
199+
if ! is_docker_running || [ ! -S /var/run/docker.sock ]
200+
then
201+
msg_box "Failed to install or start Docker.
186202
187-
After installing Docker, run this script again."
188-
exit 1
203+
Please check your system logs and try again."
204+
exit 1
205+
fi
189206
fi
190207

191208
# Check if www-data user can access docker socket
@@ -534,6 +551,22 @@ then
534551
print_text_in_color "$ICyan" "Starting test deployment..."
535552
print_text_in_color "$ICyan" "This may take 1-2 minutes for the first run (Docker image download)..."
536553

554+
# Clean up any existing test apps first
555+
if nextcloud_occ app_api:app:list 2>/dev/null | grep -q "test-deploy"
556+
then
557+
print_text_in_color "$ICyan" "Removing existing test-deploy ExApp..."
558+
nextcloud_occ_no_check app_api:app:disable test-deploy 2>/dev/null || true
559+
nextcloud_occ_no_check app_api:app:unregister test-deploy --silent --rm-data 2>/dev/null || true
560+
docker rm -f nc_app_test-deploy 2>/dev/null || true
561+
fi
562+
if nextcloud_occ app_api:app:list 2>/dev/null | grep -q "app-skeleton-python"
563+
then
564+
print_text_in_color "$ICyan" "Removing existing app-skeleton-python ExApp..."
565+
nextcloud_occ_no_check app_api:app:disable app-skeleton-python 2>/dev/null || true
566+
nextcloud_occ_no_check app_api:app:unregister app-skeleton-python --silent --rm-data 2>/dev/null || true
567+
docker rm -f nc_app_app-skeleton-python 2>/dev/null || true
568+
fi
569+
537570
# Register test ExApp using the official test-deploy app
538571
print_text_in_color "$ICyan" "Step 1/6: Registering test ExApp..."
539572
if ! nextcloud_occ app_api:app:register test-deploy "$DAEMON_NAME" \

0 commit comments

Comments
 (0)