-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
84 lines (71 loc) · 2.42 KB
/
install.sh
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
#!/bin/bash
# Installation script for bash-library
# This script installs the bash library system-wide
set -euo pipefail
# Configuration
INSTALL_DIR="${BASH_LIBRARY_PATH:-/usr/local/lib/bash-library}"
BIN_DIR="/usr/local/bin"
PROFILE_DIR="/etc/profile.d"
# Read version from version file
VERSION=$(cat version)
# Check if running as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Create source directory structure if it doesn't exist
echo "Creating source directory structure..."
mkdir -p modules scripts
# Create installation directory
echo "Creating installation directory..."
mkdir -p "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR/modules"
mkdir -p "$INSTALL_DIR/scripts"
mkdir -p "$BIN_DIR"
# Copy library files
echo "Copying library files..."
cp -r modules/* "$INSTALL_DIR/modules/"
cp -r scripts/* "$INSTALL_DIR/scripts/"
cp lib-loader.sh "$INSTALL_DIR/"
# Create symlinks for scripts
echo "Creating symlinks for scripts..."
for script in "$INSTALL_DIR/scripts"/*.sh; do
if [ -f "$script" ]; then
script_name=$(basename "$script" .sh)
ln -sf "$script" "$BIN_DIR/$script_name"
fi
done
# Set permissions
echo "Setting permissions..."
chmod -R 755 "$INSTALL_DIR"
chmod 644 "$INSTALL_DIR/modules"/*.sh
chmod 755 "$INSTALL_DIR/scripts"/*.sh
# Create system-wide profile script
echo "Creating system-wide profile script..."
mkdir -p "$PROFILE_DIR"
{
echo "# Bash Library"
echo "export BASH_LIBRARY_PATH=\"$INSTALL_DIR\""
echo "export BASH_LIBRARY_VERSION=\"$VERSION\""
echo "export PATH=\"\$PATH:$BIN_DIR\""
echo "source \"$INSTALL_DIR/lib-loader.sh\""
} > "$PROFILE_DIR/bash-library.sh"
chmod 644 "$PROFILE_DIR/bash-library.sh"
# Add to user shell initialization
echo "Adding to user shell initialization..."
for shell_rc in ~/.bashrc ~/.zshrc; do
if [ -f "$shell_rc" ]; then
if ! grep -q "source $INSTALL_DIR/lib-loader.sh" "$shell_rc"; then
{
echo "# Bash Library"
echo "export BASH_LIBRARY_PATH=\"$INSTALL_DIR\""
echo "export BASH_LIBRARY_VERSION=\"$VERSION\""
echo "export PATH=\"\$PATH:$BIN_DIR\""
echo "source \"$INSTALL_DIR/lib-loader.sh\""
} >> "$shell_rc"
fi
fi
done
echo "Installation complete!"
echo "The bash library is now available system-wide."
echo "You may need to restart your shell or run: source /etc/profile.d/bash-library.sh"