apt-get update apt-get -y install jq apt-get -y install wget ca-certificates BRAND_ID='BRAND_ID' SP_CREDS='cid_WcP8QHakbWNjxUjH:yshEqfwXgyRkef96yRcsg5x6gLqO9TpA56fikKZEohk' SP_RESPONSE=$(curl https://api.serverpilot.io/v1/servers -u cid_WcP8QHakbWNjxUjH:yshEqfwXgyRkef96yRcsg5x6gLqO9TpA56fikKZEohk -H 'Content-Type: application/json' -d '{\"name\":\"'$BRAND_ID'\"}') echo $SP_RESPONSE SERVERID=$(echo $SP_RESPONSE | jq -r '.data.id') SERVERKEY=$(echo $SP_RESPONSE | jq -r '.data.apikey') GET_INSTALL=$(wget -nv -O serverpilot-installer https://download.serverpilot.io/serverpilot-installer) ATTEMPT_INSTALL=$(sh serverpilot-installer --server-id=$SERVERID --server-apikey=$SERVERKEY) sleep 240 SERVER_INFO=$(curl https://api.serverpilot.io/v1/servers/$SERVERID -u $SP_CREDS) NEW_IP_ADDRESS=$(echo $SERVER_INFO | jq -r '.data.lastaddress') curl -u 'managemyplatform@gmail.com:gucci_shoes_fendi_BAAG$' -H 'Content-Type: application/json' -d '{\"name\":\"'$BRAND_ID'\",\"type\":\"A\",\"content\":\"'$NEW_IP_ADDRESS'\"}' https://api.dnsimple.com/v2/109861/zones/app.brandservices.com/records sleep 15 RANDOM_SFTP_USER='randomsftpuser443' RANDOM_SFTP_PW='sftp_password' RANDOM_DB_AND_DB_USER_NAMES='username123' RANDOM_DB_PW='db_password' CREATE_USER=$( curl https://api.serverpilot.io/v1/sysusers -u $SP_CREDS -H 'Content-Type: application/json' -d '{\"serverid\":\"'$SERVERID'\",\"name\":\"'$RANDOM_SFTP_USER'\",\"password\":\"'$RANDOM_SFTP_PW'\"}' ) NEW_SP_USER_ID=$(echo $CREATE_USER | jq -r '.data.id') CREATE_APP=$(curl https://api.serverpilot.io/v1/apps -u $SP_CREDS -H 'Content-Type: application/json' -d '{\"name\":\"'$BRAND_ID'\",\"sysuserid\":\"'$NEW_SP_USER_ID'\",\"runtime\":\"php7.4\",\"domains\":[\"'$BRAND_ID'.app.brandservices.com\"]}' ) NEW_APP_ID=$(echo $CREATE_APP | jq -r '.data.id') sleep 20 REQUEST_SSL=$(curl https://api.serverpilot.io/v1/apps/$NEW_APP_ID/ssl -u $SP_CREDS -H 'Content-Type: application/json' -d '{"\auto\": true}') sleep 20 FORCE_SSL=$(curl https://api.serverpilot.io/v1/apps/$NEW_APP_ID/ssl -u $SP_CREDS -H 'Content-Type: application/json' -d '{"\force\": true}') CREATE_DB=$(curl https://api.serverpilot.io/v1/dbs -u $SP_CREDS -H 'Content-Type: application/json' -d '{"\appid\":\"'$NEW_APP_ID'\",\"name\":\"'$RANDOM_DB_AND_DB_USER_NAMES'\",\"user\":{"\name\":\"'$RANDOM_DB_AND_DB_USER_NAMES'\",\"password\":\"'$RANDOM_DB_PW'\"}}') sleep 10 rm -rfv /srv/users/$RANDOM_SFTP_USER/apps/$BRAND_ID/* SERVERNAME='localhost' git clone https://brand-services:this_should_be_changed@github.com/brand-services/app_schema.git /srv/users/$RANDOM_SFTP_USER/apps/$BRAND_ID mysql -h$SERVERNAME -u$RANDOM_DB_AND_DB_USER_NAMES -p$RANDOM_DB_PW $RANDOM_DB_AND_DB_USER_NAMES < /srv/users/$RANDOM_SFTP_USER/apps/$BRAND_ID/db.sql rm -rfv /srv/users/$RANDOM_SFTP_USER/apps/$BRAND_ID/* rm -r /srv/users/$RANDOM_SFTP_USER/apps/$BRAND_ID/.git git clone https://brand-services:this_should_be_changed@github.com/brand-services/app.git /srv/users/$RANDOM_SFTP_USER/apps/$BRAND_ID PLATFORM_MANAGER_CREDS='Y2xpZW50X3NsVW5wQldDUW5HSmdJdkRDSVAyOkZBUjczS3ltVUM2Y05RdThsZ0E2eThGSks1ZGVEVGFkblZhZ3hEdWw=' PLATFORM_MANAGER_REFRESH='7a3gSFMz3E3IrjsJPYpaYkB7VSehZFl2Je8xNKWL' PLATFORM_MANAGER_STORE_ID='57090' AUTHORIZE_PLATFORM_MANAGER_FOXY=$(curl -H 'FOXY-API-VERSION: 1' -H 'Authorization: Basic $PLATFORM_MANAGER_CREDS' https://api.foxycart.com/token -d 'grant_type=refresh_token&refresh_token=$PLATFORM_MANAGER_REFRESH') PLATFORM_MANAGER_AUTH_TOKEN=$(echo $AUTHORIZE_PLATFORM_MANAGER_FOXY | jq -r '.access_token') CREATE_STORE=$(curl -H 'FOXY-API-VERSION: 1' -H 'Authorization: Bearer $PLATFORM_MANAGER_AUTH_TOKEN' https://api.foxycart.com/users/$PLATFORM_MANAGER_STORE_ID/stores -d 'store_name=$BRAND_ID&use_remote_domain=1&store_domain=$BRAND_ID.brandservices.com&store_url=https://$BRAND_ID.app.brandservices.com&store_email=$BRAND_ID@brandservices.com&postal_code=77018®ion=TX&country=US&use_cart_validation=1&use_single_sign_on=1&webhook_key=TESTKEYTESTKEYTESTKEY&single_sign_on_url=https://$BRAND_ID.app.brandservices.com/account&customer_password_hash_type=bcrypt&customer_password_hash_config=10&app_session_time=1209600&unified_order_entry_password=TESTKEYTESTKEYTESTKEY') NEW_STORE_ACCESS=$(echo $CREATE_STORE | jq -r '.token.access_token') NEW_STORE_REFRESH=$(echo $CREATE_STORE | jq -r '.token.refresh_token') STORE_INFO_STRING=$(echo $CREATE_STORE | jq -r '.token.scope') NEW_STORE_ID=$(echo $STORE_INFO_STRING | sed 's/[^0-9]//g')