Commit d11b6ce7 authored by King Alex's avatar King Alex

Upload New File

parent b3e7df77
#!/bin/bash
# Script location ex:
# /mnt/c/Users/kinga/OneDrive/Desktop/Script/GallerieImagesHTTP.sh
# First time:
# - Drag script in folder containing images.
# - Run the script
# - Let the script organise your images
# - Enjoy the new Index.html file.
# Updating images:
# - Drop images in deposit folder.
# - Run the script.
# GALLERY:
TITLE="Image Gallery"
STYLE="style.css"
# Path of the folder containing the script:
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Define 3 folders
DEPOSIT=$DIR"/deposit"
IMAGES=$DIR"/images"
THUMBNAILS=$DIR"/thumbnails"
# Create 3 folders if they don't exist.
if [ ! -d $DEPOSIT ]; then
mkdir -p $DEPOSIT;
fi
if [ ! -d $IMAGES ]; then
mkdir -p $IMAGES;
fi
if [ ! -d $THUMBNAILS ]; then
mkdir -p $THUMBNAILS;
fi
# Move original images to Deposit folder.
find $DIR -maxdepth 1 -type f \( -name "*.png" -o -name "*.gif" -o -name "*.jpg" \) -exec mv {} $DEPOSIT \;
# Number of images in original image and destination files:
ORIGIN=$(find $DEPOSIT -maxdepth 1 -type f \( -name "*.png" -o -name "*.gif" -o -name "*.jpg" \) | wc -l);
DESTINATION=$(find $IMAGES -maxdepth 1 -type f \( -name "*.png" -o -name "*.gif" -o -name "*.jpg" \) | wc -l);
# Compare origin to destination files if update is needed.
echo "Comparing files..."
COUNT=0
for depo in $DEPOSIT/*; do
for img in $IMAGES/*; do
if [[ $(basename $depo) == $(basename $img) ]]
then
((COUNT++))
fi
done
done
(( ($COUNT == $ORIGIN) && ($COUNT == $DESTINATION)))
EQUALFILES=$?
# If files are not the same, back them up.
case $EQUALFILES in
0) echo "Files are up to date, no further action is required."
;;
1) echo "Updating files..."
# Copy original files to destination folder
find $DEPOSIT -maxdepth 1 -type f \( -name "*.png" -o -name "*.gif" -o -name "*.jpg" \) -exec cp {} $IMAGES \;
find $DEPOSIT -maxdepth 1 -type f \( -name "*.png" -o -name "*.gif" -o -name "*.jpg" \) -exec cp {} $THUMBNAILS \;
echo "Update complete."
# Make thumbnails of images.
for thumbnail in $THUMBNAILS/*; do
convert -resize 400x $thumbnail $thumbnail
done
;;
esac
if [ ! -e $DIR"/index.html" ]
then
echo "Gallery (index.html) does not exist..."
UPDATE="Y"
else
read -t 10 -p "Gallery exists, do you want to update it? [Y/N]" UPDATE
UPDATE=${UPDATE:-Y}
fi
case $UPDATE in
Y)
echo "Creating html..."
# Create html
echo "<html>">$DIR"/index.html"
echo "<head>">>$DIR"/index.html"
echo '<title>'$TITLE'</title>'>>$DIR"/index.html"
echo '<link rel="stylesheet" type="text/css" href="'$STYLE'">'>>$DIR"/index.html"
echo '<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">'>>$DIR"/index.html"
echo "</head>">>$DIR"/index.html"
echo "<body>">>$DIR"/index.html"
echo '<div class="container">'>>$DIR"/index.html"
echo '<div class="title"><h1>Gallerie</h1></div>'>>$DIR"/index.html"
for thumbnail in $THUMBNAILS/*; do
echo '<a href="images/'$(basename $thumbnail)'">'>>$DIR"/index.html"
IMG='<img src="thumbnails/'$(basename $thumbnail)'"/>'
echo $IMG>>$DIR"/index.html"
echo "</a>">>$DIR"/index.html"
done
echo '</div>'>>$DIR"/index.html"
echo '<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>'>>$DIR"/index.html"
echo "</body>">>$DIR"/index.html"
echo "</html>">>$DIR"/index.html"
echo "Complete"
;;
*) # Do not create html
echo "Complete"
;;
esac
read -t 10 -p "Create archive? (yes by default) [Y/N]" ARCHIVE
ARCHIVE=${ARCHIVE:-Y}
case $ARCHIVE in
Y)
echo "Creating archive..."
DATE=`date +%d-%m-%Y_%H-%M-%S`
tar -czvf vignettes-$DATE.tgz index.html images thumbnails
echo "Complete"
echo "Clearing up.."
rm -r $DIR"/images"
rm -r $DIR"/thumbnails"
rm $DIR"/index.html"
echo "Done"
;;
*)
echo "Complete"
;;
esac
exit 0
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment