#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: https://mirrors.slickstack.io/bash/ss-optimize-files.txt ############################## #### path: /var/www/ss-optimize-files ############################################################## #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Converts any DOS files in the SlickStack directory tree to Unix file format ########## #### module version: Ubuntu 22.04 LTS ############################################################## #### sourced by: ss core cron jobs, ss-update ###################################################### #### bash aliases: ss dos2unix, ss dos2unix files ################################################## #################################################################################################### ## source ss-config ## source /var/www/ss-config ## source ss-functions ## source /var/www/ss-functions ## BELOW THIS RELIES ON SS-CONFIG AND SS-FUNCTIONS #################################################################################################### #### TABLE OF CONTENTS (SS-Optimize-Files) ######################################################### #################################################################################################### ## this is a brief summary of the different code snippets you will find in this script ## ## each section should be commented so you understand what is being accomplished ## ## A. Touch Timestamp File ## B. Message (Begin Script) #################################################################################################### #### A. SS-Optimize-Files: Touch Timestamp File #################################################### #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ## script timestamp ## ss_touch "${TIMESTAMP_SS_OPTIMIZE_FILES}" #################################################################################################### #### B. SS-Optimize-Files: Message (Begin Script) ################################################## #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be noticed by sudo users who manually call ss core bash scripts ## ## echo message ## ss_echo "${COLOR_INFO}Running ss-optimize-files... ${COLOR_RESET}" #################################################################################################### #### SS-DOS2Unix-Files: Install Ubuntu Package If Not Exists (dos2unix) ############################ #################################################################################################### ## here is a brief script to install dos2unix package if does not exist already on server ## ## this approach ensures this bash script is completely self-contained to function ## PACKAGE_DOS2UNIX_EXISTS=$(dpkg-query -W --showformat='${Status}\n' $PACKAGE_DOS2UNIX|grep "install ok installed") echo Checking for $PACKAGE_DOS2UNIX: $PACKAGE_DOS2UNIX_EXISTS if [ "" = "$PACKAGE_DOS2UNIX_EXISTS" ]; then echo "$PACKAGE_DOS2UNIX package not found. We will install the package before proceeding." sudo apt install "$PACKAGE_DOS2UNIX" fi #################################################################################################### #### SS-DOS2Unix-Files: Convert DOS Files To Unix Files ############################################ #################################################################################################### ## this utility will search the SlickStack directories for any DOS files and conver them ## ## avoiding DOS formats (e.g. janky line breaks) helps ensure file compatibility ## find /var/www/html/ -type f -exec dos2unix --quiet --keepdate --oldfile --safe {} \; #################################################################################################### #### SS-Optimize-Files: Strip All EXIF Metadata #################################################### #################################################################################################### ## for better file and image security run exiftool to remove any EXIF data from files ## ## this helps prevent people from seeing things like GPS location and etc ## PACKAGE_EXIFTOOL_EXISTS=$(dpkg-query -W --showformat='${Status}\n' $PACKAGE_EXIFTOOL|grep "install ok installed") echo Checking for $PACKAGE_EXIFTOOL: $PACKAGE_EXIFTOOL_EXISTS if [ "" = "$PACKAGE_EXIFTOOL_EXISTS" ]; then echo "$PACKAGE_EXIFTOOL package not found. We will install the package before proceeding." sudo apt install "$PACKAGE_EXIFTOOL" fi exiftool -recurse -overwrite_original -EXIF= -ext jpg,jpeg /var/www/html #################################################################################################### #### PLACEHOLDER: Reset Permissions (SlickStack Scripts) ########################################### #################################################################################################### ## we include this permissions reset in all cron jobs and bash scripts for redundancy ## ## chmod 0700 means only the root/sudo users can execute any SlickStack scripts ## ## THIS SNIPPET DOES NOT RELY ON SS-CONFIG OR SS-FUNCTIONS ## SNIPPET: ss bash scripts, ss cron jobs ## UPDATED: 02JUL2022 chown root:root /var/www/ss* ## must be root:root chown root:root /var/www/crons/*cron* ## must be root:root chown root:root /var/www/crons/custom/*cron* ## must be root:root chmod 0700 /var/www/ss* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/*cron* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/custom/*cron* ## 0700 means only root/sudo can execute #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://askubuntu.com/questions/319307/reliably-check-if-a-package-is-installed-or-not ## Ref: https://stackoverflow.com/questions/1298066/check-if-an-apt-get-package-is-installed-and-then-install-it-if-its-not-on-linu ## Ref: https://www.computerhope.com/unix/dos2unix.htm ## Ref: https://linuxnightly.com/how-to-remove-exif-data-via-linux-command-line/ ## Ref: https://stackoverflow.com/questions/2654281/how-to-remove-exif-data-without-recompressing-the-jpeg ## SS_EOF