How to Automatically Update Sendy (example with Bluehost)

  1. Download the newest version of Sendy (zipped)
  2. Upload the sendy-*.zip file to the ~/ or $HOME
  3. Create the script file (your_script.sh):
#!/bin/bash
set -e
# Stop the script if any command fails

# PLEASE upload the new Sendy ZIP file to the root/home directory (~/ or $HOME)
# PLEASE set your existing Sendy folder path
sendy="$HOME/public_html/EXISTING"
# PLEASE set the path for the temporary Sendy folder
tsendy="$HOME/public_html/TEMPORARY"

# Check if $tsendy exists and prompt for deletion if it does
if [ -d "$tsendy" ]; then
  read -p "$tsendy exists. Do you want to delete it? [Y/n]: " del_answer
  del_answer=$(echo "$del_answer" | tr '[:upper:]' '[:lower:]')
  if [[ "$del_answer" == "y" || "$del_answer" == "yes" ]]; then
    rm -r "$tsendy"
    echo "Deleted $tsendy"
  else
    echo "Exiting. Please remove $tsendy manually."
    exit 1
  fi
fi

# Create the temporary Sendy directory if it doesn't already exist
mkdir -p "$tsendy"

# Unzip the new Sendy installation into the temporary directory
unzip "$HOME/sendy*.zip" -d "$tsendy"
mv "$tsendy/sendy/"* "$tsendy/"
rm -r "$tsendy/sendy/"

# Confirmation message
echo "Successfully unzipped new Sendy installation."

# Copy the existing config.php to the new installation
cp "$sendy/includes/config.php" "$tsendy/includes/"

# Confirmation message
echo "Successfully copied config.php to new installation."

# Copy the existing 'uploads' folder to the new installation
cp -R "$sendy/uploads" "$tsendy/"

# Confirmation message
echo "Successfully copied 'uploads' folder to new installation."

# Copy the existing .htaccess file to the new installation
cp "$sendy/.htaccess" "$tsendy/"

# Confirmation message
echo "Successfully copied .htaccess to new installation."

# Archive the existing installation folder
tar czvf "$HOME/sendy.tar.gz" "$sendy"

# Confirmation message
echo "Successfully archived the old installation."

# Remove the old installation folder
rm -r "$sendy"

# Confirmation message
echo "Successfully removed the old installation."

# Rename the new installation folder to match the old installation folder's name
mv "$tsendy" "$sendy"

# Confirmation message
echo "Successfully created the new installation."

# Prompt user to delete the Sendy installation file
read -p "Do you want to delete the Installation ZIP file? [Y/n]: " answer
answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]')
if [[ "$answer" == "y" || "$answer" == "yes" ]]; then
    find $HOME -maxdepth 1 -name 'sendy*.zip' -print0 | xargs -0 rm --
    echo "Successfully removed the Installation ZIP file."
else
    echo "Kept the Installation ZIP file."
fi
# Prompt user to delete the backup ZIP file
read -p "Do you want to delete the backup GZ file? [Y/n]: " answer
answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]')
if [[ "$answer" == "y" || "$answer" == "yes" ]]; then
    rm "$HOME/sendy.tar.gz"
    echo "Successfully removed the backup GZ file."
else
    echo "Kept the backup GZ file."
fi
  1. Make your script executable:
    chmod +x ./sendy.sh
  2. Eliminate the Windows EOLs (if your script won’t run):
    a) vi your_script.sh or vim your_script.sh
    b) once inside the editor, type : to go into command mode
    c) set ff=unix
    d) :wq