Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.39 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # check number of arguments
  4. if [ $# -eq 0 ]
  5. then
  6.     echo "Usage: installer <CSV-FILE>"; exit 0
  7. fi
  8.  
  9. # check first argument, '! -f' checks if it is NOT a file
  10. if [ ! -f $1 ]
  11. then
  12.     echo "File $1 does not exist!"; exit -1
  13. fi
  14.  
  15. # declare some variables
  16. PACKAGE_FILE=$1
  17. PKG_NUMBER=0
  18.  
  19. echo -n "Packages: "
  20. while IFS=, read pkg_name pkg_ver pkg_url pkg_checksum
  21. do
  22.     echo -n "$pkg_name "
  23.     let PKG_NUMBER=PKG_NUMBER+1
  24. done < $PACKAGE_FILE
  25.  
  26. echo -e "\nNumber of packages: $PKG_NUMBER"
  27. echo -n "Sure you want to install all packages[Y/n]? "
  28. read INPUT
  29.  
  30. # If 'Y', 'y' or '' is entered, continue, else exit.
  31. if [ $INPUT != "Y" ] && [ $INPUT != "y" ] && [ $INPUT != "" ]
  32. then
  33.     echo "Aborting installation ..."; echo; exit 0
  34. fi
  35.  
  36. # create a directory with has a unique name.
  37. # This pipes the current date through base64
  38. # which converts the string into base64
  39. # (alphabet with 64 letters; a to z, A to Z,'+' and '/')
  40. TMP_DIR="/tmp/$(date|base64)"
  41.  
  42. # if this directory already exist, try again until it works
  43. until mkdir $TMP_DIR
  44. do
  45.     TMP_DIR="/tmp/$(date|base64)"
  46. done
  47.  
  48. # save current directory
  49. OLD_DIR="${PWD}"
  50.  
  51. # check is 'MY_LIBS' is set, if not set it to some
  52. # default value
  53. if [ -z $MY_LIBS ]
  54. then
  55.     MY_LIBS="$OLD_DIR/libs"
  56. fi
  57.  
  58. # check if 'MY_LIBS' is a real diretory
  59. if [ ! -d $MY_LIBS ]
  60. then
  61.     mkdir $MY_LIBS
  62. fi
  63.  
  64. # first copy package file to temp folder
  65. cp "$PACKAGE_FILE" "$TMP_DIR/$PACKAGE_FILE"
  66.  
  67. # change directory
  68. cd $TMP_DIR
  69.  
  70. # Number of installed packages
  71. PKG_INSTALLED=0
  72.  
  73. mkdir "download"
  74. cd "download"
  75.  
  76. CONFIG_FILE="../$PACKAGE_FILE"
  77.  
  78. # Go through each package and install it
  79. while IFS=, read pkg_name pkg_ver pkg_url pkg_checksum
  80. do
  81.     # Step 1: Download package
  82.     FILENAME=$(basename "$pkg_url") # get name of file
  83.     if ! wget -q --show-progress --progress=bar:force $pkg_url  
  84.     then
  85.     # clean up directory
  86.     rm -R -f * # clean up everything in tmp folder
  87.     echo "Package '$pkg_name' could not be downloaded from $pkg_url!"; exit -1;
  88.     fi
  89.    
  90.     # Step 2: Unpack package according to suffix
  91.     if file --mime-type "$FILENAME" | grep -q ".tar.gz"; then
  92.     if ! tar xfz "$FILENAME" -C "." --strip 1; then
  93.         echo "ERROR: could not unpack $FILENAME!"
  94.         continue;
  95.     fi
  96.     elif file --mime-type "$FILENAME" | grep ".tar.xz"; then
  97.     if ! tar xf "$FILENAME" -C "." --strip 1; then
  98.         echo "ERROR: could not unpack $FILENAME!"
  99.         continue;
  100.     fi
  101.     elif file --mime-type "$FILENAME" | grep ".zip"; then
  102.     if ! unzip "$FILENAME" -d "."; then
  103.         echo "ERROR: could not unpack $FILENAME!"
  104.         continue;
  105.     fi
  106.     else
  107.     echo "ERROR: not supported file format!"
  108.     continue;
  109.     fi
  110.    
  111.     # Step 3: Check Checksum
  112.     # need more information to perform checksum, sha1 md5 BSD which checksum to use?
  113.    
  114.     # Step 4: install it
  115.     if ! /bin/bash ./configure; then
  116.     echo "ERROR: configure!"
  117.     continue
  118.     fi
  119.     if ! make; then
  120.     echo "ERROR: make!"
  121.     continue
  122.     fi
  123. #   if ! make install; then
  124. #       echo "ERROR: make install"
  125. #   continue
  126. #   fi
  127.    
  128.     # Step 5: copy everything to location
  129.     cp -R * $MY_LIBS
  130.    
  131.     # Step 6: delete files and continue
  132.     rm -R -f *
  133.    
  134.     let PKG_INSTALLED=PKG_INSTALLED+1
  135. done < $CONFIG_FILE
  136.  
  137. # remove all temp files
  138. rm -R -f $TMP_DIR
  139.  
  140. echo "Installed $PKG_INSTALLED/$PKG_NUMBER packages."
  141. echo "Checkout $MY_LIBS for the packages!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement