Guest User

install_komic.ffs

a guest
Feb 3rd, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.64 KB | None | 0 0
  1. #!/bin/sh
  2. OTA=com.lab126.blanket.ota
  3. LOG=/mnt/us/Komic_update_log.txt
  4. LOCALSTORAGE=/mnt/us/extensions/komic/bin/resource/LocalStorage/file__0.localstorage
  5. GALLERY="/mnt/us/documents/Komic"
  6. OLDGALLERY="/mnt/us/documents/Gallery"
  7. KOMIC="/mnt/us/extensions/komic"
  8. UPSTART="/etc/upstart/komic_event_handler.conf"
  9.  
  10. progress()
  11. {
  12.     lipc-send-event $OTA otaSplashProgress -i $1
  13.     local x=48
  14.     local y=11
  15.     eips 0 $y "                                                ";
  16.     eips $((($x - $(expr length "$2")) / 2)) $y "$2"
  17.     sleep 3
  18. }
  19.  
  20. fail()
  21. {
  22.     lipc-send-event $OTA otaSplashError -s "${1}"
  23.     sleep 10
  24.     exit 1;
  25. }
  26.  
  27. progress 25 "Checking if Komic is installed"
  28. varkomic=$(sqlite3 /var/local/appreg.db "select handlerId from handlerIds where handlerId='com.silver18.komic001'")
  29. varmemory=$(sqlite3 /var/local/appreg.db "select handlerId from properties where handlerId='com.silver18.komic001' and name='memUnloadLevel'")
  30. mesquite=$(sqlite3 /var/local/appreg.db "select value from properties where handlerId='com.silver18.komic001' and name='command'" | grep mesquite)
  31. varbaseus=$(sqlite3 /var/local/appreg.db "select value from properties where handlerId='com.silver18.komic001' and name='command'" | grep base)
  32.  
  33. if [[ -n "$varkomic" ]]
  34. then
  35.     echo "Komic is already installed" >> $LOG
  36.     komicinstalled=1
  37.    
  38.     if [[ -z "$mesquite" ]]
  39.     then
  40.         echo "Komic is not yet updated to mesquite" >> $LOG
  41.         sqlite3 /var/local/appreg.db "delete from properties where handlerId='com.silver18.komic001' and name='command'"
  42.         sqlite3 /var/local/appreg.db "INSERT INTO properties (handlerId, name, value) VALUES ('com.silver18.komic001','command','/usr/bin/mesquite -l com.silver18.komic001 -c /mnt/us/extensions/komic/bin/')"
  43.     else
  44.         echo "Komic is already updated to mesquite" >> $LOG
  45.         if [[ ! -z "$varbaseus" ]]
  46.         then
  47.             echo "Moving installation folder to /mnt/us" >> $LOG
  48.             sqlite3 /var/local/appreg.db "delete from properties where handlerId='com.silver18.komic001' and name='command'"
  49.             sqlite3 /var/local/appreg.db "INSERT INTO properties (handlerId, name, value) VALUES ('com.silver18.komic001','command','/usr/bin/mesquite -l com.silver18.komic001 -c /mnt/us/extensions/komic/bin/')"
  50.         fi
  51.     fi
  52.    
  53.     if [ -d "$KOMIC" ]
  54.     then
  55.         echo "Komic folder present" >> $LOG
  56.         komicpresent=1
  57.     else
  58.         echo "Komic folder not present" >> $LOG
  59.     fi
  60.  
  61. else
  62.  
  63.     echo "Komic is not yet installed" >> $LOG
  64.     sqlite3 /var/local/appreg.db "INSERT INTO handlerIds VALUES ('com.silver18.komic001')"
  65.     sqlite3 /var/local/appreg.db "INSERT INTO properties (handlerId, name, value) VALUES ('com.silver18.komic001','command','/usr/bin/mesquite -l com.silver18.komic001 -c /mnt/us/extensions/komic/bin/')"
  66.     sqlite3 /var/local/appreg.db "INSERT INTO properties (handlerId, name, value) VALUES ('com.silver18.komic001','unloadPolicy','unloadOnPause')"
  67.    
  68. fi
  69.  
  70. if [[ -n "$varmemory" ]]
  71. then
  72.     echo "Bigger memory space already present" >> $LOG
  73. else
  74.     echo "Bigger memory space not present" >> $LOG
  75.     sqlite3 /var/local/appreg.db "INSERT INTO properties (handlerId, name, value) VALUES ('com.silver18.komic001','memUnloadLevel','150000')"
  76.     sqlite3 /var/local/appreg.db "INSERT INTO properties (handlerId, name, value) VALUES ('com.silver18.komic001','memWarnLevel','71680')"
  77. fi     
  78.  
  79. progress 50 "Copying Komic"
  80. echo "--------------------------------" >> $LOG
  81. if [[ -n "$komicinstalled" ]]
  82. then
  83.     echo "Updating Komic and managing file__0.localstorage" >> $LOG
  84.    
  85.     if [[ -n "$komicpresent" ]]
  86.     then
  87.         echo "Removing old Komic and unzipping new Komic" >> $LOG
  88.         rm -rf $KOMIC || fail "Unable to delete Komic folder"
  89.         unzip komic.zip -d /mnt/us/extensions/ || fail "Unable to unzip Komic"
  90.     else
  91.         echo "Unzipping new Komic" >> $LOG
  92.         unzip komic.zip -d /mnt/us/extensions/ || fail "Unable to unzip Komic"
  93.     fi
  94.    
  95.     if [[ -n "$localstoragepresent" ]]
  96.     then
  97.         echo "Restoring old file__0.localstorage" >> $LOG
  98.         mv /mnt/us/file__0.localstorage $LOCALSTORAGE || fail "Unable to replace old file__0.localstorage"
  99.         rm -f /mnt/us/file__0.localstorage || fail "Unable to delete old file__0.localstorage"
  100.     else
  101.         echo "Placing new file__0.localstorage" >> $LOG
  102.         mv file__0.localstorage $LOCALSTORAGE || fail "Unable to place new file__0.localstorage"
  103.     fi
  104.    
  105.     echo "Updating upstart script" >> $LOG
  106.     rm -rf $UPSTART || fail "Unable to delete upstart script"
  107.     mv komic_event_handler.conf $UPSTART || fail "Unable to place upstart script"
  108.    
  109.     sqlite3 /mnt/us/extensions/komic/bin/resource/LocalStorage/file__0.localstorage "INSERT INTO ItemTable (key, value) VALUES ('komicStatus', 'updated')"
  110.    
  111. else
  112.  
  113.     echo "Installing Komic, placing plain file__0.localstorage and upstart script" >> $LOG
  114.     unzip -o komic.zip -d /mnt/us/extensions/ || fail "Unable to unzip Komic"
  115.     mv file__0.localstorage $LOCALSTORAGE || fail "Unable to place new file__0.localstorage"
  116.     mv komic_event_handler.conf $UPSTART || fail "Unable to place upstart script"
  117.    
  118.     sqlite3 /mnt/us/extensions/komic/bin/resource/LocalStorage/file__0.localstorage "INSERT INTO ItemTable (key, value) VALUES ('komicStatus', 'firstRun')"
  119.    
  120. fi
  121.  
  122. progress 75 "Creating Komic documents folder"
  123. if [ -d "$OLDGALLERY" ]
  124. then
  125.     echo "Old Komic documents folder present, renaming it" >> $LOG
  126.     mv $OLDGALLERY $GALLERY
  127.     GALLERY="/mnt/us/documents/Komic"
  128. fi
  129. if [ -d "$GALLERY" ]
  130. then
  131.     echo "Komic documents folder present" >> $LOG
  132.     unzip -o =README=.zip -d $GALLERY/ || fail "Unable to unzip README"
  133. else
  134.     echo "Creating Komic documents folder" >> $LOG
  135.     mkdir -p $GALLERY
  136.     unzip -o =README=.zip -d $GALLERY/ || fail "Unable to unzip README"
  137. fi
  138.  
  139. progress 100 "Installation complete."
  140. echo "Installation complete" >> $LOG
  141. mv $LOG /mnt/us/extensions/komic/bin/resource/Logs/Komic_update_log.txt
Add Comment
Please, Sign In to add comment