Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create install_arch.sh #335

Merged
merged 9 commits into from
May 4, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,4 @@ $RECYCLE.BIN/

data/
.pdm-python
.history
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mkdir -p ./Spoolman && \
source_url=$(curl -s https://api.github.com/repos/Donkie/Spoolman/releases/latest | jq -r '.assets[] | select(.name == "spoolman.zip").browser_download_url') && \
curl -sSL $source_url -o temp.zip && unzip temp.zip -d ./Spoolman && rm temp.zip && \
cd ./Spoolman && \
bash ./scripts/install_debian.sh
bash ./scripts/install.sh
```

#### Updating
Expand All @@ -77,7 +77,7 @@ source_url=$(curl -s https://api.github.com/repos/Donkie/Spoolman/releases/lates
curl -sSL $source_url -o temp.zip && unzip temp.zip -d ./Spoolman && rm temp.zip && \
cp Spoolman_old/.env Spoolman/.env && \
cd ./Spoolman && \
bash ./scripts/install_debian.sh && \
bash ./scripts/install.sh && \
rm -rf ../Spoolman_old
```

Expand Down
66 changes: 47 additions & 19 deletions scripts/install_debian.sh → scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,63 @@ else
echo -e "${ORANGE}Please look up how to install Python 3.9 or later for your specific operating system.${NC}"
exit 1
fi

#
# Install needed system packages
# Get os package manager
#
# Run apt-get update
echo -e "${GREEN}Updating apt-get cache...${NC}"
sudo apt-get update || exit 1
if [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ "$ID_LIKE" == *"debian"* ]]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out on Debian itself, ID_LIKE doesn't exist, only ID does, which is "debian". So you should check for either ID_LIKE like you do here, or "$ID" == *"debian"*

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I check for both ID and ID_LIKE variables, this should do the trick for you.

pkg_manager="apt-get"
Donkie marked this conversation as resolved.
Show resolved Hide resolved
update_cmd="sudo $pkg_manager update"
install_cmd="sudo $pkg_manager install -y"
elif [[ "$ID_LIKE" == *"arch"* ]]; then
pkg_manager="pacman"
update_cmd="sudo $pkg_manager -Sy"
install_cmd="sudo $pkg_manager -S --noconfirm"
else
echo -e "${ORANGE}Your operating system is not supported. Either try to install manually or reach out to spoolman github for support.${NC}"
exit 1
fi
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If /etc/os-release is not available it should also fail


install_packages=0
# Run pkg manager update
echo -e "${GREEN}Updating $pkg_manager cache...${NC}"
$update_cmd || exit 1
packages=""
if ! python3 -c 'import venv, ensurepip' &>/dev/null; then
echo -e "${ORANGE}Python venv module is not accessible. Installing venv...${NC}"
install_packages=1
if [[ "$pkg_manager" == "apt-get" ]]; then
packages+="python3-venv"
elif [[ "$pkg_manager" == "pacman" ]]; then
packages+="python-virtualenv"
fi
fi

if ! command -v pip3 &>/dev/null; then
echo -e "${ORANGE}Python pip is not installed. Installing pip...${NC}"
install_packages=1
if [[ "$pkg_manager" == "apt-get" ]]; then
packages+="python3-pip"
Donkie marked this conversation as resolved.
Show resolved Hide resolved
elif [[ "$pkg_manager" == "pacman" ]]; then
packages+="python-pip"
fi
fi

if ! command -v pg_config &>/dev/null; then
echo -e "${ORANGE}pg_config is not available. Installing libpq-dev...${NC}"
install_packages=1
if [[ "$pkg_manager" == "apt-get" ]]; then
packages+="libpq-dev"
elif [[ "$pkg_manager" == "pacman" ]]; then
packages+="postgresql-libs"
fi
fi

if ! command -v unzip &>/dev/null; then
echo -e "${ORANGE}unzip is not available. Installing unzip...${NC}"
install_packages=1
packages+="unzip"
fi

if [ "$install_packages" -eq 1 ]; then
# sudo apt-get update
sudo apt-get install -y python3-pip python3-venv libpq-dev unzip || exit 1
if [[ -n "$packages" ]]; then
$install_cmd $packages || exit 1
fi

#
Expand Down Expand Up @@ -114,11 +139,15 @@ fi
echo -e "${GREEN}Installing system-wide pip packages needed for Spoolman...${NC}"
if [[ $is_externally_managed_env ]]; then
echo -e "${GREEN}Installing the packages using apt-get instead of pip since pip is externally managed...${NC}"
apt_packages=("python3-setuptools" "python3-wheel")
sudo apt-get install -y "${apt_packages[@]}" || exit 1
if [[ "$pkg_manager" == "apt-get" ]]; then
packages="python3-setuptools python3-wheel"
elif [[ "$pkg_manager" == "pacman" ]]; then
packages="python-setuptools python-wheel"
fi
$install_cmd $packages || exit 1
else
packages=("setuptools" "wheel")
for package in "${packages[@]}"; do
packages="setuptools wheel"
for package in $packages; do
if ! pip3 show "$package" &>/dev/null; then
echo -e "${GREEN}Installing $package...${NC}"
pip3 install --user "$package" || exit 1
Expand All @@ -138,9 +167,8 @@ fi
# Install Spoolman
#

# Install PDM dependencies
# Install dependencies
echo -e "${GREEN}Installing Spoolman backend and its dependencies...${NC}"

# Create venv if it doesn't exist
if [ ! -d ".venv" ]; then
python3 -m venv .venv || exit 1
Expand Down