aboutsummaryrefslogtreecommitdiff
path: root/debian/install_vlang_full.sh
blob: 4eb33f530b24643bc7f5e45034bed6aa3ea8cee4 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh

# Exit immediately if a command fails
set -e

# Overview
echo "=================================================="
echo "This script will perform the following actions:"
echo "  1. Check your home for ~/Projects"
echo "  2. Update the system package repository."
echo "  3. Clone vlang into ~/Projects and build it"
echo "  4. Build all v tools and recompile it with prod"
echo "=================================================="

# Ask for confirmation
read -p "Do you want to proceed? [y/N]: " -r response
response=$(echo "$response" | tr '[:upper:]' '[:lower:]')
if [[ "$response" != "y" ]]; then
    echo "Operation cancelled."
    exit 1
fi

# Helper function to run commands with sudo if not already root
run_as_root() {
    if [ "$(id -u)" -eq 0 ]; then
        "$@"
    else
        # Asking for sudo permission before executing
        sudo "$@"
    fi
}

# Get projects directory and create it if necessary
PROJECTS_DIR="${XDG_PROJECTS_DIR:-$HOME/Projects}"
if [ ! -d "$PROJECTS_DIR" ]; then
    echo "Creating directory $PROJECTS_DIR"
    mkdir -p "$PROJECTS_DIR"
else
    echo "Found $PROJECTS_DIR"
fi

if [ "$(id -u)" -ne 0 ]; then
    echo "Privileged access required to install packages."
    sudo -v || { echo "Authentication failed."; exit 1; }
fi

# Install all necessary packages for vlang
PACKAGES="git build-essential libsqlite3-dev sqlite3 unixodbc postgresql-client libpq-dev libxi-dev libxcursor-dev mesa-common-dev make"

echo "Updating package lists..."
run_as_root apt-get update -y

echo "Installing packages: $PACKAGES"
if run_as_root apt-get install -y $PACKAGES; then
    echo "Success: All packages were installed successfully!"
else
    # This block triggers if set -e isn't used or if custom failure logic is needed
    echo "Error: Package installation failed." >&2
    exit 1
fi

# Clone and Build Vlang inside PROJECTS_DIR (as regular user)
cd "$PROJECTS_DIR"

if [ -d "v" ]; then
    echo "Directory 'v' already exists in $PROJECTS_DIR. Skipping clone."
else
    echo "Cloning V repository..."
    git clone --depth=1 https://github.com/vlang/v
fi

echo "Building V..."
cd v
make

# Verify vlang executable
if [ -x "./v" ]; then
    echo "Success: V compiler successfully built!"
    echo "Executable path: $(pwd)/v"
else
    echo "Error: V build failed. Binary not found." >&2
    exit 1
fi

# Build v for prod + tools
./v -prod self
./v -prod build-tools

# Symlink V
echo "Creating symlink..."
run_as_root ./v symlink

# Verify symlink
hash -r 2>/dev/null || true

if command -v v >/dev/null 2>&1; then
    echo "Success: V is installed and available in PATH!"
    v version
else
    echo "Error: 'v' command was not found in PATH." >&2
    exit 1
fi