Skip to content

Commit

Permalink
Break out config
Browse files Browse the repository at this point in the history
  • Loading branch information
rbamos committed Jul 9, 2024
1 parent b47c5dd commit f608b79
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 77 deletions.
84 changes: 84 additions & 0 deletions config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
if [[ "$kernel_name" == "Darwin" ]]; then
# Leapp integration setup
LEAPP=/Applications/Leapp.app
leapp_proc_name=Leapp
elif [[ "$kernel_name" == "Linux" ]]; then
LEAPP=/opt/Leapp/leapp
leapp_proc_name=leapp
fi

# Check if Leapp is installed
if [ -e "$LEAPP" ]; then
# If Leapp is not running, open it and wait for it to start up
if ! pgrep -x $leapp_proc_name &>/dev/null; then
if [[ $kernel_name == "Darwin" ]]; then
open $LEAPP
elif [[ $kernel_name == "Linux" ]]; then
$LEAPP &
fi
sleep 5
fi

# If there's no Panorama integration, set it up
if ! leapp integration list --no-header | grep -i Panorama; then
leapp integration create \
--integrationType AWS-SSO \
--integrationAlias Panorama \
--integrationPortalUrl $INTEGRATION_PORTAL_URL \
--integrationRegion us-east-1
fi

PANORAMA_INTEGRATION=$(
leapp integration list --csv --columns=ID,"Integration Name","Status" \
| grep Panorama
)

INTEGRATION_ID=$(echo $PANORAMA_INTEGRATION | awk -F$',' '{print $1;}')
INTEGRATION_STATUS=$(echo $PANORAMA_INTEGRATION | awk -F$',' '{print $3;}')

if [[ $INTEGRATION_STATUS == "Offline" ]]; then
leapp integration login --integrationId $INTEGRATION_ID
fi

function set_profile_id() {
PROFILE_ID=$(
leapp profile list --csv --columns=ID,'Profile Name' \
| grep $ROLE_NAME \
| awk -F$',' '{print $1;}'
)
}

AVAILABLE_LEAPP_SESSIONS=$(
leapp session list --csv --columns=id,role |
grep -E $LEAPP_ROLES
)

while IFS= read -r line; do
SESSION_ID=$(echo $line | awk -F$',' '{print $1;}')
ROLE_NAME=$(echo $line | awk -F$',' '{print $2;}')

echo "Creating $ROLE_NAME profile"

set_profile_id

# If the role's name is not in the list of existing profiles, create it.
if [ -z "$PROFILE_ID" ]; then
leapp profile create --profileName $ROLE_NAME

set_profile_id
fi

# Associate the session with the profile matching the role.
leapp session change-profile --profileId $PROFILE_ID --sessionId $SESSION_ID
done <<< "$AVAILABLE_LEAPP_SESSIONS"

# If we found at least one available session, then we can presume
# this installation was successful.
if (( $(echo "$AVAILABLE_LEAPP_SESSIONS" | wc -l) > 0 )); then
echo "+++++ Installation successful. +++++"
else
red_echo "----- Error during installation. Please share the above output to the Infra/Ops Zone. -----"
fi
else
red_echo "Leapp has not been installed."
fi
77 changes: 0 additions & 77 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,80 +118,3 @@ elif [[ "$kernel_name" == "Linux" ]]; then
LEAPP=/opt/Leapp/leapp
leapp_proc_name=leapp
fi


# Check if Leapp is installed
if [ -e "$LEAPP" ]; then
# If Leapp is not running, open it and wait for it to start up
if ! pgrep -x $leapp_proc_name &>/dev/null; then
if [[ $kernel_name == "Darwin" ]]; then
open $LEAPP
elif [[ $kernel_name == "Linux" ]]; then
$LEAPP &
fi
sleep 5
fi

# If there's no Panorama integration, set it up
if ! leapp integration list --no-header | grep -i Panorama; then
leapp integration create \
--integrationType AWS-SSO \
--integrationAlias Panorama \
--integrationPortalUrl $INTEGRATION_PORTAL_URL \
--integrationRegion us-east-1
fi

PANORAMA_INTEGRATION=$(
leapp integration list --csv --columns=ID,"Integration Name","Status" \
| grep Panorama
)

INTEGRATION_ID=$(echo $PANORAMA_INTEGRATION | awk -F$',' '{print $1;}')
INTEGRATION_STATUS=$(echo $PANORAMA_INTEGRATION | awk -F$',' '{print $3;}')

if [[ $INTEGRATION_STATUS == "Offline" ]]; then
leapp integration login --integrationId $INTEGRATION_ID
fi

function set_profile_id() {
PROFILE_ID=$(
leapp profile list --csv --columns=ID,'Profile Name' \
| grep $ROLE_NAME \
| awk -F$',' '{print $1;}'
)
}

AVAILABLE_LEAPP_SESSIONS=$(
leapp session list --csv --columns=id,role |
grep -E $LEAPP_ROLES
)

while IFS= read -r line; do
SESSION_ID=$(echo $line | awk -F$',' '{print $1;}')
ROLE_NAME=$(echo $line | awk -F$',' '{print $2;}')

echo "Creating $ROLE_NAME profile"

set_profile_id

# If the role's name is not in the list of existing profiles, create it.
if [ -z "$PROFILE_ID" ]; then
leapp profile create --profileName $ROLE_NAME

set_profile_id
fi

# Associate the session with the profile matching the role.
leapp session change-profile --profileId $PROFILE_ID --sessionId $SESSION_ID
done <<< "$AVAILABLE_LEAPP_SESSIONS"

# If we found at least one available session, then we can presume
# this installation was successful.
if (( $(echo "$AVAILABLE_LEAPP_SESSIONS" | wc -l) > 0 )); then
echo "+++++ Installation successful. +++++"
else
red_echo "----- Error during installation. Please share the above output to the Infra/Ops Zone. -----"
fi
else
red_echo "Leapp has not been installed."
fi

0 comments on commit f608b79

Please sign in to comment.