Skip to content

Commit

Permalink
Merge pull request #435 from foxt/patch-1
Browse files Browse the repository at this point in the history
Install script: Don't bother using sudo if user is running as root
  • Loading branch information
Donkie authored Aug 9, 2024
2 parents 2fd8003 + 208e2f6 commit b2f6227
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CYAN='\033[0;36m'
NC='\033[0m' # No Color

# Warn with a prompt if we're running as root
SUDO=sudo
if [ "$EUID" -eq 0 ]; then
echo -e "${ORANGE}WARNING: You are running this script as root. It is recommended to run this script as a non-root user.${NC}"
echo -e "${ORANGE}Do you want to continue? (y/n)${NC}"
Expand All @@ -16,6 +17,8 @@ if [ "$EUID" -eq 0 ]; then
echo -e "${ORANGE}Aborting installation.${NC}"
exit 1
fi

SUDO=
fi

# CD to project root if we're in the scripts dir
Expand Down Expand Up @@ -58,13 +61,13 @@ if [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ "$ID_LIKE" == *"debian"* || "$ID" == *"debian"* ]]; then
pkg_manager="apt-get"
update_cmd="sudo $pkg_manager update"
install_cmd="sudo $pkg_manager install -y"
update_cmd="$SUDO $pkg_manager update"
install_cmd="$SUDO $pkg_manager install -y"
echo -e "${GREEN}Detected Debian-based system. Using apt-get package manager.${NC}"
elif [[ "$ID_LIKE" == *"arch"* || "$ID" == *"arch"* ]]; then
pkg_manager="pacman"
update_cmd="sudo $pkg_manager -Sy"
install_cmd="sudo $pkg_manager -S --noconfirm"
update_cmd="$SUDO $pkg_manager -Sy"
install_cmd="$SUDO $pkg_manager -S --noconfirm"
echo -e "${GREEN}Detected Arch-based system. Using pacman package manager.${NC}"
else
echo -e "${ORANGE}Your operating system is not supported. Either try to install manually or reach out to spoolman github for support.${NC}"
Expand Down Expand Up @@ -249,14 +252,14 @@ WantedBy=default.target

# Create the systemd service unit file
service_file="/etc/systemd/system/$service_name.service"
echo "$service_unit" | sudo tee "$service_file" > /dev/null
echo "$service_unit" | $SUDO tee "$service_file" > /dev/null

# Reload the systemd user service manager
sudo systemctl daemon-reload
$SUDO systemctl daemon-reload

# Enable and start the service
sudo systemctl enable "$service_name"
sudo systemctl start "$service_name"
$SUDO systemctl enable "$service_name"
$SUDO systemctl start "$service_name"

# Load .env file now
set -o allexport
Expand Down

0 comments on commit b2f6227

Please sign in to comment.