#!/bin/bash set -x set -e source scripts/config.sh || exit 1 SITE_FOLDER="dist" function dependency_check { if ! command -v $@ &> /dev/null; then echo "dependency error: $@ could not be found" exit 1 fi } # Check dependencies dependency_check png2ico dependency_check convert dependency_check exiftool dependency_check optipng dependency_check jpegoptim npm run build cp -r ./scripts/ dist/scripts/ # Git repo setup mkdir -p "$SITE_FOLDER/repos" cp -r "$SITE_FOLDER/dotfiles/.git" "$SITE_FOLDER/repos/dotfiles.git" pushd "$SITE_FOLDER/repos/dotfiles.git" git update-server-info popd # Render ico file convert "$SITE_FOLDER/img/me.jpg" -resize 64x64 "$SITE_FOLDER/img/profile_image.jpg" convert "$SITE_FOLDER/img/me.jpg" -resize 64x64 "$SITE_FOLDER/img/profile_image.png" png2ico "$SITE_FOLDER/favicon.ico" "$SITE_FOLDER/img/profile_image.png" || { echo 'error: failed to make .ico image' } # Clear configuration info sed -ie "s/$S3_BUCKET/s3-bucket-name/g" "$SITE_FOLDER/scripts/config.sh" sed -ie "s/$DISTRIBUTION_ID/cloudfront-distribution-id/g" "$SITE_FOLDER/scripts/config.sh" # Alias files to folder/index.html find "$SITE_FOLDER" -type f ! -iname 'index.html' -iname '*.html' -print0 | while read -d $'\0' f; do mkdir -p "${f%.html}" cp "$f" "${f%.html}/index.html" done mkdir -p .cache # Find all images find "$SITE_FOLDER" -type f \( \ -iname "*.jpg" \ -o -iname "*.jpeg" \ -o -iname "*.png" \ -o -iname "*.gif" \ -o -iname "*.tiff" \ \) -print0 | while read -d $'\0' f; do # Compute names + caches HASH="$(shasum -a 256 $f | cut -d' ' -f1)" SOURCE_FILENAME="$f" CANONICAL_NAME="$(echo $SOURCE_FILENAME | tr "[:lower:]" "[:upper:]")" CACHED_FILENAME=".cache/$HASH" if [[ ! -f "$CACHED_FILENAME" ]]; then cp "$f" "$CACHED_FILENAME" # EXIF metadata stripping if [[ "$CANONICAL_NAME" == *.JPG || "$CANONICAL_NAME" == *.JPEG || "$CANONICAL_NAME" == *.PNG || "$CANONICAL_NAME" == *.GIF || "$CANONICAL_NAME" == *.TIFF ]]; then echo "stripping tags..." exiftool -overwrite_original -all= -tagsfromfile @ -Orientation "$CACHED_FILENAME" || exit 1 fi # PNG optmization if [[ "$CANONICAL_NAME" == *.PNG ]]; then echo "optipng..." optipng "$CACHED_FILENAME" || exit 1 fi # JPG optimization if [[ "$CANONICAL_NAME" == *.JPG || "$CANONICAL_NAME" == *.JPEG ]]; then echo "jpegoptim..." jpegoptim --size=200k "$CACHED_FILENAME" || exit 1 fi fi # Copy out cp "$CACHED_FILENAME" "$SOURCE_FILENAME" || exit 1 done