-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
123 lines (104 loc) · 3.16 KB
/
install.sh
File metadata and controls
123 lines (104 loc) · 3.16 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}Installing RPM...${NC}"
# Detect architecture and OS
ARCH=$(uname -m)
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
# Convert architecture names
case ${ARCH} in
x86_64)
ARCH="x86_64"
;;
aarch64)
ARCH="aarch64"
;;
*)
echo -e "${RED}Unsupported architecture: ${ARCH}${NC}"
exit 1
;;
esac
# Allow custom installation directory
DEFAULT_INSTALL_DIR="/usr/local/bin"
INSTALL_DIR=${RPM_INSTALL_DIR:-$DEFAULT_INSTALL_DIR}
RPM_HOME="${HOME}/.rpm"
# Create temporary directory
TMP_DIR=$(mktemp -d)
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
# Download binary
echo "Downloading RPM..."
BINARY_URL="https://github.com/nowayhecodes/rpm/releases/latest/download/rpm-${OS}-${ARCH}.tar.gz"
if ! curl -L --progress-bar "$BINARY_URL" -o "$TMP_DIR/rpm.tar.gz"; then
echo -e "${RED}Failed to download RPM${NC}"
exit 1
fi
# Extract binary
cd "$TMP_DIR"
tar xzf rpm.tar.gz
# Create RPM home directory
mkdir -p "$RPM_HOME"
mkdir -p "$RPM_HOME/bin"
# Install binary
if [ ! -w "$INSTALL_DIR" ]; then
echo "Escalating privileges to install to $INSTALL_DIR"
sudo mv "$TMP_DIR/rpm" "$INSTALL_DIR/rpm"
sudo chmod +x "$INSTALL_DIR/rpm"
else
mv "$TMP_DIR/rpm" "$INSTALL_DIR/rpm"
chmod +x "$INSTALL_DIR/rpm"
fi
# Update shell configuration
update_shell_config() {
local shell_config="$1"
local updated=false
# Create config file if it doesn't exist
touch "$shell_config"
# Check if RPM_HOME is already in the config
if ! grep -q "export RPM_HOME=" "$shell_config"; then
echo -e "\n# RPM Configuration" >>"$shell_config"
echo "export RPM_HOME=\"$RPM_HOME\"" >>"$shell_config"
updated=true
fi
# Add to PATH if custom installation directory is used
if [ "$INSTALL_DIR" != "$DEFAULT_INSTALL_DIR" ]; then
if ! grep -q "export PATH=.*$INSTALL_DIR" "$shell_config"; then
echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >>"$shell_config"
updated=true
fi
fi
# Add RPM_HOME/bin to PATH
if ! grep -q "export PATH=.*\$RPM_HOME/bin" "$shell_config"; then
echo "export PATH=\"\$PATH:\$RPM_HOME/bin\"" >>"$shell_config"
updated=true
fi
if [ "$updated" = true ]; then
echo -e "${GREEN}Updated ${shell_config}${NC}"
fi
}
# Update shell configurations
if [ -n "$BASH_VERSION" ]; then
update_shell_config "$HOME/.bashrc"
elif [ -n "$ZSH_VERSION" ]; then
update_shell_config "$HOME/.zshrc"
fi
# Verify installation
if command -v rpm >/dev/null; then
echo -e "${GREEN}RPM has been successfully installed!${NC}"
echo -e "You can now use RPM by running: ${BLUE}rpm install <package>${NC}"
echo -e "\nEnvironment variables set:"
echo -e "${BLUE}RPM_HOME=${RPM_HOME}${NC}"
echo -e "${BLUE}PATH includes: ${INSTALL_DIR}${NC}"
echo -e "\nPlease restart your shell or run:"
echo -e "${BLUE}source ~/.bashrc${NC} (for bash)"
echo -e "${BLUE}source ~/.zshrc${NC} (for zsh)"
else
echo -e "${RED}Installation failed. Please try again or install manually.${NC}"
exit 1
fi