Changes between Version 18 and Version 19 of RB1100AHX4


Ignore:
Timestamp:
12/23/25 15:10:36 (2 weeks ago)
Author:
krit
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RB1100AHX4

    v18 v19  
    241241
    242242}}}
     243
     244
     245script for install alpine as container and start
     246{{{
     247
     248:do {
     249    # --- Certificate Cleanup ---
     250    :put "--- Starting Full Certificate Cleanup ---"
     251    # Find all certificates by their ID. The 'find' command returns a list of internal IDs.
     252    :local allCertIds [/certificate find]
     253 
     254    :if ([:len $allCertIds] > 0) do={
     255        :put ("Found " . [:len $allCertIds] . " certificates. Removing all...")
     256        # The 'remove' command can take a list of IDs directly.
     257        /certificate remove $allCertIds
     258        :put "All certificates have been removed."
     259    } else={
     260        :put "No certificates found to remove."
     261    }
     262    :put "--- Certificate Cleanup Complete ---"
     263    :delay 2s
     264 
     265 
     266    # --- Container Management ---
     267    :local cname "alpine"
     268    :put "Searching for existing container..."
     269    :local cid [/container find where name=$cname]
     270 
     271    :if ($cid != "") do={
     272        :put ("Found existing container. Stopping and removing: " . $cname)
     273        #/container stop $cid
     274        #:delay 2s
     275        /container remove $cid
     276        :delay 5s
     277    } else={
     278        :put ("No existing container found: " . $cname)
     279    }
     280 
     281    :put "Creating new alpine container..."
     282    /container add \
     283        name=$cname \
     284        remote-image=library/alpine:latest \
     285        interface=veth1 \
     286        root-dir=ram \
     287        cmd="/bin/sh -c 'trap : TERM INT; sleep infinity & wait'" \
     288        logging=yes
     289 
     290    :delay 10s
     291 
     292    :local newcid [/container find where name=$cname]
     293    :if ($newcid = "") do={
     294        :error "FATAL: Container was not created. Check logs for details."
     295        :put "FATAL: Container was not created"
     296    }
     297 
     298    :put ("Starting alpine container... ". $cname)
     299    /container start $cname
     300    :delay 10s
     301     # --- Verify Container is Running ---
     302    :put $cname
     303    :local status [/container print count-only where name=$cname and running=yes ]
     304    :if ($status != 1) do={
     305        :error ("FATAL: Container failed to start. Current status: " . $status)
     306    }
     307 
     308    :put "Container is running. Proceeding with package installation..."
     309 
     310    # --- Setup Inside Container ---
     311    :put "Installing packages (update, wget, python3...)"
     312    /container shell $newcid cmd="apk update"
     313    :delay 5s
     314    /container shell $newcid cmd="apk add --no-cache python3 tzdata inetutils-telnet busybox-ext>
     315    :delay 5s
     316    /container shell $newcid cmd="ln -s /usr/share/zoneinfo/Asia/Bangkok /etc/localtime"
     317    :delay 3s
     318 
     319    :put "Downloading .profile..."
     320    /container shell $newcid cmd="wget -O /root/.profile http://188.166.217.51/~krit/dot_profile"
     321 
     322    :put "---"
     323    :put "Alpine container setup complete and running successfully!"
     324    :put "---"
     325}
     326 
     327}}}