-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
114 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
@@ -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 | ||
} | ||
|
@@ -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 | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh | ||
|
||
set -x | ||
set -ex | ||
|
||
main() { | ||
exitcode=0 | ||
|