| | 379 | |
| | 380 | Use the image tar file from /file/alpine-arm64.tar that we already upload |
| | 381 | {{{ |
| | 382 | :do { |
| | 383 | # --- Certificate Cleanup --- |
| | 384 | :put "--- Starting Full Certificate Cleanup ---" |
| | 385 | # Find all certificates by their ID. The 'find' command returns a list of internal IDs. |
| | 386 | :local allCertIds [/certificate find] |
| | 387 | |
| | 388 | :if ([:len $allCertIds] > 0) do={ |
| | 389 | :put ("Found " . [:len $allCertIds] . " certificates. Removing all...") |
| | 390 | # The 'remove' command can take a list of IDs directly. |
| | 391 | /certificate remove $allCertIds |
| | 392 | :put "All certificates have been removed." |
| | 393 | } else={ |
| | 394 | :put "No certificates found to remove." |
| | 395 | } |
| | 396 | :put "--- Certificate Cleanup Complete ---" |
| | 397 | :delay 2s |
| | 398 | |
| | 399 | |
| | 400 | # --- Container Management --- |
| | 401 | :local cname "alpine" |
| | 402 | :put "Searching for existing container..." |
| | 403 | :local cid [/container find where name=$cname] |
| | 404 | |
| | 405 | :if ($cid != "") do={ |
| | 406 | :put ("Found existing container. Stopping and removing: " . $cname) |
| | 407 | #/container stop $cid |
| | 408 | #:delay 2s |
| | 409 | /container remove $cid |
| | 410 | :delay 5s |
| | 411 | } else={ |
| | 412 | :put ("No existing container found: " . $cname) |
| | 413 | } |
| | 414 | |
| | 415 | :put "Creating new alpine container..." |
| | 416 | /container add \ |
| | 417 | name=$cname \ |
| | 418 | file=alpine-arm64.tar \ |
| | 419 | interface=veth1 \ |
| | 420 | root-dir=ram \ |
| | 421 | logging=yes |
| | 422 | |
| | 423 | :delay 10s |
| | 424 | |
| | 425 | :local newcid [/container find where name=$cname] |
| | 426 | :if ($newcid = "") do={ |
| | 427 | :error "FATAL: Container was not created. Check logs for details." |
| | 428 | :put "FATAL: Container was not created" |
| | 429 | } |
| | 430 | |
| | 431 | :put ("Starting alpine container... ". $cname) |
| | 432 | /container start $cname |
| | 433 | :delay 10s |
| | 434 | |
| | 435 | # --- Verify Container is Running --- |
| | 436 | :put $cname |
| | 437 | :local status [/container print count-only where name=$cname and running=yes ] |
| | 438 | :if ($status != 1) do={ |
| | 439 | :error ("FATAL: Container failed to start. Current status: " . $status) |
| | 440 | } |
| | 441 | |
| | 442 | :put "Container is running. Proceeding with package installation..." |
| | 443 | |
| | 444 | # --- Setup Inside Container --- |
| | 445 | #:put "Installing packages (update, wget, python3...)" |
| | 446 | #/container shell $newcid cmd="apk update" |
| | 447 | #:delay 5s |
| | 448 | #/container shell $newcid cmd="apk add --no-cache python3 tzdata inetutils-telnet busybox-extras" |
| | 449 | #:delay 5s |
| | 450 | /container shell $newcid cmd="ln -s /usr/share/zoneinfo/Asia/Bangkok /etc/localtime" |
| | 451 | :delay 3s |
| | 452 | |
| | 453 | #:put "Downloading .profile..." |
| | 454 | #/container shell $newcid cmd="wget -O /root/.profile http://188.166.217.51/~krit/dot_profile" |
| | 455 | |
| | 456 | :put "---" |
| | 457 | :put "Alpine container setup complete and running successfully!" |
| | 458 | :put "---" |
| | 459 | } |
| | 460 | |
| | 461 | |
| | 462 | }}} |