docker creators
This commit is contained in:
3
docker/base/.gitignore
vendored
Normal file
3
docker/base/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.bash_history
|
||||
.openvscode-server/
|
||||
.cache/
|
||||
31
docker/base/Dockerfile
Normal file
31
docker/base/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
# Use Ubuntu 24.04 as the base image
|
||||
FROM ubuntu:24.04
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /root
|
||||
|
||||
# Copy local installation scripts into the container
|
||||
COPY scripts/install_v.sh /tmp/install_v.sh
|
||||
COPY scripts/install_herolib.vsh /tmp/install_herolib.vsh
|
||||
COPY scripts/install_vscode.sh /tmp/install_vscode.sh
|
||||
COPY scripts/ourinit.sh /usr/local/bin/
|
||||
|
||||
# Make the scripts executable
|
||||
RUN chmod +x /tmp/install_v.sh /tmp/install_herolib.vsh
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
curl bash sudo mc wget tmux
|
||||
|
||||
RUN bash /tmp/install_v.sh
|
||||
|
||||
RUN yes y | bash /tmp/install_v.sh --analyzer
|
||||
|
||||
RUN bash /tmp/install_vscode.sh
|
||||
|
||||
RUN /tmp/install_herolib.vsh && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/ourinit.sh"]
|
||||
CMD ["/bin/bash"]
|
||||
|
||||
40
docker/base/build.sh
Executable file
40
docker/base/build.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Copy installation files
|
||||
cp ../../install_v.sh ./scripts/install_v.sh
|
||||
cp ../../install_herolib.vsh ./scripts/install_herolib.vsh
|
||||
|
||||
# Docker image and container names
|
||||
DOCKER_IMAGE_NAME="herolib"
|
||||
DEBUG_CONTAINER_NAME="herolib"
|
||||
|
||||
function cleanup {
|
||||
if docker ps -aq -f name="$DEBUG_CONTAINER_NAME" &>/dev/null; then
|
||||
echo "Cleaning up leftover debug container..."
|
||||
docker rm -f "$DEBUG_CONTAINER_NAME" &>/dev/null || true
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Attempt to build the Docker image
|
||||
BUILD_LOG=$(mktemp)
|
||||
set +e
|
||||
docker build --progress=plain -t "$DOCKER_IMAGE_NAME" .
|
||||
BUILD_EXIT_CODE=$?
|
||||
set -e
|
||||
|
||||
# Handle build failure
|
||||
if [ $BUILD_EXIT_CODE -ne 0 ]; then
|
||||
echo -e "\\n[ERROR] Docker build failed.\n"
|
||||
echo -e "remove the part which didn't build in the Dockerfile, the run again and to debug do:"
|
||||
echo docker run --name debug -it --entrypoint=/bin/bash "debug-image"
|
||||
exit $BUILD_EXIT_CODE
|
||||
else
|
||||
echo -e "\\n[INFO] Docker build completed successfully."
|
||||
fi
|
||||
|
||||
|
||||
21
docker/base/debug.sh
Executable file
21
docker/base/debug.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
# Get the directory where the script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Remove any existing container named 'debug' (ignore errors)
|
||||
docker rm -f herolib > /dev/null 2>&1
|
||||
|
||||
# Run the Docker container
|
||||
docker run --name herolib -it \
|
||||
--entrypoint="/bin/bash" \
|
||||
-v "${SCRIPT_DIR}/scripts:/scripts" \
|
||||
-v "$HOME/code:/root/code" \
|
||||
-p 4100:8100 \
|
||||
-p 4101:8101 \
|
||||
-p 4102:8102 \
|
||||
-p 4379:6379 \
|
||||
-p 4000:3000 \
|
||||
herolib
|
||||
|
||||
31
docker/base/docker-compose.yml
Normal file
31
docker/base/docker-compose.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:latest
|
||||
container_name: postgres_service
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: planetfirst
|
||||
POSTGRES_DB: mydb
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
herolib:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: herolib
|
||||
volumes:
|
||||
- ~/code:/root/code
|
||||
stdin_open: true
|
||||
tty: true
|
||||
ports:
|
||||
- "8100:4100"
|
||||
- "8101:4101"
|
||||
- "8102:4102"
|
||||
- "6379:4379"
|
||||
- "3000:4000"
|
||||
volumes:
|
||||
postgres_data:
|
||||
|
||||
|
||||
71
docker/base/scripts/install_herolib.vsh
Executable file
71
docker/base/scripts/install_herolib.vsh
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import os
|
||||
import flag
|
||||
|
||||
fn addtoscript(tofind string, toadd string) ! {
|
||||
home_dir := os.home_dir()
|
||||
mut rc_file := '${home_dir}/.zshrc'
|
||||
if !os.exists(rc_file) {
|
||||
rc_file = '${home_dir}/.bashrc'
|
||||
if !os.exists(rc_file) {
|
||||
return error('No .zshrc or .bashrc found in home directory')
|
||||
}
|
||||
}
|
||||
|
||||
// Read current content
|
||||
mut content := os.read_file(rc_file)!
|
||||
|
||||
// Remove existing alias if present
|
||||
lines := content.split('\n')
|
||||
mut new_lines := []string{}
|
||||
mut prev_is_emtpy := false
|
||||
for line in lines {
|
||||
if prev_is_emtpy {
|
||||
if line.trim_space() == ""{
|
||||
continue
|
||||
}else{
|
||||
prev_is_emtpy = false
|
||||
}
|
||||
}
|
||||
if line.trim_space() == ""{
|
||||
prev_is_emtpy = true
|
||||
}
|
||||
|
||||
if !line.contains(tofind) {
|
||||
new_lines << line
|
||||
}
|
||||
}
|
||||
new_lines << toadd
|
||||
new_lines << ""
|
||||
// Write back to file
|
||||
new_content := new_lines.join('\n')
|
||||
os.write_file(rc_file, new_content)!
|
||||
}
|
||||
|
||||
|
||||
vroot := @VROOT
|
||||
abs_dir_of_script := dir(@FILE)
|
||||
|
||||
// Reset symlinks if requested
|
||||
println('Resetting all symlinks...')
|
||||
os.rm('${os.home_dir()}/.vmodules/freeflowuniverse/herolib') or {}
|
||||
|
||||
// Create necessary directories
|
||||
os.mkdir_all('${os.home_dir()}/.vmodules/freeflowuniverse') or {
|
||||
panic('Failed to create directory ~/.vmodules/freeflowuniverse: ${err}')
|
||||
}
|
||||
|
||||
// Create new symlinks
|
||||
os.symlink('${abs_dir_of_script}/lib', '${os.home_dir()}/.vmodules/freeflowuniverse/herolib') or {
|
||||
panic('Failed to create herolib symlink: ${err}')
|
||||
}
|
||||
|
||||
println('Herolib installation completed successfully!')
|
||||
|
||||
// Add vtest alias
|
||||
addtoscript('alias vtest=', 'alias vtest=\'v -stats -enable-globals -n -w -cg -gc none -no-retry-compilation -cc tcc test\' ') or {
|
||||
eprintln('Failed to add vtest alias: ${err}')
|
||||
}
|
||||
|
||||
println('Added vtest alias to shell configuration')
|
||||
473
docker/base/scripts/install_v.sh
Executable file
473
docker/base/scripts/install_v.sh
Executable file
@@ -0,0 +1,473 @@
|
||||
|
||||
#!/bin/bash -e
|
||||
|
||||
# Help function
|
||||
print_help() {
|
||||
echo "V & HeroLib Installer Script"
|
||||
echo
|
||||
echo "Usage: $0 [options]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help message"
|
||||
echo " --reset Force reinstallation of V"
|
||||
echo " --remove Remove V installation and exit"
|
||||
echo " --analyzer Install/update v-analyzer"
|
||||
echo " --herolib Install our herolib"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " $0"
|
||||
echo " $0 --reset "
|
||||
echo " $0 --remove "
|
||||
echo " $0 --analyzer "
|
||||
echo " $0 --herolib "
|
||||
echo " $0 --reset --analyzer # Fresh install of both"
|
||||
echo
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
RESET=false
|
||||
REMOVE=false
|
||||
INSTALL_ANALYZER=false
|
||||
HEROLIB=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
-h|--help)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
--reset)
|
||||
RESET=true
|
||||
;;
|
||||
--remove)
|
||||
REMOVE=true
|
||||
;;
|
||||
--herolib)
|
||||
HEROLIB=true
|
||||
;;
|
||||
--analyzer)
|
||||
INSTALL_ANALYZER=true
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $arg"
|
||||
echo "Use -h or --help to see available options"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function to check if command exists
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
export DIR_BASE="$HOME"
|
||||
export DIR_BUILD="/tmp"
|
||||
export DIR_CODE="$DIR_BASE/code"
|
||||
export DIR_CODE_V="$DIR_BASE/_code"
|
||||
|
||||
function sshknownkeysadd {
|
||||
mkdir -p ~/.ssh
|
||||
touch ~/.ssh/known_hosts
|
||||
if ! grep github.com ~/.ssh/known_hosts > /dev/null
|
||||
then
|
||||
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||
fi
|
||||
if ! grep git.ourworld.tf ~/.ssh/known_hosts > /dev/null
|
||||
then
|
||||
ssh-keyscan git.ourworld.tf >> ~/.ssh/known_hosts
|
||||
fi
|
||||
git config --global pull.rebase false
|
||||
|
||||
}
|
||||
|
||||
function package_check_install {
|
||||
local command_name="$1"
|
||||
if command -v "$command_name" >/dev/null 2>&1; then
|
||||
echo "command '$command_name' is already installed."
|
||||
else
|
||||
package_install '$command_name'
|
||||
fi
|
||||
}
|
||||
|
||||
function package_install {
|
||||
local command_name="$1"
|
||||
if [[ "${OSNAME}" == "ubuntu" ]]; then
|
||||
apt -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" install $1 -q -y --allow-downgrades --allow-remove-essential
|
||||
elif [[ "${OSNAME}" == "darwin"* ]]; then
|
||||
brew install $command_name
|
||||
elif [[ "${OSNAME}" == "alpine"* ]]; then
|
||||
apk add $command_name
|
||||
elif [[ "${OSNAME}" == "arch"* ]]; then
|
||||
pacman --noconfirm -Su $command_name
|
||||
else
|
||||
echo "platform : ${OSNAME} not supported"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
is_github_actions() {
|
||||
[ -d "/home/runner" ] || [ -d "$HOME/runner" ]
|
||||
}
|
||||
|
||||
|
||||
function myplatform {
|
||||
if [[ "${OSTYPE}" == "darwin"* ]]; then
|
||||
export OSNAME='darwin'
|
||||
elif [ -e /etc/os-release ]; then
|
||||
# Read the ID field from the /etc/os-release file
|
||||
export OSNAME=$(grep '^ID=' /etc/os-release | cut -d= -f2)
|
||||
if [ "${os_id,,}" == "ubuntu" ]; then
|
||||
export OSNAME="ubuntu"
|
||||
fi
|
||||
if [ "${OSNAME}" == "archarm" ]; then
|
||||
export OSNAME="arch"
|
||||
fi
|
||||
if [ "${OSNAME}" == "debian" ]; then
|
||||
export OSNAME="ubuntu"
|
||||
fi
|
||||
else
|
||||
echo "Unable to determine the operating system."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# if [ "$(uname -m)" == "x86_64" ]; then
|
||||
# echo "This system is running a 64-bit processor."
|
||||
# else
|
||||
# echo "This system is not running a 64-bit processor."
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
}
|
||||
|
||||
myplatform
|
||||
|
||||
function os_update {
|
||||
echo ' - os update'
|
||||
if [[ "${OSNAME}" == "ubuntu" ]]; then
|
||||
if is_github_actions; then
|
||||
echo "github actions"
|
||||
else
|
||||
rm -f /var/lib/apt/lists/lock
|
||||
rm -f /var/cache/apt/archives/lock
|
||||
rm -f /var/lib/dpkg/lock*
|
||||
fi
|
||||
export TERM=xterm
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
dpkg --configure -a
|
||||
apt update -y
|
||||
if is_github_actions; then
|
||||
echo "** IN GITHUB ACTIONS, DON'T DO UPDATE"
|
||||
else
|
||||
set +e
|
||||
echo "** UPDATE"
|
||||
apt-mark hold grub-efi-amd64-signed
|
||||
set -e
|
||||
apt upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
|
||||
apt autoremove -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
|
||||
fi
|
||||
#apt install apt-transport-https ca-certificates curl software-properties-common -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
|
||||
package_install "apt-transport-https ca-certificates curl wget software-properties-common tmux"
|
||||
package_install "rclone rsync mc redis-server screen net-tools git dnsutils htop ca-certificates screen lsb-release binutils pkg-config"
|
||||
|
||||
elif [[ "${OSNAME}" == "darwin"* ]]; then
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
echo ' - homebrew installed'
|
||||
else
|
||||
export NONINTERACTIVE=1
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
unset NONINTERACTIVE
|
||||
fi
|
||||
set +e
|
||||
brew install mc redis curl tmux screen htop wget rclone tcc
|
||||
set -e
|
||||
elif [[ "${OSNAME}" == "alpine"* ]]; then
|
||||
apk update screen git htop tmux
|
||||
apk add mc curl rsync htop redis bash bash-completion screen git rclone
|
||||
sed -i 's#/bin/ash#/bin/bash#g' /etc/passwd
|
||||
elif [[ "${OSNAME}" == "arch"* ]]; then
|
||||
pacman -Syy --noconfirm
|
||||
pacman -Syu --noconfirm
|
||||
pacman -Su --noconfirm arch-install-scripts gcc mc git tmux curl htop redis wget screen net-tools git sudo htop ca-certificates lsb-release screen rclone
|
||||
|
||||
# Check if builduser exists, create if not
|
||||
if ! id -u builduser > /dev/null 2>&1; then
|
||||
useradd -m builduser
|
||||
echo "builduser:$(openssl rand -base64 32 | sha256sum | base64 | head -c 32)" | chpasswd
|
||||
echo 'builduser ALL=(ALL) NOPASSWD: ALL' | tee /etc/sudoers.d/builduser
|
||||
fi
|
||||
|
||||
if [[ -n "${DEBUG}" ]]; then
|
||||
execute_with_marker "paru_install" paru_install
|
||||
fi
|
||||
fi
|
||||
echo ' - os update done'
|
||||
}
|
||||
|
||||
|
||||
function hero_lib_pull {
|
||||
pushd $DIR_CODE/github/freeflowuniverse/herolib 2>&1 >> /dev/null
|
||||
if [[ $(git status -s) ]]; then
|
||||
echo "There are uncommitted changes in the Git repository herolib."
|
||||
return 1
|
||||
fi
|
||||
git pull
|
||||
popd 2>&1 >> /dev/null
|
||||
}
|
||||
|
||||
function hero_lib_get {
|
||||
|
||||
mkdir -p $DIR_CODE/github/freeflowuniverse
|
||||
if [[ -d "$DIR_CODE/github/freeflowuniverse/herolib" ]]
|
||||
then
|
||||
hero_lib_pull
|
||||
else
|
||||
pushd $DIR_CODE/github/freeflowuniverse 2>&1 >> /dev/null
|
||||
git clone --depth 1 --no-single-branch https://github.com/freeflowuniverse/herolib.git
|
||||
popd 2>&1 >> /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
function install_secp256k1 {
|
||||
echo "Installing secp256k1..."
|
||||
if [[ "${OSNAME}" == "darwin"* ]]; then
|
||||
brew install secp256k1
|
||||
elif [[ "${OSNAME}" == "ubuntu" ]]; then
|
||||
# Install build dependencies
|
||||
apt-get install -y build-essential wget autoconf libtool
|
||||
|
||||
# Download and extract secp256k1
|
||||
cd "${DIR_BUILD}"
|
||||
wget https://github.com/bitcoin-core/secp256k1/archive/refs/tags/v0.3.2.tar.gz
|
||||
tar -xvf v0.3.2.tar.gz
|
||||
|
||||
# Build and install
|
||||
cd secp256k1-0.3.2/
|
||||
./autogen.sh
|
||||
./configure
|
||||
make -j 5
|
||||
make install
|
||||
|
||||
# Cleanup
|
||||
cd ..
|
||||
rm -rf secp256k1-0.3.2 v0.3.2.tar.gz
|
||||
else
|
||||
echo "secp256k1 installation not implemented for ${OSNAME}"
|
||||
exit 1
|
||||
fi
|
||||
echo "secp256k1 installation complete!"
|
||||
}
|
||||
|
||||
|
||||
remove_all() {
|
||||
echo "Removing V installation..."
|
||||
# Set reset to true to use existing reset functionality
|
||||
RESET=true
|
||||
# Call reset functionality
|
||||
sudo rm -rf ~/code/v
|
||||
sudo rm -rf ~/_code/v
|
||||
sudo rm -rf ~/.config/v-analyzer
|
||||
if command_exists v; then
|
||||
echo "Removing V from system..."
|
||||
sudo rm -f $(which v)
|
||||
fi
|
||||
if command_exists v-analyzer; then
|
||||
echo "Removing v-analyzer from system..."
|
||||
sudo rm -f $(which v-analyzer)
|
||||
fi
|
||||
|
||||
# Remove v-analyzer path from rc files
|
||||
for RC_FILE in ~/.zshrc ~/.bashrc; do
|
||||
if [ -f "$RC_FILE" ]; then
|
||||
echo "Cleaning up $RC_FILE..."
|
||||
# Create a temporary file
|
||||
TMP_FILE=$(mktemp)
|
||||
# Remove lines containing v-analyzer/bin path
|
||||
sed '/v-analyzer\/bin/d' "$RC_FILE" > "$TMP_FILE"
|
||||
# Remove empty lines at the end of file
|
||||
sed -i.bak -e :a -e '/^\n*$/{$d;N;ba' -e '}' "$TMP_FILE"
|
||||
# Replace original file
|
||||
mv "$TMP_FILE" "$RC_FILE"
|
||||
echo "Cleaned up $RC_FILE"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "V removal complete"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Function to check if a service is running and start it if needed
|
||||
check_and_start_redis() {
|
||||
|
||||
# Normal service management for non-container environments
|
||||
if [[ "${OSNAME}" == "ubuntu" ]] || [[ "${OSNAME}" == "debian" ]]; then
|
||||
|
||||
# Check if running inside a container
|
||||
if grep -q "/docker/" /proc/1/cgroup || [ ! -d "/run/systemd/system" ]; then
|
||||
echo "Running inside a container. Starting redis directly."
|
||||
|
||||
if pgrep redis-server > /dev/null; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it in the background..."
|
||||
redis-server --daemonize yes
|
||||
if pgrep redis-server > /dev/null; then
|
||||
echo "redis started successfully."
|
||||
else
|
||||
echo "Failed to start redis. Please check logs for details."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
if systemctl is-active --quiet "redis"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it..."
|
||||
sudo systemctl start "redis"
|
||||
if systemctl is-active --quiet "redis"; then
|
||||
echo "redis started successfully."
|
||||
else
|
||||
echo "Failed to start redis. Please check logs for details."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
elif [[ "${OSNAME}" == "darwin"* ]]; then
|
||||
if brew services list | grep -q "^redis.*started"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it..."
|
||||
brew services start redis
|
||||
fi
|
||||
elif [[ "${OSNAME}" == "alpine"* ]]; then
|
||||
if rc-service "redis" status | grep -q "running"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it..."
|
||||
rc-service "redis" start
|
||||
fi
|
||||
elif [[ "${OSNAME}" == "arch"* ]]; then
|
||||
if systemctl is-active --quiet "redis"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it..."
|
||||
sudo systemctl start "redis"
|
||||
fi
|
||||
else
|
||||
echo "Service management for redis is not implemented for platform: $OSNAME"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Handle remove if requested
|
||||
if [ "$REMOVE" = true ]; then
|
||||
remove_all
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Handle reset if requested
|
||||
if [ "$RESET" = true ]; then
|
||||
remove_all
|
||||
echo "Reset complete"
|
||||
fi
|
||||
|
||||
# Create code directory if it doesn't exist
|
||||
mkdir -p ~/code
|
||||
|
||||
|
||||
# Check if v needs to be installed
|
||||
if [ "$RESET" = true ] || ! command_exists v; then
|
||||
|
||||
os_update
|
||||
|
||||
sshknownkeysadd
|
||||
|
||||
# Install secp256k1
|
||||
install_secp256k1
|
||||
|
||||
# Only clone and install if directory doesn't exist
|
||||
if [ ! -d ~/code/v ]; then
|
||||
echo "Installing V..."
|
||||
mkdir -p ~/_code
|
||||
cd ~/_code
|
||||
git clone --depth=1 https://github.com/vlang/v
|
||||
cd v
|
||||
make
|
||||
sudo ./v symlink
|
||||
fi
|
||||
|
||||
# Verify v is in path
|
||||
if ! command_exists v; then
|
||||
echo "Error: V installation failed or not in PATH"
|
||||
echo "Please ensure ~/code/v is in your PATH"
|
||||
exit 1
|
||||
fi
|
||||
echo "V installation successful!"
|
||||
fi
|
||||
|
||||
# Install v-analyzer if requested
|
||||
if [ "$INSTALL_ANALYZER" = true ]; then
|
||||
echo "Installing v-analyzer..."
|
||||
v download -RD https://raw.githubusercontent.com/vlang/v-analyzer/main/install.vsh
|
||||
|
||||
# Check if v-analyzer bin directory exists
|
||||
if [ ! -d "$HOME/.config/v-analyzer/bin" ]; then
|
||||
echo "Error: v-analyzer bin directory not found at $HOME/.config/v-analyzer/bin"
|
||||
echo "Please ensure v-analyzer was installed correctly"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "v-analyzer installation successful!"
|
||||
fi
|
||||
|
||||
# Add v-analyzer to PATH if installed
|
||||
if [ -d "$HOME/.config/v-analyzer/bin" ]; then
|
||||
V_ANALYZER_PATH='export PATH="$PATH:$HOME/.config/v-analyzer/bin"'
|
||||
|
||||
# Function to add path to rc file if not present
|
||||
add_to_rc() {
|
||||
local RC_FILE="$1"
|
||||
if [ -f "$RC_FILE" ]; then
|
||||
if ! grep -q "v-analyzer/bin" "$RC_FILE"; then
|
||||
echo "" >> "$RC_FILE"
|
||||
echo "$V_ANALYZER_PATH" >> "$RC_FILE"
|
||||
echo "Added v-analyzer to $RC_FILE"
|
||||
else
|
||||
echo "v-analyzer path already exists in $RC_FILE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Add to both .zshrc and .bashrc if they exist
|
||||
add_to_rc ~/.zshrc
|
||||
if [ "$(uname)" = "Darwin" ] && [ -f ~/.bashrc ]; then
|
||||
add_to_rc ~/.bashrc
|
||||
fi
|
||||
fi
|
||||
|
||||
# Final verification
|
||||
if ! command_exists v; then
|
||||
echo "Error: V is not accessible in PATH"
|
||||
echo "Please add ~/code/v to your PATH and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_and_start_redis
|
||||
|
||||
if [ "$HEROLIB" = true ]; then
|
||||
hero_lib_get
|
||||
~/code/github/freeflowuniverse/herolib/install_herolib.vsh
|
||||
fi
|
||||
|
||||
|
||||
# if [ "$INSTALL_ANALYZER" = true ]; then
|
||||
# echo "Run 'source ~/.bashrc' or 'source ~/.zshrc' to update PATH for v-analyzer"
|
||||
# fi
|
||||
|
||||
|
||||
echo "Installation complete!"
|
||||
98
docker/base/scripts/install_vscode.sh
Executable file
98
docker/base/scripts/install_vscode.sh
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Set version and file variables
|
||||
OPENVSCODE_SERVER_VERSION="1.97.0"
|
||||
TMP_DIR="/tmp"
|
||||
FILENAME="openvscode.tar.gz"
|
||||
FILE_PATH="$TMP_DIR/$FILENAME"
|
||||
INSTALL_DIR="/opt/openvscode"
|
||||
BIN_PATH="/usr/local/bin/openvscode-server"
|
||||
TMUX_SESSION="openvscode-server"
|
||||
|
||||
# Function to detect architecture
|
||||
get_architecture() {
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64)
|
||||
echo "x64"
|
||||
;;
|
||||
aarch64)
|
||||
echo "arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: $ARCH" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Check if OpenVSCode Server is already installed
|
||||
if [ -d "$INSTALL_DIR" ] && [ -x "$BIN_PATH" ]; then
|
||||
echo "OpenVSCode Server is already installed at $INSTALL_DIR. Skipping download and installation."
|
||||
else
|
||||
# Determine architecture-specific URL
|
||||
ARCH=$(get_architecture)
|
||||
if [ "$ARCH" == "x64" ]; then
|
||||
DOWNLOAD_URL="https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-x64.tar.gz"
|
||||
elif [ "$ARCH" == "arm64" ]; then
|
||||
DOWNLOAD_URL="https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-arm64.tar.gz"
|
||||
fi
|
||||
|
||||
# Navigate to temporary directory
|
||||
cd "$TMP_DIR"
|
||||
|
||||
# Remove existing file if it exists
|
||||
if [ -f "$FILE_PATH" ]; then
|
||||
rm -f "$FILE_PATH"
|
||||
fi
|
||||
|
||||
# Download file using curl
|
||||
curl -L "$DOWNLOAD_URL" -o "$FILE_PATH"
|
||||
|
||||
# Verify file size is greater than 40 MB (40 * 1024 * 1024 bytes)
|
||||
FILE_SIZE=$(stat -c%s "$FILE_PATH")
|
||||
if [ "$FILE_SIZE" -le $((40 * 1024 * 1024)) ]; then
|
||||
echo "Error: Downloaded file size is less than 40 MB." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract the tar.gz file
|
||||
EXTRACT_DIR="openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-${ARCH}"
|
||||
tar -xzf "$FILE_PATH"
|
||||
|
||||
# Move the extracted directory to the install location
|
||||
if [ -d "$INSTALL_DIR" ]; then
|
||||
rm -rf "$INSTALL_DIR"
|
||||
fi
|
||||
mv "$EXTRACT_DIR" "$INSTALL_DIR"
|
||||
|
||||
# Create a symlink for easy access
|
||||
ln -sf "$INSTALL_DIR/bin/openvscode-server" "$BIN_PATH"
|
||||
|
||||
# Verify installation
|
||||
if ! command -v openvscode-server >/dev/null 2>&1; then
|
||||
echo "Error: Failed to create symlink for openvscode-server." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install default plugins
|
||||
PLUGINS=("ms-python.python" "esbenp.prettier-vscode")
|
||||
for PLUGIN in "${PLUGINS[@]}"; do
|
||||
"$INSTALL_DIR/bin/openvscode-server" --install-extension "$PLUGIN"
|
||||
done
|
||||
|
||||
echo "Default plugins installed: ${PLUGINS[*]}"
|
||||
|
||||
# Clean up temporary directory
|
||||
if [ -d "$TMP_DIR" ]; then
|
||||
find "$TMP_DIR" -maxdepth 1 -type f -name "openvscode*" -exec rm -f {} \;
|
||||
fi
|
||||
fi
|
||||
|
||||
# Start OpenVSCode Server in a tmux session
|
||||
if tmux has-session -t "$TMUX_SESSION" 2>/dev/null; then
|
||||
tmux kill-session -t "$TMUX_SESSION"
|
||||
fi
|
||||
tmux new-session -d -s "$TMUX_SESSION" "$INSTALL_DIR/bin/openvscode-server"
|
||||
|
||||
echo "OpenVSCode Server is running in a tmux session named '$TMUX_SESSION'."
|
||||
11
docker/base/scripts/ourinit.sh
Executable file
11
docker/base/scripts/ourinit.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash -e
|
||||
redis-server --daemonize yes
|
||||
|
||||
TMUX_SESSION="vscode"
|
||||
# Start OpenVSCode Server in a tmux session
|
||||
if tmux has-session -t "$TMUX_SESSION" 2>/dev/null; then
|
||||
tmux kill-session -t "$TMUX_SESSION"
|
||||
fi
|
||||
tmux new-session -d -s "$TMUX_SESSION" "/usr/local/bin/openvscode-server --host 0.0.0.0 --without-connection-token"
|
||||
|
||||
|
||||
0
docker/base/start.sh
Normal file
0
docker/base/start.sh
Normal file
1
docker/vscode.sh
Normal file
1
docker/vscode.sh
Normal file
@@ -0,0 +1 @@
|
||||
docker run -it --init -p 4000:3000 -v "$(pwd):/home/workspace:cached" gitpod/openvscode-server
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
#!/usr/bin/env -S v -n -w -no-retry-compilation -d use_openssl -enable-globals run
|
||||
//#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||
//-parallel-cc
|
||||
import os
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.develop.performance
|
||||
// import freeflowuniverse.herolib.develop.performance
|
||||
|
||||
mut silent := false
|
||||
|
||||
@@ -12,6 +13,9 @@ coderoot := if 'CODEROOT' in os.environ() {
|
||||
os.join_path(os.home_dir(), 'code')
|
||||
}
|
||||
|
||||
// timer := performance.new('gittools')
|
||||
|
||||
|
||||
mut gs := gittools.get()!
|
||||
if coderoot.len > 0 {
|
||||
// is a hack for now
|
||||
@@ -23,5 +27,4 @@ mypath := gs.do(
|
||||
cmd: 'list'
|
||||
)!
|
||||
|
||||
timer := performance.new('gittools')
|
||||
timer.timeline()
|
||||
// timer.timeline()
|
||||
|
||||
@@ -64,7 +64,7 @@ os.symlink('${abs_dir_of_script}/lib', '${os.home_dir()}/.vmodules/freeflowunive
|
||||
println('Herolib installation completed successfully!')
|
||||
|
||||
// Add vtest alias
|
||||
addtoscript('alias vtest=', 'alias vtest=\'v -stats -enable-globals -n -w -cg -gc none -no-retry-compilation -cc tcc test\' %') or {
|
||||
addtoscript('alias vtest=', 'alias vtest=\'v -stats -enable-globals -n -w -cg -gc none -no-retry-compilation -cc tcc test\' ') or {
|
||||
eprintln('Failed to add vtest alias: ${err}')
|
||||
}
|
||||
|
||||
|
||||
69
install_v.sh
69
install_v.sh
@@ -297,6 +297,73 @@ remove_all() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Function to check if a service is running and start it if needed
|
||||
check_and_start_redis() {
|
||||
|
||||
# Normal service management for non-container environments
|
||||
if [[ "${OSNAME}" == "ubuntu" ]] || [[ "${OSNAME}" == "debian" ]]; then
|
||||
|
||||
# Check if running inside a container
|
||||
if grep -q "/docker/" /proc/1/cgroup || [ ! -d "/run/systemd/system" ]; then
|
||||
echo "Running inside a container. Starting redis directly."
|
||||
|
||||
if pgrep redis-server > /dev/null; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it in the background..."
|
||||
redis-server --daemonize yes
|
||||
if pgrep redis-server > /dev/null; then
|
||||
echo "redis started successfully."
|
||||
else
|
||||
echo "Failed to start redis. Please check logs for details."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
if systemctl is-active --quiet "redis"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it..."
|
||||
sudo systemctl start "redis"
|
||||
if systemctl is-active --quiet "redis"; then
|
||||
echo "redis started successfully."
|
||||
else
|
||||
echo "Failed to start redis. Please check logs for details."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
elif [[ "${OSNAME}" == "darwin"* ]]; then
|
||||
if brew services list | grep -q "^redis.*started"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it..."
|
||||
brew services start redis
|
||||
fi
|
||||
elif [[ "${OSNAME}" == "alpine"* ]]; then
|
||||
if rc-service "redis" status | grep -q "running"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it..."
|
||||
rc-service "redis" start
|
||||
fi
|
||||
elif [[ "${OSNAME}" == "arch"* ]]; then
|
||||
if systemctl is-active --quiet "redis"; then
|
||||
echo "redis is already running."
|
||||
else
|
||||
echo "redis is not running. Starting it..."
|
||||
sudo systemctl start "redis"
|
||||
fi
|
||||
else
|
||||
echo "Service management for redis is not implemented for platform: $OSNAME"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Handle remove if requested
|
||||
if [ "$REMOVE" = true ]; then
|
||||
remove_all
|
||||
@@ -390,6 +457,8 @@ if ! command_exists v; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_and_start_redis
|
||||
|
||||
if [ "$HEROLIB" = true ]; then
|
||||
hero_lib_get
|
||||
~/code/github/freeflowuniverse/herolib/install_herolib.vsh
|
||||
|
||||
Reference in New Issue
Block a user