Skip to content

Commit

Permalink
First network issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Jul 13, 2021
1 parent 5d966a5 commit 9b3baf0
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- run: networksetup -listallhardwareports
- run: ifconfig
- uses: mondeja/solaris-vm-action@v1
with:
run: sh tests.sh
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
runs:
using: "composite"
steps:
- run: INPUT_COMMANDS="${{ inputs.run }}" INPUT_CPUS="${{ inputs.cpus }}" INPUT_MEMORY="${{ inputs.memory }}" sh ${{ github.action_path }}/run.sh
- run: RUNNING_AS_ACTION=1 INPUT_COMMANDS="${{ inputs.run }}" INPUT_CPUS="${{ inputs.cpus }}" INPUT_MEMORY="${{ inputs.memory }}" sh ${{ github.action_path }}/run.sh
shell: sh

branding:
Expand Down
123 changes: 111 additions & 12 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,61 @@
#!/bin/sh

MACHINE_IP=""
MACOSX=0
LINUX=0

MACHINE_IP="127.0.0.1"
SSH_PORT=2522

if [ -z "$INPUT_CPUS" ]; then
INPUT_CPUS=1
fi
if [ -z "$INPUT_MEMORY" ]; then
INPUT_MEMORY=4096
fi
if [ -z "$RUNNING_AS_ACTION" ]; then
RUNNING_AS_ACTION=0
fi

CURRENT_DIR_BASENAME="$(pwd | awk -F/ '{print $NF}')"

case "$(uname -s)" in

Darwin)
MACOSX=1
;;

Linux)
LINUX=1
;;
esac

set -ex

prepare_dependencies() {
if [ -z "$(command -v sshpass)" ]; then
if [ "$MACOSX" -eq 1 ]; then
brew install hudochenkov/sshpass/sshpass &
else
echo "You must install sshpass before run this script." >&2
exit 1
fi
fi
}

wait_for_dependencies() {
SSHPASS="$(command -v sshpass)"
if [ -z "$SSHPASS" ]; then
sleep 2
if [ "$1" -gt "300" ]; then
printf "Error installing 'sshpass' dependency after 10 minutes." >&2
printf " Timeout reached.\n" >&2
exit 1
else
wait_for_dependencies "$(( $1 + 1 ))"
fi
fi
}

clean_ova_parts() {
rm -f sol-11_4-part*.zip
}
Expand All @@ -39,6 +82,19 @@ prepare_ova() {
fi
}

prepare_ssh_config() {
# if [ "$RUNNING_AS_ACTION" -eq 1 ]; then
# DEVICE_NAME="$(networksetup -listallhardwareports | grep "Device:" | cut -d' ' -f2)"
# else
# DEVICE_NAME="wlp3s0"
# fi
# vboxmanage modifyvm sol-11_4 \
# --nic1 bridged \
# --cableconnected1 on \
# --bridgeadapter1 $DEVICE_NAME

}

import_vm() {
vboxmanage import sol-11_4.ova
}
Expand All @@ -61,46 +117,89 @@ get_machine_ip() {
| cut -d' ' -f2
}

wait_for_dhcp_ip() {
MACHINE_IP="$(get_machine_ip)"
if [ "$(echo $MACHINE_IP | cut -d'.' -f1)" = "10" ]; then
sleep 3
if [ "$1" -gt "200" ]; then
wait_for_ssh_enter() {
#MACHINE_IP="$(get_machine_ip)"
if ! nc --wait 5 127.0.0.1 $SSH_PORT < /dev/null &> /dev/null; then
sleep 10
if [ "$1" -gt "60" ]; then
printf "Error starting the Solaris VM after 10 minutes." >&2
printf " Timeout reached.\n" >&2
exit 1
else
wait_for_dhcp_ip "$(( $1 + 1 ))"
wait_for_ssh_enter "$(( $1 + 1 ))"
fi
fi

# if [ "$CONNECT" != "OK" ]; then
# MACHINE_IP="$(nmap -p 22 --open -sV 10.79.15.0/24 | grep "scan report for" | cut -d' ' -f5)"
# if [ -n "$MACHINE_IP" ]; then
# CONNECT="$(sshpass -p solaris ssh \
# -p 22 \
# -o StrictHostKeyChecking=no \
# -o ConnectTimeout=10 \
# solaris@$MACHINE_IP "printf 'OK'" || true)"
# if [ "$CONNECT" != "OK" ]; then
# if [ "$1" -gt "60" ]; then
# printf "Error starting the Solaris VM after 10 minutes." >&2
# printf " Timeout reached.\n" >&2
# exit 1
# else
# wait_for_ssh_enter "$(( $1 + 1 ))"
# fi
# fi
# else
# if [ "$1" -gt "60" ]; then
# printf "Error starting the Solaris VM after 10 minutes." >&2
# printf " Timeout reached.\n" >&2
# exit 1
# else
# wait_for_ssh_enter "$(( $1 + 1 ))"
# fi
# fi
# fi
}

sync_files() {
sshpass -p "solaris" \
rsync \
--exclude _actions/mondeja/solaris-vm \
--exclude sol-11_4.ova \
-ae "ssh -p 22 -o StrictHostKeyChecking=no" \
--exclude sol-11_4-backup.zip \
-ae "ssh -p $SSH_PORT -o StrictHostKeyChecking=accept-new" \
$PWD \
solaris@$MACHINE_IP:/export/home/solaris
[email protected]:/export/home/solaris && _sync=1 || _sync=0
if [ "$_sync" -eq 0 ]; then
sleep 10
if [ "$1" -gt "60" ]; then
printf "Error starting the Solaris VM after 10 minutes." >&2
printf " Timeout reached.\n" >&2
exit 1
else
sync_files "$(( $1 + 1 ))"
fi
fi;
}

run_commands() {
sshpass -p solaris ssh \
-o StrictHostKeyChecking=no solaris@$MACHINE_IP << EOF
-p $SSH_PORT \
-o StrictHostKeyChecking=accept-new \
[email protected] << EOF
set -e
cd /export/home/solaris/$CURRENT_DIR_BASENAME
$INPUT_COMMANDS
EOF
}

main() {
prepare_dependencies
prepare_ova
import_vm
prepare_ssh_config
modify_vm
run_vm
wait_for_dhcp_ip 1
sync_files
wait_for_dependencies 1
sync_files 1
run_commands
}

Expand Down
2 changes: 1 addition & 1 deletion tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -x
set -ex

main() {
exitcode=0
Expand Down

0 comments on commit 9b3baf0

Please sign in to comment.