Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View mirror-images.sh
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
#!/bin/bash
 
# This script creates symbolic links of english images on the arabic images folder
# Just make sure the specific language image in english have the same name in arabic
# any other image in english will be symblinked on the arabic folder to avoid duplication
# When it comes to generate a sprite using Compass,
# There is a limitation of using a single asset type load path at a time
# which means, using Compass you cannot generate a single sprite from two different paths unless
# your folders are nested then it's one path using two folders.
 
# Created by Hichem ben chaabene on 28/7/2013
 
#main variables
imagesDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )""/../static/images/"
rtlDirectory="rtl"
ltrDirectory="ltr"
rtlPath="standard/$rtlDirectory"
ltrPath="standard/$ltrDirectory"
 
# Functions
#******************************************************
 
deleteAllsymblinks(){
cd "$imagesDirectory"
#find all symbolic links and delete them to make sure its up to date
find . -type l -name "*.png" -exec rm -f {} \;
}
 
createSymblinks(){
echo "Deleting old symblinks and creating new ones..."
#function call
deleteAllsymblinks
#function call
cd "$imagesDirectory"
 
# Loop threw all folders but still looking for a better option
for i in *; do
#if it's a directory (not . and not ..)
if [ -d "$i" ]; then
#acessing the folder
cd $i
# Security check against the folder, if the folder doesn't have rtl/ ltr/
# it means the logic doesn't apply any more, skip that
if [ -d $ltrPath ]; then
cd "$ltrPath"
# Extension control protects against wrong manipulation
# like symblinking other extensions in case the developer
# forgot to put .png images
# if he do that sprites will not work
for k in `ls`; do
if [ "${k##*.}" = "png" ]; then
# now you have to check if the filenames are same
# if they are not the same or the file doesn't exist in the other folder
# then create a symblink
 
#check if the file has no equivalent in arbic folder
#if not then we should have a symbolic link
if [ -f ../rtl/$k ]; then
#image has the same name, tell the user to verify if it's suppose to be the arabic one
#in that case it's fine
echo "Please make sure this image is arabic specific $i/ltr/$k"
echo "This script is linking only shared images, arabic specific images should have the same name as in english"
else
#create symbolic link for this imaeg on the rtl folder
ln -s ../ltr/"$k" ../rtl/$k
fi
fi
done
cd ../../../
else
echo "The folder $i doesn't have rtl / ltr structure , skipping ..."
cd ..
fi
fi
# help to loop again threw the folders from the images path
done
# everything is done
echo "Done, Yalla dude go ahead with sprites now..."
}
 
welcome(){
#clear the screen
clear
echo "***********************************************************"
echo "Creating symbolic links for ltr images in rtl folders "
echo "***********************************************************"
}
 
# SCRIPT MAIN
#------------------------------------------------#
welcome
createSymblinks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.