Advertisement
nielstron

Support of @2x and @3x BootLogos

Jun 19th, 2015
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.40 KB | None | 0 0
  1. #!/bin/bash
  2. #Script for automatically making use of the right logo version, according to the iDevices screen resolution
  3. #You may use this script in your own package but please don't remove this comment
  4. #this script was written by Niels Muendler (nielstron)
  5.  
  6. #the screen scale (ie 1 for normal screens, 2 for @2x and 3 for @3x) is read from gsc.main-screen-scale
  7. model=$(dpkg -s gsc.main-screen-scale | grep -i -e "Version" | cut -b 10- )
  8.  
  9.     #the following is made functions because... well I hope that it's improving readability
  10.     function mvall2x () {
  11.     #rename all @2x versions to normal versions
  12.         for j in $(seq 0 $count)
  13.         do
  14.             #but only if the files really exists (it double checks here, don't want to loose any important files )
  15.             if test -e "$j@2x.png"
  16.             then
  17.                 mv -v -f "$j@2x.png" "$j.png"
  18.             fi
  19.         done
  20.     }
  21.     function mvall3x () {
  22.     #rename all @3x versions to normal versions
  23.     for j in $(seq 0 $count)
  24.     do
  25.         #but only if the files really exists (it double checks here, don't want to loose any important files and yes I DID copy pasta here)
  26.         if test -e "$j@3x.png"
  27.             then
  28.                 mv -v -f "$j@3x.png" "$j.png"
  29.         #if there's no @3x version just use the @2x version
  30.         elif test -e "$j@2x.png"
  31.             then
  32.                 mv -v -f "$j@2x.png" "$j.png"
  33.         fi
  34.     done
  35.     }
  36.  
  37. #if the end device isn't anything exit with error status
  38. if test -z $model
  39. then
  40.     exit 1
  41. fi
  42.  
  43. #Go to the Boot Logo home dir
  44. cd /Library/BootLogos/
  45. #read all folders and send them to the while loop
  46. #run the following for each folder in this dir
  47. ls --hide="*.*" ./ | while read dir
  48. do
  49.     #enter the dir
  50.     cd "/Library/BootLogos/$dir"
  51.     #read the amount of logos in this dir and save it to $count
  52.     i="0"
  53.     count="0"
  54.     while test -e "$i.png"
  55.     do
  56.         count="$i"
  57.         i=$(expr $i + 1)
  58.     done
  59.    
  60.     #if the screen scale is 1
  61.     if test $model = "1"
  62.     then
  63.         #do nothing
  64.         echo ""
  65.     #if the screen scale is 2
  66.     elif test $model = "2"
  67.     then
  68.         #use @2x logos
  69.         mvall2x
  70.     #for future compatibility reasons do this for every other screen scale (>= 3)
  71.     else
  72.         #use @3x logos
  73.         mvall3x
  74.     fi
  75.    
  76.    
  77.     #remove all remaining @2x and @3x logos to save disk space (there are no @2x logos left on generation 4 to 6 and no @3x logos left on the 6+)
  78.     # note: this actually removes everything but the logos 0.png-n.png
  79.     #do so by reading all files except 0.png-n.png and send them to the while loop
  80.     ls ./ | grep -v -i "[0-9].png") | while read k
  81.     do
  82.         rm -f "$k"
  83.     done
  84. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement