Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 83af9ad

Browse files
committed
...
1 parent 8fa5517 commit 83af9ad

File tree

2 files changed

+229
-0
lines changed

2 files changed

+229
-0
lines changed

install.sh

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Colors for output
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[0;33m'
8+
NC='\033[0m' # No Color
9+
10+
# GitHub repository information
11+
GITHUB_REPO="threefoldtech/zinit"
12+
13+
# Get the latest version from GitHub API
14+
echo -e "${YELLOW}Fetching latest version information...${NC}"
15+
if command -v curl &> /dev/null; then
16+
VERSION=$(curl -s "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep -o '"tag_name": "[^"]*' | grep -o '[^"]*$')
17+
elif command -v wget &> /dev/null; then
18+
VERSION=$(wget -qO- "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | grep -o '"tag_name": "[^"]*' | grep -o '[^"]*$')
19+
else
20+
echo -e "${RED}Neither curl nor wget found. Please install one of them and try again.${NC}"
21+
exit 1
22+
fi
23+
24+
if [ -z "$VERSION" ]; then
25+
echo -e "${RED}Failed to fetch the latest version. Please check your internet connection.${NC}"
26+
exit 1
27+
fi
28+
29+
echo -e "${GREEN}Latest version: ${VERSION}${NC}"
30+
DOWNLOAD_URL="https://github.com/${GITHUB_REPO}/releases/download/${VERSION}"
31+
MIN_SIZE_BYTES=2000000 # 2MB in bytes
32+
33+
echo -e "${GREEN}Installing zinit ${VERSION}...${NC}"
34+
35+
# Create temporary directory
36+
TMP_DIR=$(mktemp -d)
37+
trap 'rm -rf "$TMP_DIR"' EXIT
38+
39+
# Detect OS and architecture
40+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
41+
ARCH=$(uname -m)
42+
43+
# Map architecture names
44+
if [ "$ARCH" = "x86_64" ]; then
45+
ARCH_NAME="x86_64"
46+
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
47+
ARCH_NAME="aarch64"
48+
else
49+
echo -e "${RED}Unsupported architecture: $ARCH${NC}"
50+
exit 1
51+
fi
52+
53+
# Determine binary name based on OS and architecture
54+
if [ "$OS" = "linux" ]; then
55+
if [ "$ARCH_NAME" = "x86_64" ]; then
56+
BINARY_NAME="zinit-linux-x86_64"
57+
else
58+
echo -e "${RED}Unsupported Linux architecture: $ARCH${NC}"
59+
exit 1
60+
fi
61+
elif [ "$OS" = "darwin" ]; then
62+
if [ "$ARCH_NAME" = "x86_64" ]; then
63+
BINARY_NAME="zinit-macos-x86_64"
64+
elif [ "$ARCH_NAME" = "aarch64" ]; then
65+
BINARY_NAME="zinit-macos-aarch64"
66+
else
67+
echo -e "${RED}Unsupported macOS architecture: $ARCH${NC}"
68+
exit 1
69+
fi
70+
else
71+
echo -e "${RED}Unsupported operating system: $OS${NC}"
72+
exit 1
73+
fi
74+
75+
# Download URL
76+
DOWNLOAD_PATH="${DOWNLOAD_URL}/${BINARY_NAME}"
77+
LOCAL_PATH="${TMP_DIR}/${BINARY_NAME}"
78+
79+
echo -e "${YELLOW}Detected: $OS on $ARCH_NAME${NC}"
80+
echo -e "${YELLOW}Downloading from: $DOWNLOAD_PATH${NC}"
81+
82+
# Download the binary
83+
if command -v curl &> /dev/null; then
84+
curl -L -o "$LOCAL_PATH" "$DOWNLOAD_PATH"
85+
elif command -v wget &> /dev/null; then
86+
wget -O "$LOCAL_PATH" "$DOWNLOAD_PATH"
87+
else
88+
echo -e "${RED}Neither curl nor wget found. Please install one of them and try again.${NC}"
89+
exit 1
90+
fi
91+
92+
# Check file size
93+
FILE_SIZE=$(stat -f%z "$LOCAL_PATH" 2>/dev/null || stat -c%s "$LOCAL_PATH" 2>/dev/null)
94+
if [ "$FILE_SIZE" -lt "$MIN_SIZE_BYTES" ]; then
95+
echo -e "${RED}Downloaded file is too small (${FILE_SIZE} bytes). Expected at least ${MIN_SIZE_BYTES} bytes.${NC}"
96+
echo -e "${RED}This might indicate a failed or incomplete download.${NC}"
97+
exit 1
98+
fi
99+
100+
echo -e "${GREEN}Download successful. File size: $(echo "$FILE_SIZE / 1000000" | bc -l | xargs printf "%.2f") MB${NC}"
101+
102+
# Make the binary executable
103+
chmod +x "$LOCAL_PATH"
104+
105+
# Determine installation directory
106+
if [ "$OS" = "darwin" ]; then
107+
# macOS - install to ~/hero/bin/
108+
INSTALL_DIR="$HOME/hero/bin"
109+
else
110+
# Linux - install to /usr/local/bin/ if running as root, otherwise to ~/.local/bin/
111+
if [ "$(id -u)" -eq 0 ]; then
112+
INSTALL_DIR="/usr/local/bin"
113+
else
114+
INSTALL_DIR="$HOME/.local/bin"
115+
# Ensure ~/.local/bin exists and is in PATH
116+
mkdir -p "$INSTALL_DIR"
117+
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
118+
echo -e "${YELLOW}Adding $INSTALL_DIR to your PATH. You may need to restart your terminal.${NC}"
119+
if [ -f "$HOME/.bashrc" ]; then
120+
echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >> "$HOME/.bashrc"
121+
fi
122+
if [ -f "$HOME/.zshrc" ]; then
123+
echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >> "$HOME/.zshrc"
124+
fi
125+
fi
126+
fi
127+
fi
128+
129+
# Create installation directory if it doesn't exist
130+
mkdir -p "$INSTALL_DIR"
131+
132+
# Copy the binary to the installation directory
133+
cp "$LOCAL_PATH" "$INSTALL_DIR/zinit"
134+
echo -e "${GREEN}Installed zinit to $INSTALL_DIR/zinit${NC}"
135+
136+
# Test the installation
137+
echo -e "${YELLOW}Testing installation...${NC}"
138+
if "$INSTALL_DIR/zinit" --help &> /dev/null; then
139+
echo -e "${GREEN}Installation successful! You can now use 'zinit' command.${NC}"
140+
echo -e "${YELLOW}Example usage: zinit --help${NC}"
141+
"$INSTALL_DIR/zinit" --help | head -n 5
142+
else
143+
echo -e "${RED}Installation test failed. Please check the error messages above.${NC}"
144+
exit 1
145+
fi
146+
147+
echo -e "${GREEN}zinit ${VERSION} has been successfully installed!${NC}"

install_run.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Colors for output
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[0;33m'
8+
NC='\033[0m' # No Color
9+
10+
echo -e "${GREEN}Starting zinit installation and setup...${NC}"
11+
12+
# Download and execute install.sh
13+
echo -e "${YELLOW}Downloading and executing install.sh...${NC}"
14+
curl -fsSL https://raw.githubusercontent.com/threefoldtech/zinit/main/install.sh | bash
15+
16+
# Determine the path to zinit based on OS
17+
if [ "$(uname -s)" = "Darwin" ]; then
18+
ZINIT_PATH="$HOME/hero/bin/zinit"
19+
else
20+
if [ "$(id -u)" -eq 0 ]; then
21+
ZINIT_PATH="/usr/local/bin/zinit"
22+
else
23+
ZINIT_PATH="$HOME/.local/bin/zinit"
24+
fi
25+
fi
26+
27+
# Ensure zinit is in PATH
28+
export PATH="$PATH:$(dirname "$ZINIT_PATH")"
29+
30+
# Function to check if zinit is running
31+
is_zinit_running() {
32+
pgrep -f "zinit$" > /dev/null
33+
return $?
34+
}
35+
36+
# Try to shutdown zinit gracefully if it's running
37+
if is_zinit_running; then
38+
echo -e "${YELLOW}Zinit is already running. Attempting graceful shutdown...${NC}"
39+
"$ZINIT_PATH" shutdown || true
40+
41+
# Give it a moment to shut down
42+
sleep 2
43+
44+
# Check if it's still running
45+
if is_zinit_running; then
46+
echo -e "${YELLOW}Zinit is still running. Attempting to kill the process...${NC}"
47+
pkill -f "zinit$" || true
48+
sleep 1
49+
fi
50+
else
51+
echo -e "${YELLOW}No existing zinit process found.${NC}"
52+
fi
53+
54+
# Double-check no zinit is running
55+
if is_zinit_running; then
56+
echo -e "${RED}Warning: Could not terminate existing zinit process. You may need to manually kill it.${NC}"
57+
ps aux | grep "zinit" | grep -v grep
58+
else
59+
echo -e "${GREEN}No zinit process is running. Ready to start a new instance.${NC}"
60+
fi
61+
62+
# Launch zinit in the background
63+
echo -e "${GREEN}Starting zinit in the background...${NC}"
64+
"$ZINIT_PATH" &
65+
66+
# Give it a moment to start
67+
sleep 1
68+
69+
# Verify zinit is running
70+
if is_zinit_running; then
71+
echo -e "${GREEN}Zinit is now running in the background.${NC}"
72+
echo -e "${YELLOW}You can manage services with:${NC}"
73+
echo -e " ${YELLOW}$ZINIT_PATH list${NC} - List all services"
74+
echo -e " ${YELLOW}$ZINIT_PATH status${NC} - Show status of all services"
75+
echo -e " ${YELLOW}$ZINIT_PATH monitor${NC} - Monitor services in real-time"
76+
echo -e " ${YELLOW}$ZINIT_PATH shutdown${NC} - Shutdown zinit when needed"
77+
else
78+
echo -e "${RED}Failed to start zinit. Please check for errors above.${NC}"
79+
exit 1
80+
fi
81+
82+
echo -e "${GREEN}Zinit installation and startup complete!${NC}"

0 commit comments

Comments
 (0)