Advertisement
zefie

osupack.sh

May 18th, 2018
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.45 KB | None | 0 0
  1. #!/bin/bash
  2. IFS=$'\n'
  3. OSUROOT="/mnt/f/Games/osu!"
  4. DESTROOT="/mnt/z/Backups/Games/osu"
  5.  
  6. function packArchive() {
  7.     Z_ACT="${1}"
  8.     Z_FILE="${2}"
  9.     shift 2
  10.     "7za" "${Z_ACT}" -scrcCRC32 -stl -tzip -mx=9 -mtc=off -mcu=on "${Z_FILE}" "${@}" 2>/dev/null > /dev/null
  11.     if [ $? -ne 0 ] && [ "${1}" == "u" ]; then
  12.         echo "Update failed, re-creating..."
  13.         rm -rf "${2}"
  14.         echo "Creating $(echo ${2} | rev | cut -d'/' -f1 | rev)"
  15.         packArchive "a" "${2}" "${3}"
  16.     fi
  17. }
  18.  
  19.  
  20. function packSkins() {
  21.     cd "${OSUROOT}/Skins"
  22.     if [ ! -d "${DESTROOT}/Skins" ]; then
  23.         mkdir "${DESTROOT}/Skins";
  24.     fi
  25.     for f in $(ls -1); do
  26.         case "${f}" in
  27.             "User")
  28.                 continue
  29.                 ;;
  30.         esac
  31.         if [ -d "${f}" ]; then
  32.             NEWDIR="${OSUROOT}/Skins/${f}"
  33.             cd -- "${NEWDIR}"
  34.             OUTFILE=$(echo "${f}" | sed 's/%/\_/g;s/[+]/ /g;s/[|]/\_/g')
  35.             FULLOUT="${DESTROOT}/Skins/${OUTFILE}.osk"
  36.             if [ -f "${FULLOUT}" ]; then
  37.                 VERB="Updating"
  38.                 Z7ACT="u"
  39.             else
  40.                 VERB="Creating"
  41.                 Z7ACT="a"
  42.             fi
  43.             echo "${VERB} ${OUTFILE}.osk"
  44.             packArchive "${Z7ACT}" "${FULLOUT}" "."
  45.             cd ..
  46.         fi
  47.     done
  48. }
  49.  
  50. function packData() {
  51.     cd "${OSUROOT}/Data"
  52.     if [ ! -d "${DESTROOT}/Data" ]; then
  53.         mkdir "${DESTROOT}/Data";
  54.     fi
  55.     for f in $(ls -1); do
  56.         case "${f}" in
  57.             "SubmissionCache")
  58.                 continue
  59.                 ;;
  60.         esac
  61.         if [ -d "${f}" ]; then
  62.             NEWDIR="${OSUROOT}/Data/${f}"
  63.             cd -- "${NEWDIR}"
  64.             OUTFILE=$(echo "${f}" | sed 's/%/\_/g;s/[+]/ /g;s/[|]/\_/g')
  65.             FULLOUT="${DESTROOT}/Data/${OUTFILE}.zip"
  66.             if [ -f "${FULLOUT}" ]; then
  67.                 VERB="Updating"
  68.                 Z7ACT="u"
  69.             else
  70.                 VERB="Creating"
  71.                 Z7ACT="a"
  72.             fi
  73.             echo "${VERB} ${OUTFILE}.zip"
  74.             packArchive "${Z7ACT}" "${FULLOUT}" "."
  75.             cd ..
  76.         fi
  77.     done
  78. }
  79.  
  80. function packClient() {
  81.     cd "${OSUROOT}"
  82.     if [ ! -d "${DESTROOT}" ]; then
  83.         mkdir "${DESTROOT}";
  84.     fi
  85.     NEWPACK=()
  86.     for f in $(ls -1); do
  87.         case "${f}" in
  88.             "Data"|"Logs"|"Skins"|"Songs"|"sync.ffs_db")
  89.                 continue
  90.                 ;;
  91.         esac
  92.         NEWPACK+=("${f}")
  93.     done
  94.  
  95.     NEWDIR="${OSUROOT}"
  96.     cd -- "${NEWDIR}"
  97.     OUTFILE="client"
  98.     FULLOUT="${DESTROOT}/${OUTFILE}.zip"
  99.     if [ -f "${FULLOUT}" ]; then
  100.         VERB="Updating"
  101.         Z7ACT="u"
  102.     else
  103.         VERB="Creating"
  104.         Z7ACT="a"
  105.     fi
  106.     echo "${VERB} ${OUTFILE}.zip"
  107.     packArchive "${Z7ACT}" "${FULLOUT}" "${NEWPACK[@]}"
  108.     cd ..
  109. }
  110.  
  111.  
  112. function packSongs() {
  113.     cd "${OSUROOT}/Songs"
  114.     if [ ! -d "${DESTROOT}/Songs" ]; then
  115.         mkdir "${DESTROOT}/Songs";
  116.     fi
  117.     for f in $(ls -1); do
  118.         case "${f}" in
  119.             "altimitmine - Twitch Friends Appreciation Song")
  120.             continue
  121.             ;;
  122.         esac
  123.         if [ -d "${f}" ]; then
  124.             NEWDIR="${OSUROOT}/Songs/${f}"
  125.             cd -- "${NEWDIR}"
  126.             OUTFILE=$(echo "${f}" | sed 's/%/\_/g;s/[+]/ /g;s/[|]/\_/g')
  127.             FULLOUT="${DESTROOT}/Songs/${OUTFILE}.osz"
  128.             if [ -f "${FULLOUT}" ]; then
  129.                 VERB="Updating"
  130.                 Z7ACT="u"
  131.             else
  132.                 VERB="Creating"
  133.                 Z7ACT="a"
  134.             fi
  135.             echo "${VERB} ${OUTFILE}.osz"
  136.             packArchive "${Z7ACT}" "${FULLOUT}" "."
  137.             cd ..
  138.         fi
  139.     done
  140. }
  141.  
  142. if [ -z "${OSUEMBED}" ]; then
  143.     if [ "$1" == "client" ]; then
  144.         packClient;
  145.     elif [ "$1" == "skins" ]; then
  146.         packSkins;
  147.     elif [ "$1" == "songs" ]; then
  148.         packSongs;
  149.     elif [ "$1" == "data" ]; then
  150.         packData;
  151.     elif [ "$1" == "all" ]; then
  152.         packClient;
  153.         packSkins;
  154.         packSongs;
  155.         packData;
  156.     else
  157.         echo "Usage: $0 [client|skins|songs|data|all]";
  158.         exit 1;
  159.     fi
  160. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement