Merge pull request #182 from Incubaid/development_installer
Update install script
This commit is contained in:
5
.github/workflows/hero_build.yml
vendored
5
.github/workflows/hero_build.yml
vendored
@@ -46,9 +46,6 @@ jobs:
|
|||||||
cd v
|
cd v
|
||||||
make
|
make
|
||||||
./v symlink
|
./v symlink
|
||||||
if [ "${{ runner.os }}" = "macOS" ]; then
|
|
||||||
sudo sed -i '' '618,631d' /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h
|
|
||||||
fi
|
|
||||||
cd -
|
cd -
|
||||||
|
|
||||||
mkdir -p ~/.vmodules/incubaid
|
mkdir -p ~/.vmodules/incubaid
|
||||||
@@ -92,7 +89,7 @@ jobs:
|
|||||||
'
|
'
|
||||||
|
|
||||||
else
|
else
|
||||||
v -w -d use_openssl -enable-globals -gc none -cc tcc cli/hero.v -o cli/hero-${{ matrix.target }}
|
v -w -d use_openssl -enable-globals -cc clang cli/hero.v -o cli/hero-${{ matrix.target }}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Upload glibc binary
|
- name: Upload glibc binary
|
||||||
|
|||||||
572
install_v.sh
572
install_v.sh
@@ -1,8 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
#==============================================================================
|
||||||
cd "$SCRIPT_DIR"
|
# GLOBAL VARIABLES
|
||||||
|
#==============================================================================
|
||||||
|
RESET=false
|
||||||
|
REMOVE=false
|
||||||
|
INSTALL_ANALYZER=false
|
||||||
|
HEROLIB=false
|
||||||
|
START_REDIS=false
|
||||||
|
|
||||||
|
export DIR_BASE="$HOME"
|
||||||
|
export DIR_BUILD="/tmp"
|
||||||
|
export DIR_CODE="$DIR_BASE/code"
|
||||||
|
export DIR_CODE_V="$DIR_BASE/_code"
|
||||||
|
export OSNAME=""
|
||||||
|
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
# FUNCTION DEFINITIONS
|
||||||
|
#==============================================================================
|
||||||
|
|
||||||
# Help function
|
# Help function
|
||||||
print_help() {
|
print_help() {
|
||||||
@@ -16,6 +33,8 @@ print_help() {
|
|||||||
echo " --remove Remove V installation and exit"
|
echo " --remove Remove V installation and exit"
|
||||||
echo " --analyzer Install/update v-analyzer"
|
echo " --analyzer Install/update v-analyzer"
|
||||||
echo " --herolib Install our herolib"
|
echo " --herolib Install our herolib"
|
||||||
|
echo " --herolib-version=VERSION Install specific herolib tag/branch (default: development)"
|
||||||
|
echo " --start-redis Start the Redis service if installed"
|
||||||
echo
|
echo
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " $0"
|
echo " $0"
|
||||||
@@ -27,38 +46,6 @@ print_help() {
|
|||||||
echo
|
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
|
# Function to check if command exists
|
||||||
command_exists() {
|
command_exists() {
|
||||||
command -v "$1" >/dev/null 2>&1
|
command -v "$1" >/dev/null 2>&1
|
||||||
@@ -80,25 +67,20 @@ function run_sudo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
export DIR_BASE="$HOME"
|
|
||||||
export DIR_BUILD="/tmp"
|
|
||||||
export DIR_CODE="$DIR_BASE/code"
|
|
||||||
export DIR_CODE_V="$DIR_BASE/_code"
|
|
||||||
|
|
||||||
check_release() {
|
check_release() {
|
||||||
if ! command -v lsb_release >/dev/null 2>&1; then
|
if ! command -v lsb_release >/dev/null 2>&1; then
|
||||||
echo "❌ lsb_release command not found. Install 'lsb-release' package first."
|
echo "❌ lsb_release command not found. Install 'lsb-release' package first."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CODENAME=$(lsb_release -sc)
|
CODENAME=$(lsb_release -sc)
|
||||||
RELEASE=$(lsb_release -rs)
|
RELEASE=$(lsb_release -rs)
|
||||||
|
|
||||||
if dpkg --compare-versions "$RELEASE" lt "24.04"; then
|
if dpkg --compare-versions "$RELEASE" lt "24.04"; then
|
||||||
echo "ℹ️ Detected Ubuntu $RELEASE ($CODENAME). Skipping mirror fix (requires 24.04+)."
|
echo "ℹ️ Detected Ubuntu $RELEASE ($CODENAME). Skipping mirror fix (requires 24.04+)."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,36 +90,36 @@ ubuntu_sources_fix() {
|
|||||||
echo "ℹ️ Not running on Ubuntu. Skipping mirror fix."
|
echo "ℹ️ Not running on Ubuntu. Skipping mirror fix."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if check_release; then
|
if check_release; then
|
||||||
local CODENAME
|
local CODENAME
|
||||||
CODENAME=$(lsb_release -sc)
|
CODENAME=$(lsb_release -sc)
|
||||||
local TIMESTAMP
|
local TIMESTAMP
|
||||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||||
|
|
||||||
echo "🔎 Fixing apt mirror setup for Ubuntu $(lsb_release -rs) ($CODENAME)..."
|
echo "🔎 Fixing apt mirror setup for Ubuntu $(lsb_release -rs) ($CODENAME)..."
|
||||||
|
|
||||||
if [ -f /etc/apt/sources.list ]; then
|
if [ -f /etc/apt/sources.list ]; then
|
||||||
echo "📦 Backing up /etc/apt/sources.list -> /etc/apt/sources.list.backup.$TIMESTAMP"
|
echo "📦 Backing up /etc/apt/sources.list -> /etc/apt/sources.list.backup.$TIMESTAMP"
|
||||||
sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup.$TIMESTAMP
|
run_sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup.$TIMESTAMP
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
|
if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
|
||||||
echo "📦 Backing up /etc/apt/sources.list.d/ubuntu.sources -> /etc/apt/sources.list.d/ubuntu.sources.backup.$TIMESTAMP"
|
echo "📦 Backing up /etc/apt/sources.list.d/ubuntu.sources -> /etc/apt/sources.list.d/ubuntu.sources.backup.$TIMESTAMP"
|
||||||
sudo mv /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.backup.$TIMESTAMP
|
run_sudo mv /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.backup.$TIMESTAMP
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "📝 Writing new /etc/apt/sources.list.d/ubuntu.sources"
|
echo "📝 Writing new /etc/apt/sources.list.d/ubuntu.sources"
|
||||||
sudo tee /etc/apt/sources.list.d/ubuntu.sources >/dev/null <<EOF
|
run_sudo tee /etc/apt/sources.list.d/ubuntu.sources >/dev/null <<EOF
|
||||||
Types: deb
|
Types: deb
|
||||||
URIs: mirror://mirrors.ubuntu.com/mirrors.txt
|
URIs: mirror://mirrors.ubuntu.com/mirrors.txt
|
||||||
Suites: $CODENAME $CODENAME-updates $CODENAME-backports $CODENAME-security
|
Suites: $CODENAME $CODENAME-updates $CODENAME-backports $CODENAME-security
|
||||||
Components: main restricted universe multiverse
|
Components: main restricted universe multiverse
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo "🔄 Running apt update..."
|
echo "🔄 Running apt update..."
|
||||||
sudo apt update -qq
|
run_sudo apt update -qq
|
||||||
|
|
||||||
echo "✅ Done! Your system now uses the rotating Ubuntu mirror list."
|
echo "✅ Done! Your system now uses the rotating Ubuntu mirror list."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -156,37 +138,14 @@ function sshknownkeysadd {
|
|||||||
ssh-keyscan git.threefold.info >> ~/.ssh/known_hosts
|
ssh-keyscan git.threefold.info >> ~/.ssh/known_hosts
|
||||||
fi
|
fi
|
||||||
git config --global pull.rebase false
|
git config --global pull.rebase false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function package_check_install {
|
# Performs a non-interactive, forceful apt installation.
|
||||||
local command_name="$1"
|
# WARNING: This is designed for CI/automated environments. It can be dangerous
|
||||||
if command -v "$command_name" >/dev/null 2>&1; then
|
# on a personal machine as it may remove essential packages to resolve conflicts.
|
||||||
echo "command '$command_name' is already installed."
|
function apt_force_install {
|
||||||
else
|
run_sudo apt -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" install "$@" -q -y --allow-downgrades --allow-remove-essential
|
||||||
package_install '$command_name'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function package_install {
|
|
||||||
local command_name="$1"
|
|
||||||
if [[ "${OSNAME}" == "ubuntu" ]]; then
|
|
||||||
if is_github_actions; then
|
|
||||||
run_sudo apt -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" install $1 -q -y --allow-downgrades --allow-remove-essential
|
|
||||||
else
|
|
||||||
apt -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" install $1 -q -y --allow-downgrades --allow-remove-essential
|
|
||||||
fi
|
|
||||||
|
|
||||||
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() {
|
is_github_actions() {
|
||||||
@@ -201,11 +160,10 @@ is_github_actions() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function myplatform {
|
function myplatform {
|
||||||
if [[ "${OSTYPE}" == "darwin"* ]]; then
|
if [[ "${OSTYPE}" == "darwin"* ]]; then
|
||||||
export OSNAME='darwin'
|
export OSNAME='darwin'
|
||||||
elif [ -e /etc/os-release ]; then
|
elif [ -e /etc/os-release ]; then
|
||||||
# Read the ID field from the /etc/os-release file
|
# Read the ID field from the /etc/os-release file
|
||||||
export OSNAME=$(grep '^ID=' /etc/os-release | cut -d= -f2)
|
export OSNAME=$(grep '^ID=' /etc/os-release | cut -d= -f2)
|
||||||
if [ "${OSNAME,,}" == "ubuntu" ]; then
|
if [ "${OSNAME,,}" == "ubuntu" ]; then
|
||||||
@@ -221,27 +179,14 @@ function myplatform {
|
|||||||
echo "Unable to determine the operating system."
|
echo "Unable to determine the operating system."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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 update_system {
|
||||||
|
echo ' - System Update'
|
||||||
function os_update {
|
|
||||||
if [[ "${OSNAME}" == "ubuntu" ]]; then
|
if [[ "${OSNAME}" == "ubuntu" ]]; then
|
||||||
ubuntu_sources_fix
|
ubuntu_sources_fix
|
||||||
fi
|
|
||||||
echo ' - os update'
|
|
||||||
if [[ "${OSNAME}" == "ubuntu" ]]; then
|
|
||||||
if is_github_actions; then
|
if is_github_actions; then
|
||||||
echo "github actions"
|
echo "github actions: preparing system"
|
||||||
else
|
else
|
||||||
rm -f /var/lib/apt/lists/lock
|
rm -f /var/lib/apt/lists/lock
|
||||||
rm -f /var/cache/apt/archives/lock
|
rm -f /var/cache/apt/archives/lock
|
||||||
@@ -252,54 +197,56 @@ function os_update {
|
|||||||
run_sudo dpkg --configure -a
|
run_sudo dpkg --configure -a
|
||||||
run_sudo apt update -y
|
run_sudo apt update -y
|
||||||
if is_github_actions; then
|
if is_github_actions; then
|
||||||
echo "** IN GITHUB ACTIONS, DON'T DO UPDATE"
|
echo "** IN GITHUB ACTIONS, DON'T DO SYSTEM UPGRADE"
|
||||||
else
|
else
|
||||||
set +e
|
set +e
|
||||||
echo "** UPDATE"
|
echo "** System Upgrade"
|
||||||
apt-mark hold grub-efi-amd64-signed
|
apt-mark hold grub-efi-amd64-signed
|
||||||
set -e
|
set -e
|
||||||
apt upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
|
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
|
apt autoremove -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
|
||||||
fi
|
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
|
elif [[ "${OSNAME}" == "darwin"* ]]; then
|
||||||
package_install "apt-transport-https ca-certificates curl wget software-properties-common tmux make gcc"
|
if ! command -v brew >/dev/null 2>&1; then
|
||||||
package_install "rclone rsync mc redis-server screen net-tools git dnsutils htop ca-certificates screen lsb-release binutils pkg-config libssl-dev iproute2"
|
echo ' - Installing Homebrew'
|
||||||
|
|
||||||
elif [[ "${OSNAME}" == "darwin"* ]]; then
|
|
||||||
if command -v brew >/dev/null 2>&1; then
|
|
||||||
echo ' - homebrew installed'
|
|
||||||
else
|
|
||||||
export NONINTERACTIVE=1
|
export NONINTERACTIVE=1
|
||||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||||
unset NONINTERACTIVE
|
unset NONINTERACTIVE
|
||||||
fi
|
fi
|
||||||
|
elif [[ "${OSNAME}" == "alpine"* ]]; then
|
||||||
|
apk update
|
||||||
|
elif [[ "${OSNAME}" == "arch"* ]]; then
|
||||||
|
pacman -Syyu --noconfirm
|
||||||
|
fi
|
||||||
|
echo ' - System Update Done'
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_packages {
|
||||||
|
echo ' - Installing Packages'
|
||||||
|
if [[ "${OSNAME}" == "ubuntu" ]]; then
|
||||||
|
apt_force_install apt-transport-https ca-certificates curl wget software-properties-common tmux make gcc rclone rsync mc redis-server screen net-tools git dnsutils htop lsb-release binutils pkg-config libssl-dev iproute2
|
||||||
|
elif [[ "${OSNAME}" == "darwin"* ]]; then
|
||||||
|
# The set +e is to prevent script failure if some packages are already installed.
|
||||||
set +e
|
set +e
|
||||||
brew install mc redis curl tmux screen htop wget rclone tcc
|
brew install mc redis curl tmux screen htop wget rclone tcc
|
||||||
set -e
|
set -e
|
||||||
elif [[ "${OSNAME}" == "alpine"* ]]; then
|
elif [[ "${OSNAME}" == "alpine"* ]]; then
|
||||||
apk update screen git htop tmux
|
apk add --no-cache screen git htop tmux mc curl rsync redis bash bash-completion rclone
|
||||||
apk add mc curl rsync htop redis bash bash-completion screen git rclone
|
# Switch default shell to bash for better interactive use
|
||||||
sed -i 's#/bin/ash#/bin/bash#g' /etc/passwd
|
sed -i 's#/bin/ash#/bin/bash#g' /etc/passwd
|
||||||
elif [[ "${OSNAME}" == "arch"* ]]; then
|
elif [[ "${OSNAME}" == "arch"* ]]; then
|
||||||
pacman -Syy --noconfirm
|
pacman -Su --noconfirm arch-install-scripts gcc mc git tmux curl htop redis wget screen net-tools sudo lsb-release rclone
|
||||||
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
|
# Check if builduser exists, create if not
|
||||||
if ! id -u builduser > /dev/null 2>&1; then
|
if ! id -u builduser > /dev/null 2>&1; then
|
||||||
useradd -m builduser
|
useradd -m builduser
|
||||||
echo "builduser:$(openssl rand -base64 32 | sha256sum | base64 | head -c 32)" | chpasswd
|
echo "builduser:$(openssl rand -base64 32 | sha256sum | base64 | head -c 32)" | chpasswd
|
||||||
echo 'builduser ALL=(ALL) NOPASSWD: ALL' | tee /etc/sudoers.d/builduser
|
echo 'builduser ALL=(ALL) NOPASSWD: ALL' | tee /etc/sudoers.d/builduser
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if [[ -n "${DEBUG}" ]]; then
|
|
||||||
# execute_with_marker "paru_install" paru_install
|
|
||||||
# fi
|
|
||||||
fi
|
fi
|
||||||
echo ' - os update done'
|
echo ' - Package Installation Done'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function hero_lib_pull {
|
function hero_lib_pull {
|
||||||
pushd $DIR_CODE/github/incubaid/herolib 2>&1 >> /dev/null
|
pushd $DIR_CODE/github/incubaid/herolib 2>&1 >> /dev/null
|
||||||
if [[ $(git status -s) ]]; then
|
if [[ $(git status -s) ]]; then
|
||||||
@@ -311,7 +258,7 @@ function hero_lib_pull {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function hero_lib_get {
|
function hero_lib_get {
|
||||||
|
|
||||||
mkdir -p $DIR_CODE/github/incubaid
|
mkdir -p $DIR_CODE/github/incubaid
|
||||||
if [[ -d "$DIR_CODE/github/incubaid/herolib" ]]
|
if [[ -d "$DIR_CODE/github/incubaid/herolib" ]]
|
||||||
then
|
then
|
||||||
@@ -321,46 +268,19 @@ function hero_lib_get {
|
|||||||
git clone --depth 1 --no-single-branch https://github.com/incubaid/herolib.git
|
git clone --depth 1 --no-single-branch https://github.com/incubaid/herolib.git
|
||||||
popd 2>&1 >> /dev/null
|
popd 2>&1 >> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Checkout specific version if requested
|
||||||
|
if [ -n "${HEROLIB_VERSION:-}" ]; then
|
||||||
|
pushd $DIR_CODE/github/incubaid/herolib 2>&1 >> /dev/null
|
||||||
|
if ! git checkout "$HEROLIB_VERSION"; then
|
||||||
|
echo "Failed to checkout herolib version: $HEROLIB_VERSION"
|
||||||
|
popd 2>&1 >> /dev/null
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
popd 2>&1 >> /dev/null
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# function install_secp256k1 {
|
|
||||||
|
|
||||||
# echo "Installing secp256k1..."
|
|
||||||
# if [[ "${OSNAME}" == "darwin"* ]]; then
|
|
||||||
# # Attempt installation only if not already found
|
|
||||||
# echo "Attempting secp256k1 installation via Homebrew..."
|
|
||||||
# brew install secp256k1
|
|
||||||
# elif [[ "${OSNAME}" == "ubuntu" ]]; then
|
|
||||||
# # Install build dependencies
|
|
||||||
# package_install "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
|
|
||||||
# if is_github_actions; then
|
|
||||||
# run_sudo make install
|
|
||||||
# else
|
|
||||||
# make install
|
|
||||||
# fi
|
|
||||||
|
|
||||||
# # 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() {
|
remove_all() {
|
||||||
echo "Removing V installation..."
|
echo "Removing V installation..."
|
||||||
# Set reset to true to use existing reset functionality
|
# Set reset to true to use existing reset functionality
|
||||||
@@ -377,7 +297,7 @@ remove_all() {
|
|||||||
echo "Removing v-analyzer from system..."
|
echo "Removing v-analyzer from system..."
|
||||||
run_sudo rm -f $(which v-analyzer)
|
run_sudo rm -f $(which v-analyzer)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove v-analyzer path from rc files
|
# Remove v-analyzer path from rc files
|
||||||
for RC_FILE in ~/.zshrc ~/.bashrc; do
|
for RC_FILE in ~/.zshrc ~/.bashrc; do
|
||||||
if [ -f "$RC_FILE" ]; then
|
if [ -f "$RC_FILE" ]; then
|
||||||
@@ -393,127 +313,54 @@ remove_all() {
|
|||||||
echo "Cleaned up $RC_FILE"
|
echo "Cleaned up $RC_FILE"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "V removal complete"
|
echo "V removal complete"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Starts the Redis service if it is not already running.
|
||||||
|
function start_redis_service() {
|
||||||
|
echo "Attempting to start Redis service..."
|
||||||
|
# Check if redis-server is even installed
|
||||||
|
if ! command_exists redis-server; then
|
||||||
|
echo "Warning: redis-server command not found. Skipping."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if redis is already running by pinging it
|
||||||
|
if redis-cli ping > /dev/null 2>&1; then
|
||||||
|
echo "Redis is already running."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Function to check if a service is running and start it if needed
|
echo "Redis is not running. Attempting to start it..."
|
||||||
check_and_start_redis() {
|
if command_exists systemctl; then
|
||||||
|
run_sudo systemctl start redis
|
||||||
# Normal service management for non-container environments
|
# For Alpine, use rc-service
|
||||||
if [[ "${OSNAME}" == "ubuntu" ]] || [[ "${OSNAME}" == "debian" ]]; then
|
elif command_exists rc-service; then
|
||||||
|
run_sudo rc-service redis start
|
||||||
# Handle Redis installation for GitHub Actions environment
|
elif [[ "${OSNAME}" == "darwin"* ]]; then
|
||||||
if is_github_actions; then
|
# For macOS, use brew services
|
||||||
|
if ! brew services list | grep -q "^redis.*started"; then
|
||||||
# Import Redis GPG key
|
brew services start redis
|
||||||
curl -fsSL https://packages.redis.io/gpg | run_sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
|
|
||||||
# Add Redis repository
|
|
||||||
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | run_sudo tee /etc/apt/sources.list.d/redis.list
|
|
||||||
# Install Redis
|
|
||||||
run_sudo apt-get update
|
|
||||||
run_sudo apt-get install -y redis
|
|
||||||
|
|
||||||
# Start Redis
|
|
||||||
redis-server --daemonize yes
|
|
||||||
|
|
||||||
# Print versions
|
|
||||||
redis-cli --version
|
|
||||||
redis-server --version
|
|
||||||
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 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 command_exists zinit; then
|
|
||||||
# Check if redis service is managed by zinit and is running
|
|
||||||
if zinit status redis | grep -q "state: Running"; then
|
|
||||||
echo "redis is already running and managed by zinit."
|
|
||||||
return
|
|
||||||
else
|
|
||||||
echo "zinit is installed, but redis is not running or not managed by zinit. Proceeding with other checks."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if systemctl is-active --quiet "redis"; then
|
|
||||||
echo "redis is already running."
|
|
||||||
else
|
|
||||||
echo "redis is not running. Starting it..."
|
|
||||||
run_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
|
|
||||||
# Check if we're in GitHub Actions
|
|
||||||
if is_github_actions; then
|
|
||||||
echo "Running in GitHub Actions on macOS. 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
|
|
||||||
else
|
|
||||||
# For regular macOS environments, use brew services
|
|
||||||
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
|
|
||||||
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..."
|
|
||||||
run_sudo systemctl start "redis"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Service management for redis is not implemented for platform: $OSNAME"
|
echo "No service manager found, starting Redis manually..."
|
||||||
|
redis-server --daemonize yes
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Final check to see if it started
|
||||||
|
sleep 1 # Give it a second to start up
|
||||||
|
if redis-cli ping > /dev/null 2>&1; then
|
||||||
|
echo "Redis started successfully."
|
||||||
|
else
|
||||||
|
echo "Error: Failed to start Redis."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
v-install() {
|
v-install() {
|
||||||
|
|
||||||
# Check if v is already installed and in PATH
|
# Check if v is already installed and in PATH
|
||||||
if command_exists v; then
|
if command_exists v; then
|
||||||
echo "V is already installed and in PATH."
|
echo "V is already installed and in PATH."
|
||||||
@@ -521,8 +368,8 @@ v-install() {
|
|||||||
# For now, just exit the function assuming it's okay
|
# For now, just exit the function assuming it's okay
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Only clone and install if directory doesn't exist
|
# Only clone and install if directory doesn't exist
|
||||||
# Note: The original check was for ~/code/v, but the installation happens in ~/_code/v.
|
# Note: The original check was for ~/code/v, but the installation happens in ~/_code/v.
|
||||||
if [ ! -d ~/_code/v ]; then
|
if [ ! -d ~/_code/v ]; then
|
||||||
@@ -535,8 +382,8 @@ v-install() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Only clone and install if directory doesn't exist
|
# Only clone and install if directory doesn't exist
|
||||||
# Note: The original check was for ~/code/v, but the installation happens in ~/_code/v.
|
# Note: The original check was for ~/code/v, but the installation happens in ~/_code/v.
|
||||||
# Adjusting the check to the actual installation directory.
|
# Adjusting the check to the actual installation directory.
|
||||||
@@ -555,43 +402,43 @@ v-install() {
|
|||||||
fi
|
fi
|
||||||
echo "V built successfully. Creating symlink..."
|
echo "V built successfully. Creating symlink..."
|
||||||
run_sudo ./v symlink
|
run_sudo ./v symlink
|
||||||
|
|
||||||
# Verify v is in path
|
# Verify v is in path
|
||||||
if ! command_exists v; then
|
if ! command_exists v; then
|
||||||
echo "Error: V installation failed or not in PATH"
|
echo "Error: V installation failed or not in PATH"
|
||||||
echo "Please ensure ~/code/v is in your PATH"
|
echo "Please ensure ~/code/v is in your PATH"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "V installation successful!"
|
echo "V installation successful!"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
v-analyzer() {
|
v-analyzer() {
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
# Install v-analyzer if requested
|
# Install v-analyzer if requested
|
||||||
if [ "$INSTALL_ANALYZER" = true ]; then
|
if [ "$INSTALL_ANALYZER" = true ]; then
|
||||||
echo "Installing v-analyzer..."
|
echo "Installing v-analyzer..."
|
||||||
cd /tmp
|
cd /tmp
|
||||||
v download -RD https://raw.githubusercontent.com/vlang/v-analyzer/main/install.vsh
|
v download -RD https://raw.githubusercontent.com/vlang/v-analyzer/main/install.vsh
|
||||||
|
|
||||||
# Check if v-analyzer bin directory exists
|
# Check if v-analyzer bin directory exists
|
||||||
if [ ! -d "$HOME/.config/v-analyzer/bin" ]; then
|
if [ ! -d "$HOME/.config/v-analyzer/bin" ]; then
|
||||||
echo "Error: v-analyzer bin directory not found at $HOME/.config/v-analyzer/bin"
|
echo "Error: v-analyzer bin directory not found at $HOME/.config/v-analyzer/bin"
|
||||||
echo "Please ensure v-analyzer was installed correctly"
|
echo "Please ensure v-analyzer was installed correctly"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "v-analyzer installation successful!"
|
echo "v-analyzer installation successful!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add v-analyzer to PATH if installed
|
# Add v-analyzer to PATH if installed
|
||||||
if [ -d "$HOME/.config/v-analyzer/bin" ]; then
|
if [ -d "$HOME/.config/v-analyzer/bin" ]; then
|
||||||
V_ANALYZER_PATH='export PATH="$PATH:$HOME/.config/v-analyzer/bin"'
|
V_ANALYZER_PATH='export PATH="$PATH:$HOME/.config/v-analyzer/bin"'
|
||||||
|
|
||||||
# Function to add path to rc file if not present
|
# Function to add path to rc file if not present
|
||||||
add_to_rc() {
|
add_to_rc() {
|
||||||
local RC_FILE="$1"
|
local RC_FILE="$1"
|
||||||
@@ -605,7 +452,7 @@ v-analyzer() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add to both .zshrc and .bashrc if they exist
|
# Add to both .zshrc and .bashrc if they exist
|
||||||
add_to_rc ~/.zshrc
|
add_to_rc ~/.zshrc
|
||||||
if [ "$(uname)" = "Darwin" ] && [ -f ~/.bashrc ]; then
|
if [ "$(uname)" = "Darwin" ] && [ -f ~/.bashrc ]; then
|
||||||
@@ -615,70 +462,119 @@ v-analyzer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
# MAIN EXECUTION
|
||||||
|
#==============================================================================
|
||||||
|
main() {
|
||||||
|
# Make sure we're running in the directory where the script is
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
# Handle remove if requested
|
# Parse arguments
|
||||||
if [ "$REMOVE" = true ]; then
|
for arg in "$@"; do
|
||||||
remove_all
|
case $arg in
|
||||||
exit 0
|
-h|--help)
|
||||||
fi
|
print_help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--reset)
|
||||||
|
RESET=true
|
||||||
|
;;
|
||||||
|
--remove)
|
||||||
|
REMOVE=true
|
||||||
|
;;
|
||||||
|
--herolib)
|
||||||
|
HEROLIB=true
|
||||||
|
;;
|
||||||
|
--herolib-version=*)
|
||||||
|
HEROLIB_VERSION="${arg#*=}"
|
||||||
|
if [ -z "$HEROLIB_VERSION" ]; then
|
||||||
|
echo "Error: --herolib-version requires a version argument"
|
||||||
|
echo "Example: $0 --herolib-version=v1.0.0"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
--analyzer)
|
||||||
|
INSTALL_ANALYZER=true
|
||||||
|
;;
|
||||||
|
--start-redis)
|
||||||
|
START_REDIS=true
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $arg"
|
||||||
|
echo "Use -h or --help to see available options"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
# Create code directory if it doesn't exist
|
myplatform
|
||||||
mkdir -p ~/code
|
|
||||||
|
# Handle remove if requested
|
||||||
|
if [ "$REMOVE" = true ]; then
|
||||||
|
remove_all
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create code directory if it doesn't exist
|
||||||
|
mkdir -p ~/code
|
||||||
|
|
||||||
|
|
||||||
# Check if v needs to be installed
|
# Check if v needs to be installed
|
||||||
if [ "$RESET" = true ] || ! command_exists v; then
|
if [ "$RESET" = true ] || ! command_exists v; then
|
||||||
|
|
||||||
os_update
|
|
||||||
|
|
||||||
sshknownkeysadd
|
|
||||||
|
|
||||||
# Install secp256k1
|
|
||||||
|
|
||||||
v-install
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# set -x
|
update_system
|
||||||
check_and_start_redis
|
install_packages
|
||||||
|
|
||||||
if [ "$HEROLIB" = true ]; then
|
sshknownkeysadd
|
||||||
echo "=== Herolib Installation ==="
|
|
||||||
echo "Current directory: $(pwd)"
|
|
||||||
echo "Checking for install_herolib.vsh: $([ -f "./install_herolib.vsh" ] && echo "found" || echo "not found")"
|
|
||||||
echo "Checking for lib directory: $([ -d "./lib" ] && echo "found" || echo "not found")"
|
|
||||||
|
|
||||||
# Check if we're in GitHub Actions and already in the herolib directory
|
# Install secp256k1
|
||||||
if is_github_actions; then
|
|
||||||
# In GitHub Actions, check if we're already in a herolib checkout
|
v-install
|
||||||
if [ -f "./install_herolib.vsh" ] && [ -d "./lib" ]; then
|
fi
|
||||||
echo "✓ Running in GitHub Actions, using current directory for herolib installation"
|
|
||||||
HEROLIB_DIR="$(pwd)"
|
if [ "$START_REDIS" = true ]; then
|
||||||
|
start_redis_service
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$HEROLIB" = true ]; then
|
||||||
|
echo "=== Herolib Installation ==="
|
||||||
|
echo "Current directory: $(pwd)"
|
||||||
|
echo "Checking for install_herolib.vsh: $([ -f "./install_herolib.vsh" ] && echo "found" || echo "not found")"
|
||||||
|
echo "Checking for lib directory: $([ -d "./lib" ] && echo "found" || echo "not found")"
|
||||||
|
|
||||||
|
# Check if we're in GitHub Actions and already in the herolib directory
|
||||||
|
if is_github_actions; then
|
||||||
|
# In GitHub Actions, check if we're already in a herolib checkout
|
||||||
|
if [ -f "./install_herolib.vsh" ] && [ -d "./lib" ]; then
|
||||||
|
echo "✓ Running in GitHub Actions, using current directory for herolib installation"
|
||||||
|
HEROLIB_DIR="$(pwd)"
|
||||||
|
else
|
||||||
|
echo "⚠ Running in GitHub Actions, but not in herolib directory. Cloning..."
|
||||||
|
hero_lib_get
|
||||||
|
HEROLIB_DIR="$HOME/code/github/incubaid/herolib"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "⚠ Running in GitHub Actions, but not in herolib directory. Cloning..."
|
echo "Not in GitHub Actions, using standard installation path"
|
||||||
hero_lib_get
|
hero_lib_get
|
||||||
HEROLIB_DIR="$HOME/code/github/incubaid/herolib"
|
HEROLIB_DIR="$HOME/code/github/incubaid/herolib"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "Not in GitHub Actions, using standard installation path"
|
echo "Installing herolib from: $HEROLIB_DIR"
|
||||||
hero_lib_get
|
"$HEROLIB_DIR/install_herolib.vsh"
|
||||||
HEROLIB_DIR="$HOME/code/github/incubaid/herolib"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Installing herolib from: $HEROLIB_DIR"
|
|
||||||
"$HEROLIB_DIR/install_herolib.vsh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
if [ "$INSTALL_ANALYZER" = true ]; then
|
||||||
if [ "$INSTALL_ANALYZER" = true ]; then
|
# Only install v-analyzer if not in GitHub Actions environment
|
||||||
# Only install v-analyzer if not in GitHub Actions environment
|
if ! is_github_actions; then
|
||||||
if ! is_github_actions; then
|
v-analyzer
|
||||||
v-analyzer
|
fi
|
||||||
|
echo "Run 'source ~/.bashrc' or 'source ~/.zshrc' to update PATH for v-analyzer"
|
||||||
fi
|
fi
|
||||||
echo "Run 'source ~/.bashrc' or 'source ~/.zshrc' to update PATH for v-analyzer"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
echo "Installation complete!"
|
echo "Installation complete!"
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user