Última atividade 7 months ago

uk's Avatar uk revisou este gist 7 months ago. Ir para a revisão

1 file changed, 1 insertion, 1 deletion

install_vmtools.sh

@@ -2,7 +2,7 @@
2 2 set -e
3 3
4 4 # Define variables
5 - ISO_FILENAME="SMTX_VMTOOLS-3.2.0-2501210639.iso"
5 + ISO_FILENAME="SMTX_VMTOOLS-4.0.0-2506271023.iso"
6 6 ISO_FILE="/tmp/${ISO_FILENAME}"
7 7 MOUNT_POINT="/mnt/wuke-vmtools"
8 8

uk's Avatar uk revisou este gist 8 months ago. Ir para a revisão

Sem alterações

uk revisou este gist 10 months ago. Ir para a revisão

1 file changed, 12 insertions, 5 deletions

install_vmtools.sh

@@ -59,11 +59,18 @@ install_package_if_missing tar
59 59 install_package_if_missing bzip2
60 60 install_package_if_missing curl
61 61
62 - # 2. Download the ISO file
62 + # 2. Check if ISO URL is accessible
63 + echo "Checking if ISO URL is accessible..."
64 + if ! curl --head --silent --fail "$ISO_URL" >/dev/null; then
65 + echo "Error: ISO URL $ISO_URL is not accessible."
66 + exit 1
67 + fi
68 +
69 + # 3. Download the ISO file
63 70 echo "Downloading VMTools ISO..."
64 71 curl -o "$ISO_FILE" "$ISO_URL"
65 72
66 - # 3. Check if /mnt/wuke-vmtools exists
73 + # 4. Check if /mnt/wuke-vmtools exists
67 74 if [ -d "$MOUNT_POINT" ]; then
68 75 echo "Directory $MOUNT_POINT exists, removing..."
69 76 umount "$MOUNT_POINT" || true
@@ -73,15 +80,15 @@ fi
73 80 echo "Creating directory $MOUNT_POINT..."
74 81 mkdir -p "$MOUNT_POINT"
75 82
76 - # 4. Mount the ISO
83 + # 5. Mount the ISO
77 84 echo "Mounting ISO file to $MOUNT_POINT..."
78 85 mount -o loop "$ISO_FILE" "$MOUNT_POINT"
79 86
80 - # 5. Execute the installation script
87 + # 6. Execute the installation script
81 88 echo "Running VMTools installation script..."
82 89 bash "$MOUNT_POINT/SMTX_VM_TOOLS_INSTALL.sh"
83 90
84 - # 6. Cleanup
91 + # 7. Cleanup
85 92 echo "Cleaning up temporary files..."
86 93 umount "$MOUNT_POINT" || true
87 94 rm -f "$ISO_FILE"

uk revisou este gist 10 months ago. Ir para a revisão

1 file changed, 54 insertions, 14 deletions

install_vmtools.sh

@@ -2,22 +2,62 @@
2 2 set -e
3 3
4 4 # Define variables
5 - ISO_URL="http://172.29.48.5/VMTOOLS/3.2.0/SMTX_VMTOOLS-3.2.0-2501210639.iso"
6 - ISO_FILE="/tmp/vmtools.iso"
5 + ISO_FILENAME="SMTX_VMTOOLS-3.2.0-2501210639.iso"
6 + ISO_FILE="/tmp/${ISO_FILENAME}"
7 7 MOUNT_POINT="/mnt/wuke-vmtools"
8 8
9 - # 1. Install required packages
10 - if command -v yum >/dev/null 2>&1; then
11 - echo "Installing dependencies using yum..."
12 - yum install -y tar bzip2
13 - elif command -v apt >/dev/null 2>&1; then
14 - echo "Installing dependencies using apt..."
15 - apt update
16 - apt install -y tar bzip2
9 + # Extract version from ISO filename
10 + VMTOOLS_VERSION=$(echo "$ISO_FILENAME" | awk -F'-' '{print $2}')
11 + echo "Extracted VMTools version: $VMTOOLS_VERSION"
12 +
13 + # Detect gateway and set ISO_URL
14 + GATEWAY=$(ip route | grep default | awk '{print $3}')
15 + echo "Detected gateway: $GATEWAY"
16 +
17 + if [[ $GATEWAY == 172.29.16.* ]]; then
18 + ISO_URL="http://172.29.16.5/VMTOOLS/${VMTOOLS_VERSION}/${ISO_FILENAME}"
19 + elif [[ $GATEWAY == 172.29.48.* ]]; then
20 + ISO_URL="http://172.29.48.5/VMTOOLS/${VMTOOLS_VERSION}/${ISO_FILENAME}"
21 + elif [[ $GATEWAY == 172.29.80.* ]]; then
22 + ISO_URL="http://172.29.80.5/VMTOOLS/${VMTOOLS_VERSION}/${ISO_FILENAME}"
23 + elif [[ $GATEWAY == 172.29.112.* ]]; then
24 + ISO_URL="http://172.29.112.5/VMTOOLS/${VMTOOLS_VERSION}/${ISO_FILENAME}"
17 25 else
26 + echo "Unsupported gateway network: $GATEWAY"
27 + exit 1
28 + fi
29 +
30 + echo "Selected ISO URL: $ISO_URL"
31 +
32 + # Function to check and install a package if missing
33 + install_package_if_missing() {
34 + local package_name=$1
35 +
36 + if command -v yum >/dev/null 2>&1; then
37 + if ! rpm -q "$package_name" >/dev/null 2>&1; then
38 + echo "Installing $package_name using yum..."
39 + yum install -y "$package_name"
40 + else
41 + echo "Package $package_name already installed (yum)."
42 + fi
43 + elif command -v apt >/dev/null 2>&1; then
44 + if ! dpkg -s "$package_name" >/dev/null 2>&1; then
45 + echo "Installing $package_name using apt..."
46 + apt update
47 + apt install -y "$package_name"
48 + else
49 + echo "Package $package_name already installed (apt)."
50 + fi
51 + else
18 52 echo "Unsupported OS: yum or apt not found."
19 53 exit 1
20 - fi
54 + fi
55 + }
56 +
57 + # 1. Install required packages
58 + install_package_if_missing tar
59 + install_package_if_missing bzip2
60 + install_package_if_missing curl
21 61
22 62 # 2. Download the ISO file
23 63 echo "Downloading VMTools ISO..."
@@ -25,9 +65,9 @@ curl -o "$ISO_FILE" "$ISO_URL"
25 65
26 66 # 3. Check if /mnt/wuke-vmtools exists
27 67 if [ -d "$MOUNT_POINT" ]; then
28 - echo "Directory $MOUNT_POINT exists, removing..."
29 - umount "$MOUNT_POINT" || true
30 - rm -rf "$MOUNT_POINT"
68 + echo "Directory $MOUNT_POINT exists, removing..."
69 + umount "$MOUNT_POINT" || true
70 + rm -rf "$MOUNT_POINT"
31 71 fi
32 72
33 73 echo "Creating directory $MOUNT_POINT..."

uk revisou este gist 10 months ago. Ir para a revisão

1 file changed, 50 insertions

install_vmtools.sh(arquivo criado)

@@ -0,0 +1,50 @@
1 + #!/bin/bash
2 + set -e
3 +
4 + # Define variables
5 + ISO_URL="http://172.29.48.5/VMTOOLS/3.2.0/SMTX_VMTOOLS-3.2.0-2501210639.iso"
6 + ISO_FILE="/tmp/vmtools.iso"
7 + MOUNT_POINT="/mnt/wuke-vmtools"
8 +
9 + # 1. Install required packages
10 + if command -v yum >/dev/null 2>&1; then
11 + echo "Installing dependencies using yum..."
12 + yum install -y tar bzip2
13 + elif command -v apt >/dev/null 2>&1; then
14 + echo "Installing dependencies using apt..."
15 + apt update
16 + apt install -y tar bzip2
17 + else
18 + echo "Unsupported OS: yum or apt not found."
19 + exit 1
20 + fi
21 +
22 + # 2. Download the ISO file
23 + echo "Downloading VMTools ISO..."
24 + curl -o "$ISO_FILE" "$ISO_URL"
25 +
26 + # 3. Check if /mnt/wuke-vmtools exists
27 + if [ -d "$MOUNT_POINT" ]; then
28 + echo "Directory $MOUNT_POINT exists, removing..."
29 + umount "$MOUNT_POINT" || true
30 + rm -rf "$MOUNT_POINT"
31 + fi
32 +
33 + echo "Creating directory $MOUNT_POINT..."
34 + mkdir -p "$MOUNT_POINT"
35 +
36 + # 4. Mount the ISO
37 + echo "Mounting ISO file to $MOUNT_POINT..."
38 + mount -o loop "$ISO_FILE" "$MOUNT_POINT"
39 +
40 + # 5. Execute the installation script
41 + echo "Running VMTools installation script..."
42 + bash "$MOUNT_POINT/SMTX_VM_TOOLS_INSTALL.sh"
43 +
44 + # 6. Cleanup
45 + echo "Cleaning up temporary files..."
46 + umount "$MOUNT_POINT" || true
47 + rm -f "$ISO_FILE"
48 + rm -rf "$MOUNT_POINT"
49 +
50 + echo "Installation and cleanup completed."
Próximo Anterior