Last active
January 6, 2025 13:56
-
-
Save salehjg/3f820376ffafe78f1e3a12470746dbe9 to your computer and use it in GitHub Desktop.
My AWS F1 Setup Script
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
#!/bin/bash | |
echo "Dont forget to allow TCP port 5901 in your instance's security group. You have to add it manually to the inbound rules." | |
echo "This script is tested on Amazon Linux 2" | |
echo "You have to use a VNC client to connect to your server. You can use Vinagre for example." | |
# Detect the current user | |
USER=$(whoami) | |
echo "Detected user: $USER" | |
# Create aws directory and set the environment variable | |
mkdir -p ~/aws | |
export AWS_FPGA_REPO_DIR=~/aws/ | |
# Install necessary utilities | |
sudo yum install -y cmake git htop | |
# Configure AWS CLI (will prompt for keys) | |
aws configure | |
# Install kernel-devel and Xfce dependencies | |
sudo yum install -y kernel-devel | |
sudo yum groupinstall -y "Xfce" | |
sudo yum install -y xorg-x11-server-Xorg | |
# Define the path to the xstartup file for VNC | |
XSTARTUP_FILE="$HOME/.vnc/xstartup" | |
# Create the .vnc directory if it doesn't exist | |
mkdir -p "$(dirname "$XSTARTUP_FILE")" | |
# Write the content to the xstartup file with Full HD resolution | |
cat <<EOL > "$XSTARTUP_FILE" | |
#!/bin/bash | |
export XDG_SESSION_TYPE=x11 | |
export XDG_SESSION_DESKTOP=xfce | |
export XDG_CURRENT_DESKTOP=XFCE | |
# Set screen resolution to Full HD (1920x1080) | |
xrandr --output VNC-0 --mode 1920x1080 | |
exec startxfce4 & | |
EOL | |
# Make the xstartup file executable | |
chmod +x "$XSTARTUP_FILE" | |
echo "xstartup file created and configured." | |
# Set graphical target as the default runlevel | |
sudo systemctl set-default graphical.target | |
# Install EPEL and NUX repositories, then required packages | |
sudo yum -y install epel-release | |
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm | |
sudo yum install -y xrdp tigervnc-server | |
# Start and enable xrdp | |
sudo systemctl start xrdp | |
sudo systemctl enable xrdp | |
# Disable firewalld (be cautious) | |
sudo systemctl disable firewalld | |
sudo systemctl stop firewalld | |
# Set password for the detected user | |
sudo passwd $USER | |
# Start or restart VNC server with Full HD resolution | |
vncserver :1 -geometry 1920x1080 | |
# Clone the AWS FPGA repository | |
git clone https://github.com/aws/aws-fpga.git $AWS_FPGA_REPO_DIR | |
cd $AWS_FPGA_REPO_DIR | |
git checkout 4750aac | |
source vitis_setup.sh | |
# Check if the variable is already defined in ~/.bashrc | |
if grep -q "export AWS_PLATFORM=" ~/.bashrc; then | |
echo "AWS_PLATFORM is already defined in ~/.bashrc. Updating it to the new value." | |
# Update the existing value in ~/.bashrc | |
sed -i "s|^export AWS_PLATFORM=.*|export AWS_PLATFORM=\"$AWS_PLATFORM\"|" ~/.bashrc | |
else | |
echo "Adding AWS_PLATFORM to ~/.bashrc." | |
# Append the export command to ~/.bashrc | |
echo "export AWS_PLATFORM=\"$AWS_PLATFORM\"" >> ~/.bashrc | |
fi | |
PLATFORM_REPO_PATHS="$(dirname "$AWS_PLATFORM")" | |
# Check if PLATFORM_REPO_PATHS is already defined in ~/.bashrc | |
if grep -q "export PLATFORM_REPO_PATHS=" ~/.bashrc; then | |
echo "PLATFORM_REPO_PATHS is already defined in ~/.bashrc. Updating it to the new value." | |
# Update the existing value in ~/.bashrc | |
sed -i "s|^export PLATFORM_REPO_PATHS=.*|export PLATFORM_REPO_PATHS=\"$PLATFORM_REPO_PATHS\"|" ~/.bashrc | |
else | |
echo "Adding PLATFORM_REPO_PATHS to ~/.bashrc." | |
# Append the export command to ~/.bashrc | |
echo "export PLATFORM_REPO_PATHS=\"$PLATFORM_REPO_PATHS\"" >> ~/.bashrc | |
fi | |
source ~/.bashrc | |
# Print the path to the VNC log file | |
VNC_LOG_PATH="$HOME/.vnc/$(hostname):1.log" | |
echo "VNC log file can be found at: $VNC_LOG_PATH" | |
echo "To confirm that the setup is correct, please run: /opt/Xilinx/Vitis/2020.2/bin/platforminfo -l" | |
echo "===========================================" | |
echo "** AWS_PLATFORM is set to: $AWS_PLATFORM" | |
echo "** PLATFORM_REPO_PATHS is set to: $PLATFORM_REPO_PATHS" | |
# Fetch the public IP address using AWS instance metadata | |
PUBLIC_IP=$(curl -s ifconfig.me) | |
# Print the public IP address followed by :5901 for VNC | |
echo "** VNC is now available at: $PUBLIC_IP:5901" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment