Version 0.2 finally first commit
This commit is contained in:
132
distro_client/install_subdomain_client.sh
Normal file
132
distro_client/install_subdomain_client.sh
Normal file
@@ -0,0 +1,132 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo -e "\nInstalling Subdomain Client...\n"
|
||||
|
||||
# Define constants
|
||||
echo "Reading constants..."
|
||||
DEPENDENCIES=requests
|
||||
PYSCRIPT=refresh_subdomain.py
|
||||
INSTALLDIR=~/.local/share/refresh_subdomain
|
||||
BINDIR=~/.local/bin
|
||||
ENVDIR=~/.local/share/refresh_subdomain/venv
|
||||
SYSTEMDDIR=~/.config/systemd/user
|
||||
FILES2COPY=refresh_subdomain.py
|
||||
|
||||
echo -e "Constants:\n\tDependencies: $DEPENDENCIES\n\tInstall Directory: $INSTALLDIR\n\tLaunch Script: $BINDIR/refresh_subdomain\n\tEnvironment Directory: $ENVDIR\n\tFiles to Copy: $FILES2COPY\n"
|
||||
|
||||
echo "Checking install files..."
|
||||
# Make sure files to install are in current directory
|
||||
MISSINGFILES=false
|
||||
for file in $FILES2COPY; do
|
||||
if [ ! -f "$file" ]; then
|
||||
MISSINGFILES=true
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$MISSINGFILES" = true ]; then
|
||||
echo "Error: Required Install files not found in current directory"
|
||||
echo " Required files: $FILES2COPY"
|
||||
echo " Run this script from the root of the project directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test for venv
|
||||
echo "Checking for venv..."
|
||||
DEP_VENV=false
|
||||
python3 -c "import venv" && DEP_VENV=true || DEP_VENV=false
|
||||
|
||||
|
||||
if [ "$DEP_VENV" = false ]; then
|
||||
echo "Venv not installed. Installing venv..."
|
||||
python3 -m pip install venv
|
||||
|
||||
DEP_VENV=false
|
||||
python3 -c "import venv" && DEP_VENV=true || DEP_VENV=false
|
||||
|
||||
if [ "$DEP_VENV" = false ]; then
|
||||
echo "Error: venv not installed"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Make install directory
|
||||
echo "Creating install directory..."
|
||||
if [ ! -d "$INSTALLDIR" ]; then
|
||||
mkdir -p "$INSTALLDIR"
|
||||
fi
|
||||
|
||||
# Copy files to install directory
|
||||
echo "Copying files to install directory..."
|
||||
for file in $FILES2COPY; do
|
||||
cp "$file" "${INSTALLDIR}/"
|
||||
done
|
||||
|
||||
cd "$INSTALLDIR"
|
||||
|
||||
# Create and activate venv if needed
|
||||
echo "Creating and activating venv..."
|
||||
if [ ! -d "$ENVDIR" ]; then
|
||||
python3 -m venv "$ENVDIR"
|
||||
fi
|
||||
source "$ENVDIR/bin/activate"
|
||||
|
||||
# Install Deps
|
||||
echo "Installing Dependencies..."
|
||||
for dep in $DEPENDENCIES; do
|
||||
pip install "$dep"
|
||||
done
|
||||
|
||||
# deactivate venv
|
||||
echo "Deactivating venv..."
|
||||
deactivate
|
||||
|
||||
if [ ! -d "$BINDIR" ]; then
|
||||
echo "Creating ~/.local/bin to hold launch script..."
|
||||
mkdir -p "$BINDIR"
|
||||
fi
|
||||
|
||||
# Setup launch script
|
||||
echo "Creating launch script..."
|
||||
cat <<EOF > "$BINDIR/refresh_subdomain"
|
||||
#!/bin/bash
|
||||
cd "$INSTALLDIR"
|
||||
source "$ENVDIR/bin/activate"
|
||||
python3 "$PYSCRIPT" \$@"
|
||||
EOF
|
||||
|
||||
chmod +x "$BINDIR/refresh_subdomain"
|
||||
|
||||
# Setup systemd service
|
||||
if [ ! -d "$SYSTEMDDIR" ]; then
|
||||
echo "Creating systemd user service directory..."
|
||||
mkdir -p "$SYSTEMDDIR"
|
||||
fi
|
||||
|
||||
echo "Creating systemd user service..."
|
||||
cat <<EOF > $SYSTEMDDIR/subdomain.service
|
||||
/refresh_subdomain.service
|
||||
[Unit]
|
||||
Description=Refresh Subdomain Service
|
||||
|
||||
[Service]
|
||||
ExecStart=$BINDIR/refresh_subdomain
|
||||
EOF
|
||||
|
||||
echo "Creating systemd user timer..."
|
||||
cat <<EOF > $SYSTEMDDIR/subdomain.timer
|
||||
[Unit]
|
||||
Description=Refresh Subdomain Timer
|
||||
|
||||
[Timer]
|
||||
OnCalendar=hourly
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
EOF
|
||||
|
||||
echo "Enabling systemd service..."
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable subdomain.timer
|
||||
|
||||
echo "Installation Complete"
|
||||
20
distro_client/prep_distro.sh
Normal file
20
distro_client/prep_distro.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Creates a tar.gz of the subdomain client files
|
||||
|
||||
rm -f subdomain_client.tar.gz
|
||||
rm -rf tmp
|
||||
mkdir tmp
|
||||
cp -a ./install_subdomain_client.sh tmp/
|
||||
cp -a ../src/bpe_subdomain_server/refresh_subdomain.py tmp/
|
||||
|
||||
cd tmp
|
||||
|
||||
chmod +x install_subdomain_client.sh
|
||||
|
||||
tar -zcvf ../subdomain_client.tar.gz install_subdomain_client.sh refresh_subdomain.py
|
||||
|
||||
cd ..
|
||||
rm -rf tmp
|
||||
|
||||
echo "Created subdomain_client.tar.gz"
|
||||
Reference in New Issue
Block a user