New Entity AI



dugout-> connection_mainframe.dugout



Define default connection-related routines. Assuming that standard tools are in place like SSH and scp, provide standardized wrappers for each type of process that utilizes 1 scoped routine. This applies for the connection tool, 1->N, and the routines, 1->N.


            
  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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/sh
###############################################################################
## COPYRIGHT (C) 2020-2026 NEW ENTITY OPERATIONS INC. ALL RIGHTS RESERVED
## INSTANCE: connection_mainframe.dugout
## MODIFIED: 2026/06/19
## OVERVIEW: Define default connection-related routines
## 
## Default ports are set within CONFIGURATION_PORT_DEV and
## CONFIGURATION_PORT_DEV_COPY. The _COPY extension is for put/pull related
## activities, where the non _COPY extension is for connection routines only
##
## connection_mainframe is a controller to do setup tasks and perform critical
## backups from critical systems over the network. This includes git access and
## ssh instance hooking 
###############################################################################
## @ based routines (Add in dynamic query-based routines so you don't have to
## keep static locations
###############################################################################
export COMMAND_CONNECTION_ARGS_FROM="${DEFAULT_COMMAND_CONNECTION_FROM}"
export COMMAND_CONNECTION_ARGS_TO="${DEFAULT_COMMAND_CONNECTION_TO}"

## Update your COMMAND_CONNECTION_ARGS_FROM/TO instances
DYNAMIC_CONNECTION_ROUTINE_FROM() {
 ## Use: Provide custom connection values using the dcrf interface 
 ## dcrf ssh -i <KEY_LOCATION_HERE> -p <PORT_HERE> <USER_HERE>@<IP_HERE>
 set -- $*
 export COMMAND_CONNECTION_ARGS_FROM="$*"
 alert_connection_args_from "${COMMAND_CONNECTION_ARGS_FROM}"
}

DYNAMIC_CONNECTION_ROUTINE_TO() {
 ## Use: Provide custom connection values using the dcrt interface 
 ## dcrt ssh -i <KEY_LOCATION_HERE> -p <PORT_HERE> <USER_HERE>@<IP_HERE>
 set -- $*
 export COMMAND_CONNECTION_ARGS_TO="$*"
 alert_connection_args_to "${COMMAND_CONNECTION_ARGS_TO}"
}

###############################################################################
## Access a remote web server
###############################################################################
## DEV_SERVER: Default
###############################################################################
## Go to the branch on the external server
GO_TO_BRANCH_DEV_SERVER() {
 alert_connection_initiated_ssh "DEV_SERVER"
 td_dash_forty
 alert_connection_to_destination_with_user "${DSIP}" "${DEVUSER}"
 td_dash_forty
 alert_connection_details_summary "${SLUG_SERVER_KEY}" ${CONFIGURATION_PORT_DEV} "${DEVUSER}" "${DSIP}"
 td_dash_forty
 ssh -i "${SLUG_SERVER_KEY}" -p ${CONFIGURATION_PORT_DEV} "${DEVUSER}@${DSIP}"
}

###############################################################################
## Nth DEV_SERVER
###############################################################################
#GO_TO_*CONTEXT*_*LOCATION*() {
# alert_connection_initiated_ssh "*REPLACE SERVER NAME HERE*"
# td_dash_forty
# alert_connection_to_destination_with_user "*REPLACE SERVER DESTINATION IP HERE*" "*REPLACE SERVER ACCESS USER HERE*"
# td_dash_forty
# alert_connection_details_summary "*SERVER KEY LOCATION HERE*" *PORT FOR DEVELOPMENT MACHINE CONNECTION HERE* "*REPLACE SERVER ACCESS USER HERE*" "*REPLACE SERVER ACCESS IP HERE*"
# td_dash_forty
# ssh -i "*SERVER KEY LOCATION HERE*" -p "*DEV MACHINE Nth CONNECTION PORT HERE*" "*SERVER ACCESS USER HERE*@*SERVER_ACCESS_IP_HERE*"
#}

###############################################################################
## Copy from a server to a local resource with scp: Branches Enforced
###############################################################################
## Copy from-> Global Development Server Variables
## Use: Transfer from the Development server IP: DSIP
## Methods:
## Method 1: Raw
##
##  COPY_SLUG_FROM_SERVER
##
##      : This method is done raw. It takes a default location (/home/<USER>/CORE_HOST/CORE_HOST_branch_0.tar.gz)
##        and backs it up into the default unpacking location (/srv/http/COREHOST/EXTRA/trine/FILTER/|_|FILTER_MACHINES/FROM_STOCK_0/CORE_HOST_branch_0.tar.gz)
##        if this location exists, you can overwrite it by supplying the 1 option. 0 will skip the backup.
##        If there is no backup on the server available (/home/<USER>/CORE_HOST/CORE_HOST_branch_0.tar.gz), it fails.
## Method 2: Borken down into 2 (A) and 2 (B): They both are Supplied overrides
##  Method 2 (A): Provide 1 direct overriden slug
##
##   COPY_SLUG_FROM_SERVER CUSTOM_ARCHIVE.tar
##
##        If 2 is empty here, you are dealing with a default path location: i.e. /home/<USER>/CORE_HOST/CUSTOM_ARCHIVE_X.tar
##        This means you are defaulting to the assumed developer location provided by "/home/${DEVUSER}/${DDEVPROJECT}/${1}"
##        The ${1} variable is a custom, non-standard archive file instance. i.e. 1-> CUSTOM_ARCHIVE.tar
##
##  Method 2 (B): Provide 2 direct overriden slugs
##
##   COPY_SLUG_FROM_SERVER /mnt/archive/ ARCHIVE_IN_MOUNT.tar
##
##        You are supplying 2 commands to COPY_SLUG_FROM_SERVER
##        ${1} is the path (/mnt/archive/)
##        ${2} is the archive endpoint (ARCHIVE_IN_MOUNT.tar)
##        You are still backing up the final ${2} location to the generic unpacking location (/srv/http/COREHOST/EXTRA/trine/FILTER/|_|FILTER_MACHINES/FROM_STOCK_0/ARCHIVE_IN_MOUNT.tar)
##
##        If 2 is not empty, you are dealing with a custom path location and file always: i.e. /CUSTOM/LOCATION/CUSTOM_FILE.txt
##        We only need to check for the 2nd instance to know if we are overriding everything or not, which is the instance provided: i.e. CUSTOM_FILE.txt
##        Custom scopes require a fully qualified path and an actual file instance. i.e. 1-> /home/<USER>/CORE_HOST/ 2-> a.txt
##        Command Example::: COPY_SLUG_FROM_SERVER /home/<USER>/CORE_HOST/ a.txt
##
## Please note* This is not a archive via rsync which would require different setup commands.
##  this script assumes you are extracting an archive

## COPY_SLUG_FROM_SERVER
COPY_SLUG_FROM_SERVER() {
 alert_connection_initiated_scp "${DSIP}"
 td_dash_forty
 alert_connection_to_destination_with_user "${DSIP}" "${DEVUSER}"
 td_dash_forty
 ## Method 1
 ## If no arguements are supplied, proceed to this chain
 if [ -z "${1}" ]; then
  alert_connection_scp_summary_external "${SLUG_SERVER_KEY}" ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}" "${DSIP}" "${DEVUSER}" "${DDEVPROJECT}" "${branch_name}" "${bbext}" "${PATH_FROM_STOCK_0}"
  td_dash_forty
  if [ -d "${PATH_FROM_STOCK_0}" ]; then
   if [ -f "${PATH_FROM_STOCK_0}${branch_name}${bbext}" ]; then
    ## If the branch already exists, abort without a confirmation check
    alert_connection_scp_external_branch_exists "${PATH_FROM_STOCK_0}${branch_name}${bbext}"
    alert_confirmation_already_exists_overwrite
    printf "Confirm with 1, or terminate with 0. \n" >&2
    read -r confirmation_check
    if [ "$confirmation_check" = "1" ]; then
     ## Standard directories only
     scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/${branch_name}${bbext}" "${PATH_FROM_STOCK_0}"
    else
     alert_connection_terminated_with_key
    fi
   else
    ## If the branch does not already exists, continue with no confirmations. If the archive isn't found on the server, it will fail
    alert_connection_scp_interal_branch_does_not_exists "${PATH_FROM_STOCK_0}${branch_name}${bbext}"
    ## Standard directories only
    scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/${branch_name}${bbext}" "${PATH_FROM_STOCK_0}"
   fi
  else
   alert_connection_destination_invalid "${PATH_FROM_STOCK_0}"
  fi
 ## Method 2
 else
  ## We always unpack into the common directory, PATH_FROM_STOCK_0
  if [ -d "${PATH_FROM_STOCK_0}" ]; then
   ## Method 2 (A)
   if [ -z "${2}" ]; then
    alert_connection_special_branch_logic "${SLUG_SERVER_KEY}" ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}" "${DSIP}" "/home/${DEVUSER}/${DDEVPROJECT}/${1}" "${PATH_FROM_STOCK_0}" "/home/${DEVUSER}/${DDEVPROJECT}/${1}"
    td_dash_forty
    ## Command Example::: COPY_SLUG_FROM_SERVER a.txt
    if [ -f "${PATH_FROM_STOCK_0}${1}" ]; then
     alert_confirmation_already_exists_overwrite
     alert_connection_scp_external_branch_does_not_exists "${PATH_FROM_STOCK_0}${1}"
     printf "Confirm with 1, or terminate with 0. \n" >&2
     read -r confirmation_check
     if [ "$confirmation_check" = "1" ]; then
     ## Defaults to the generic location for DDEVPROJECT activity
      scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/${1}" "${PATH_FROM_STOCK_0}"
     else
      alert_connection_terminated_with_key
     fi
    else
     ## If the branch does not already exists, continue with no confirmations. If the archive isn't found on the server, it will fail
     alert_connection_scp_external_branch_does_not_exists "${PATH_FROM_STOCK_0}${1}"
     ## Defaults to the generic location for DDEVPROJECT activity
     scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/${1}" "${PATH_FROM_STOCK_0}"
    fi
   ## Method 2 (B)
   else
    alert_connection_special_branch_logic "${SLUG_SERVER_KEY}" ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}" "${DSIP}" "${1}${2}" "${PATH_FROM_STOCK_0}" "${1}${2}"
    td_dash_forty
    if [ -f "${PATH_FROM_STOCK_0}${2}" ]; then
     alert_confirmation_already_exists_overwrite
     printf "Confirm with 1, or terminate with 0. \n" >&2
     read -r confirmation_check
     if [ "$confirmation_check" = "1" ]; then
      scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}@${DSIP}:${1}${2}" "${PATH_FROM_STOCK_0}"
     else
      alert_connection_terminated_with_key
     fi
    else
     ## If the branch does not already exists, continue with no confirmations. If the archive isn't found on the server, it will fail
     alert_connection_scp_external_branch_does_not_exists "${PATH_FROM_STOCK_0}${2}"
     scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${DEVUSER}@${DSIP}:${1}${2}" "${PATH_FROM_STOCK_0}"
    fi
   fi
  else
   alert_connection_destination_invalid "${PATH_FROM_STOCK_0}"
  fi
 fi
}

## Emulate the mold of the first section in order to extend your access automation routines
#DO_DSIP_*CONTEXT*() {
# scp -i <KEY_LOCATION_HERE> -P <PORT_IN_USE_HERE> $DEVUSER@$DSIP:*<PATH_TO_RESOURCE>* *LOCAL_LOCATION*
#}

###############################################################################
## Copy to a server from a local resources: Branches Enforced (Working 2025/05/24)
###############################################################################
## Default copyto slug and destination
COPY_SLUG_TO_SERVER() {
 ## COPY_SLUG_TO_SERVER takes 0, or 1 arguement. When 0 arguements are provided,
 ## the default location PATH_FROM_STOCK_0+asset_transfer_location is used.
 ## When 1 arguement is provided, it should be an absolute path to the instance
 ## you wish to transfer. The PATH_FROM_STOCK_0 destination is checked for this
 ## instance first, in the event you are just passing a custom archive to transfer
 ## If that isn't found in PATH_FROM_STOCK_0, you will default to the absolute
 ## path of the provided instance
 alert_connection_initiated_scp "${DSIP}"
 td_dash_forty
 alert_connection_to_destination_with_user "${DSIP}" "${DEVUSER}"
 td_dash_forty
 ## Naked COPY_SLUG_TO_SERVER defaults to pushing the default preset instance value
 if [ -z "${1}" ]; then
  td_dash_forty
  if [ -d "${PATH_FROM_STOCK_0}${asset_transfer_location}" ]; then
   alert_connection_scp_summary_internal_directory "${SLUG_SERVER_KEY}" "${CONFIGURATION_PORT_DEV_COPY}" "${PATH_FROM_STOCK_0}${asset_transfer_location}" "${DEVUSER}" "${DSIP}" "${DDEVPROJECT}" 
   scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} -r "${PATH_FROM_STOCK_0}${asset_transfer_location}" "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/"
  else
   if [ -f "${PATH_FROM_STOCK_0}${asset_transfer_location}" ]; then
    ## All other cases default to the file case
    alert_connection_scp_summary_internal_file "${SLUG_SERVER_KEY}" "${CONFIGURATION_PORT_DEV_COPY}" "${PATH_FROM_STOCK_0}${asset_transfer_location}" "${DEVUSER}" "${DSIP}" "${DDEVPROJECT}" 
    scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${PATH_FROM_STOCK_0}${asset_transfer_location}" "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/"
   ## If this location does not exist
   else
    alert_connection_scp_archive_unavailable "${PATH_FROM_STOCK_0}${asset_transfer_location}"
   fi
  fi
 else
  alert_connection_scp_internal_branch_in_use "${1}"
  td_dash_forty
  if [ -f "${PATH_FROM_STOCK_0}${1}" ]; then
   alert_connection_scp_summary_internal_archive "${SLUG_SERVER_KEY}" "${PATH_FROM_STOCK_0}" "${asset_transfer_location}" "${DEVUSER}" "${DSIP}" "${DDEVPROJECT}" ${CONFIGURATION_PORT_DEV_COPY}
   scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${PATH_FROM_STOCK_0}${asset_transfer_location}" "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/"
  else
   alert_connection_scp_archive_unavailable_custom "${PATH_FROM_STOCK_0}${1}"
   alert_confirmation_check_if_directory_transfer_exists
   printf "Confirm with 1, or terminate with 0. \n" >&2
   read -r confirmation_check
   if [ "$confirmation_check" = "1" ]; then
    if [ -d "${1}" ]; then
      alert_connection_scp_summary_internal_custom_directory "${SLUG_SERVER_KEY}" "${CONFIGURATION_PORT_DEV_COPY}" "${1}" "${DEVUSER}" "${DSIP}" "${DDEVPROJECT}" "${1}"
      scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} -r "${1}" "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/"
    else
     if [ -f "${1}" ]; then
      alert_connection_scp_summary_internal_custom_file "${SLUG_SERVER_KEY}" "${CONFIGURATION_PORT_DEV_COPY}" "${1}" "${DEVUSER}" "${DSIP}" "${DDEVPROJECT}" "${1}"
      scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${1}" "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/"
     else
      ## All other cases default to the file case
      alert_connection_scp_summary_internal_custom_file "${SLUG_SERVER_KEY}" "${CONFIGURATION_PORT_DEV_COPY}" "${1}" "${DEVUSER}" "${DSIP}" "${DDEVPROJECT}" "${1}"
      scp -i "${SLUG_SERVER_KEY}" -P ${CONFIGURATION_PORT_DEV_COPY} "${1}" "${DEVUSER}@${DSIP}:/home/${DEVUSER}/${DDEVPROJECT}/"
     fi
    fi
   else
    alert_connection_scp_archive_unavailable_no_checks
   fi
  fi
 fi
}

## Emulate the mold of the first section in order to extend your access automation routines
#COPY_*CONTEXT*_SLUG_TO_SERVER() {
# scp -i "*SLUG SERVER KEY LOCATION HERE*" -P "*CONNECTION INBOUND MAINFRAME PORT HERE*" -r "*LOCAL_LOCATION*" "${DEVUSER}@${DSIP}:*<PATH_TO_RESOURCE>*"
#}