Advertisement
kreezxil

mkArchive.sh

Apr 10th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Adjust the following variables as necessary
  4. # You must change the DOMAIN variable
  5. DOMAIN="your.domain.tld"
  6. TEMP="/home/admin/web/${DOMAIN}/public_html/TechnicSolder/public/temp"
  7. MODS="/home/admin/web/${DOMAIN}/public_html/TechnicSolder/public/mods"
  8. WWWUSER="admin"
  9.  
  10. function isYn {
  11.  if [ ${#1} -gt 1 ]; then
  12.  echo "I only need one character!"
  13.  echo "y or n"
  14.  echo "Exiting ..."
  15.  echo
  16.  exit
  17.  fi
  18. }
  19.  
  20. function exitIfNull {
  21.  if [ "${1}" == "" ]; then
  22.  echo "Null response detected."
  23.  echo "Exiting ..."
  24.  echo
  25.  exit
  26.  fi
  27. }
  28.  
  29. re='^[0-9]+$'
  30. if [[ "${1}" -gt 0 ]]; then
  31.  if ! [[ ${1} =~ $re ]] ; then
  32.  clear
  33.  echo "error: first argument is not a valid menu choice" >&2; exit 1
  34.  echo
  35.  fi
  36. fi
  37. if [[ "${1}" -lt 1 || "${1}" -gt 5 ]]; then
  38.  echo "Pack Type:"
  39.  echo
  40.  echo "1. Standard Mod"
  41.  echo "2. Lite Mod"
  42.  echo "3. Config Pack"
  43.  echo " - You must have uploaded all configs in"
  44.  echo " the structure required by the mod to"
  45.  echo " the TEMP path"
  46.  echo "4. Forge Jar"
  47.  echo "5. Minecraft Root"
  48.  echo " - servers.dat, options.txt etc. ..."
  49.  echo
  50.  read -rp "CHOICE: " CHOICE
  51.  if [[ $CHOICE -lt 1 || $CHOICE -gt 5 ]]; then
  52.  echo "Invalid Choice!"
  53.  echo "Please choose a number from 1-5"
  54.  echo "Exiting ..."
  55.  echo
  56.  exit
  57.  fi
  58. else
  59.  # we received the menu entry at the command line
  60.  CHOICE="${1}"
  61. fi
  62. case $CHOICE in
  63.  1) STRUCTURE="mods"
  64.  TARGET="mods"
  65.  ;;
  66.  2) STRUCTURE="mods/1.8"
  67.  TARGET="mods"
  68.  ;;
  69.  3) STRUCTURE="config"
  70.  TARGET="config"
  71.  ;;
  72.  4) STRUCTURE="bin"
  73.  TARGET="bin"
  74.  FILENAM="modpack.jar"
  75.  ;;
  76.  5) STRUCTURE=""
  77.  TARGET="*"
  78.  ;;
  79. esac
  80.  
  81. if [ "${2}" == "" ]; then
  82.  # modslug not given at command line, let's get it now
  83.  read -rp "MODSLUG=" MODSLUG
  84.  exitIfNull "${MODSLUG}"
  85. else
  86.  #THE %/ is what removes the trailing slash
  87.  MODSLUG="${2%/}"
  88. fi
  89.  
  90. if [ "${3}" == "" ]; then
  91.  read -rp "VERSION=" VERSION
  92.  exitIfNull "${VERSION}"
  93. else
  94.  VERSION="${3}"
  95. fi
  96.  
  97. if [ "${4}" == "" ]; then
  98.  read -rp "Is mod in temp? (y/n) " LOCATION
  99.  exitIfNull "${LOCATION}"
  100.  isYn "${LOCATION}"
  101.  if [ "${LOCATION}" = "n" ]; then
  102.  read -rp "MODLINK=" MODLINK
  103.  exitIfNull "${MODLINK}"
  104.  
  105.  if [ "${FILENAM}" == "" ]; then
  106.  read -rp "Generate filename? (y/n)" GENFILE
  107.  exitIfNull "${GENFILE}"
  108.  isYn "${GENFILE}"
  109.  if [[ "${GENFILE}" =~ ^(y|Y)$ ]]; then
  110.  FILENAM="${MODSLUG}-${VERSION}.jar"
  111.  fi
  112.  fi
  113.  else
  114.  LOCATION="TEMP"
  115.  read -rp "Is there more than one part in Temp for ${MODSLUG}? (y/n) " CHOICE
  116.  exitIfNull "${CHOICE}"
  117.  isYn "${CHOICE}"
  118.  if [[ "${CHOICE}" =~ ^(y|Y)$ ]]; then
  119.  PAT="*"
  120.  fi
  121.  fi
  122. else
  123.  MODLINK="${4}"
  124.  if [ "${FILENAM}" == "" ]; then
  125.  if [ "${5}" == "" ]; then
  126.  # no filename on command line so gen one now
  127.  # because if we are doing this many options via
  128.  # cli then why not!?
  129.  FILENAM="${MODSLUG}-${VERSION}.jar"
  130.  fi
  131.  fi
  132. fi
  133.  
  134. if [ "${FILENAM}" = "" ]; then
  135.  if [ "${5}" != "" ]; then
  136.  FILENAM="${5}"
  137.  fi
  138. fi
  139.  
  140. if [ "${PAT}" == "" ]; then
  141.  if [ "${FILENAM}" == "" ]; then
  142.  read -rp "FILENAM=" FILENAM
  143.  exitIfNull "${FILENAM}"
  144.  fi
  145. fi
  146.  
  147. MODPATH="${MODSLUG}/${STRUCTURE}"
  148. mkdir -p "${MODPATH}" # creates the entire directory path as needed; supresses standard errors
  149.  
  150. cd "${MODPATH}"
  151. #the mods directory should actually be empty
  152. rm -f *
  153. if [ "${LOCATION}" = "TEMP" ]; then
  154.  if [ "${STRUCTURE}" != "" ]; then #root archive if true, leave it in temp
  155.  if [ "${PAT}" = "*" ]; then
  156.  mv ${TEMP}/${PAT} .
  157.  else
  158.  if [ -e "${TEMP}/${FILENAM}" ]; then
  159.  mv "${TEMP}/${FILENAM}" .
  160.  else
  161.  echo "Error locating ..."
  162.  echo "${TEMP}/${FILENAM}"
  163.  echo "Exiting ..."
  164.  exit
  165.  fi
  166.  fi
  167.  fi
  168. else
  169.  wget "${MODLINK}" -O "${FILENAM}"
  170. fi
  171.  
  172. cd "${MODS}/${MODSLUG}"
  173.  
  174. ZIPFILE="${MODSLUG}-${VERSION}.zip"
  175. if [ -e "${ZIPFILE}" ]; then
  176.  # prevent multiple copies of a same or similar mod
  177.  # based on the mod you are zipping for in the event
  178.  # you are remaking the mod archive with the same
  179.  # ZIPFILE name
  180.  clear
  181.  echo "You are duplicating your efforts, ${ZIPFILE} already exists!!!"
  182.  echo "I'm not doing this, if you insist on doing this, change the version number!"
  183.  echo "Conversely you should probably take a break!"
  184.  exit
  185. fi
  186.  
  187. # Zip options:
  188. # -r recurse into directories
  189. # -m move file into zipfile
  190. if [ "${TARGET}" == "*" ]; then
  191.  # this is a root archive operation
  192.  # we'll be working from the master temp folder
  193.  # and move the completed zipfile to its proper
  194.  # home afterwords
  195.  if [ "${STRUCTURE}" = "" ]; then # root archive
  196.  cd "${TEMP}"
  197.  zip -rm "${ZIPFILE}" *
  198.  mv "${ZIPFILE}" "${MODS}/${MODSLUG}/"
  199.  else
  200.  zip -rm "${ZIPFILE}" *
  201.  fi
  202. else
  203.  zip -rm "${ZIPFILE}" "${TARGET}"
  204. fi
  205.  
  206. cd "${MODS}"
  207. chown -R "${WWWUSER}:${WWWUSER}" "${MODSLUG}"
  208.  
  209. clear
  210. echo "Modslug=${MODSLUG}"
  211. echo "Filename=${FILENAM}"
  212. echo "Version=${VERSION}"
  213. if [ "${MODLINK}" != "" ]; then
  214.  echo "Modlink=${MODLINK}"
  215.  echo
  216.  echo "./newMod.sh ${MODLINK} ${FILENAM}"
  217.  echo
  218. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement