-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.sh
executable file
·101 lines (85 loc) · 3.87 KB
/
boot.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
set -euo pipefail
# Professional ASCII Art for Setupr Logo
ascii_art='
███████╗███████╗████████╗██╗ ██╗██████╗ ██████╗
██╔════╝██╔════╝╚══██╔══╝██║ ██║██╔══██╗██╔══██╗
███████╗█████╗ ██║ ██║ ██║██████╔╝██████╔╝
╚════██║██╔══╝ ██║ ██║ ██║██╔═══╝ ██╔══██╗
███████║███████╗ ██║ ╚██████╔╝██║ ██║ ██║
╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
'
# Ensure the script is run with sudo (not directly as root)
if [ "$EUID" -eq 0 ] && [ -z "${SUDO_USER:-}" ]; then
echo "Error: Run with sudo, not as root."
exit 1
elif [ "$EUID" -ne 0 ]; then
echo "Error: Run with sudo."
exit 1
fi
# Install dependency: gum
install_dependencies() {
if ! command -v gum &>/dev/null; then
echo "Installing dependency: gum..."
if curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo apt-key add -; then
echo "deb [arch=amd64] https://repo.charm.sh/apt/ * *" | \
sudo tee /etc/apt/sources.list.d/charm.list
sudo apt-get update -o Dir::Etc::sourcelist="/etc/apt/sources.list.d/charm.list" \
-o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y gum
else
echo "Error: Failed to add Charm repository key."
exit 1
fi
fi
}
# Main installation variables
INSTALL_DIR="/usr/local/share/Setupr"
USER_HOME=$(eval echo ~${SUDO_USER})
# Execute setup functions
install_dependencies
# Prepare the user environment
mkdir -p "${USER_HOME}/Downloads"
chown -R "${SUDO_USER}:${SUDO_USER}" "${USER_HOME}/Downloads"
# Preserve and set essential environment variables
[ -n "${TERM:-}" ] && export TERM
# Export essential environment variables for proper operation
USER_HOME="$(getent passwd "$SUDO_USER" | cut -d: -f6)"
# Set proper environment variables to run as the real user
export HOME="$USER_HOME"
export USER="$SUDO_USER"
export LOGNAME="$SUDO_USER"
export XDG_RUNTIME_DIR="/run/user/$(id -u ${SUDO_USER})"
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
export SUDO_HOME="$USER_HOME" # Additional variable for scripts to use
# Create and set permissions for Downloads directory
mkdir -p "${HOME}/Downloads"
chown -R "${SUDO_USER}:${SUDO_USER}" "${HOME}/Downloads"
# Display logo and notification
echo -e "$ascii_art"
echo "=> Setupr is for fresh Ubuntu 24.04+ installations only!"
echo "Begin installation (ctrl+c to abort)..."
# Remove existing directory if it exists
if [ -d "$INSTALL_DIR" ]; then
rm -rf "$INSTALL_DIR"
fi
# Clone fresh repository
mkdir -p "$INSTALL_DIR"
echo "Cloning Setupr..."
if ! git clone -b v2.2 https://github.com/ByteTrix/Setupr.git "$INSTALL_DIR"; then
echo "Error: Failed to clone repository."
exit 1
fi
# Set executable permissions and ownership
chmod +x "$INSTALL_DIR"/{install,check-version,system-update}.sh
chmod +x "$INSTALL_DIR"/modules/*/*.sh 2>/dev/null || true
chown -R "${SUDO_USER}:${SUDO_USER}" "$INSTALL_DIR"
# Source utility functions and run system update
source "${INSTALL_DIR}/lib/utils.sh"
log_info "Running system update..."
sudo -E TERM="$TERM" bash "$INSTALL_DIR/system-update.sh"
log_info "Starting Setupr installation..."
# Preserve TERM for proper terminal handling
[ -n "${TERM:-}" ] && export TERM
# Final command: run install.sh while preserving TERM
sudo -E TERM="$TERM" bash "$INSTALL_DIR/install.sh"