-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathss-optimize-files.txt
132 lines (100 loc) · 7.6 KB
/
ss-optimize-files.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
####################################################################################################
#### author: SlickStack ############################################################################
#### link: https://slickstack.io ###################################################################
#### mirror: littlebizzy/slickstack/blob/master/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 24.04 LTS ##############################################################
#### sourced by: ###########################################################
#### bash aliases: ss optimize files ###############################################################
####################################################################################################
####################################################################################################
#### 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. Source SS-Config + SS-Functions
## B. Touch Timestamp File
## C. Message (Begin Script)
## D. Install Dos2Unix Package If Not Exists
## E. Convert Any DOS Files To Unix Files
## F. Strip Any EXIF Metadata
####################################################################################################
#### A. SS-Optimize-Files: Source SS-Config + SS-Functions #########################################
####################################################################################################
## before anything else we must source the critical variables that power this script ##
## ss-config is setup during ss-install wizard but ss-functions is hardcoded ##
## 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
####################################################################################################
#### B. 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 ##
ss_touch "${TIMESTAMP_SS_OPTIMIZE_FILES}"
####################################################################################################
#### C. 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 seen by sudo users who manually run this script in the shell ##
ss_echo "${COLOR_INFO}Running ss-optimize-files... ${COLOR_RESET}"
####################################################################################################
#### D. SS-Optimize-Files: Install Dos2Unix Package If Not Exists ##################################
####################################################################################################
## 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
ss_echo "${PACKAGE_DOS2UNIX} package not found. We will install the package before proceeding."
ss_apt_install "${PACKAGE_DOS2UNIX}"
fi
####################################################################################################
#### E. SS-Optimize-Files: Convert Any 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 {} \;
####################################################################################################
#### F. SS-Optimize-Files: Strip Any 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."
ss_apt_install "$PACKAGE_EXIFTOOL"
fi
## disabling this due to reports of CPU hanging ##
## looking into mat2 and exiv2 instead ##
## https://slickstack.io/forum/topic/exiftool-high-cpu-spikes-and-sometimes-hangs-in-slickstack
# exiftool -recurse -overwrite_original -EXIF= -ext jpg,jpeg /var/www/html
####################################################################################################
#### SlickStack: 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