-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.sh
More file actions
53 lines (43 loc) · 1.76 KB
/
common.sh
File metadata and controls
53 lines (43 loc) · 1.76 KB
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
#!/bin/bash
# Common configuration variables
# Determine the script's directory for consistent file paths
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# Default SSH credentials
SSH_USER="user"
SSH_PASS="fedora" # Default password (set in cloud-init)
# Source network configuration
source "$SCRIPT_DIR/infrastructure/network/config.sh"
source "$SCRIPT_DIR/infrastructure/network/syzkaller.sh"
source "$SCRIPT_DIR/infrastructure/network/syzgen.sh"
# Source kernel configuration
source "$SCRIPT_DIR/infrastructure/kernel/config.sh"
source "$SCRIPT_DIR/infrastructure/kernel/syzkaller.sh"
source "$SCRIPT_DIR/infrastructure/kernel/syzgen.sh"
# Set default configurations
setup_network_config "LOCAL"
setup_kernel_config "LOCAL"
OUT_DIR="$SCRIPT_DIR/container_kernel_workspace/out" # Directory with kernel artifacts
# Helper function for logging
log() {
echo -e "\n\e[32m[$(date +"%Y-%m-%d %H:%M:%S")] $*\e[0m\n"
}
# Custom SSH function to handle both single commands and multi-line scripts
vm_ssh() {
if [ "$1" == "--script" ]; then
# Handle multi-line script (heredoc)
sshpass -p "${SSH_PASS}" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p "${VM_SSH_PORT}" "${SSH_USER}@${SSH_HOST}" /bin/bash
else
# Handle single command
local cmd="$1"
sshpass -p "${SSH_PASS}" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p "${VM_SSH_PORT}" "${SSH_USER}@${SSH_HOST}" "$cmd"
fi
}
# Function to wait for Cloud-Init to complete
wait_cloud_init() {
log "Waiting for Cloud-Init to complete..."
while ! vm_ssh "test -f /var/lib/cloud/instance/boot-finished"; do
sleep 10
log "Waiting for Cloud-Init to complete..."
done
log "Cloud-Init has completed."
}