Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # check number of arguments
- if [ $# -eq 0 ]
- then
- echo "Usage: installer <CSV-FILE>"; exit 0
- fi
- # check first argument, '! -f' checks if it is NOT a file
- if [ ! -f $1 ]
- then
- echo "File $1 does not exist!"; exit -1
- fi
- # declare some variables
- PACKAGE_FILE=$1
- PKG_NUMBER=0
- echo -n "Packages: "
- while IFS=, read pkg_name pkg_ver pkg_url pkg_checksum
- do
- echo -n "$pkg_name "
- let PKG_NUMBER=PKG_NUMBER+1
- done < $PACKAGE_FILE
- echo -e "\nNumber of packages: $PKG_NUMBER"
- echo -n "Sure you want to install all packages[Y/n]? "
- read INPUT
- # If 'Y', 'y' or '' is entered, continue, else exit.
- if [ $INPUT != "Y" ] && [ $INPUT != "y" ] && [ $INPUT != "" ]
- then
- echo "Aborting installation ..."; echo; exit 0
- fi
- # create a directory with has a unique name.
- # This pipes the current date through base64
- # which converts the string into base64
- # (alphabet with 64 letters; a to z, A to Z,'+' and '/')
- TMP_DIR="/tmp/$(date|base64)"
- # if this directory already exist, try again until it works
- until mkdir $TMP_DIR
- do
- TMP_DIR="/tmp/$(date|base64)"
- done
- # save current directory
- OLD_DIR="${PWD}"
- # check is 'MY_LIBS' is set, if not set it to some
- # default value
- if [ -z $MY_LIBS ]
- then
- MY_LIBS="$OLD_DIR/libs"
- fi
- # check if 'MY_LIBS' is a real diretory
- if [ ! -d $MY_LIBS ]
- then
- mkdir $MY_LIBS
- fi
- # first copy package file to temp folder
- cp "$PACKAGE_FILE" "$TMP_DIR/$PACKAGE_FILE"
- # change directory
- cd $TMP_DIR
- # Number of installed packages
- PKG_INSTALLED=0
- mkdir "download"
- cd "download"
- CONFIG_FILE="../$PACKAGE_FILE"
- # Go through each package and install it
- while IFS=, read pkg_name pkg_ver pkg_url pkg_checksum
- do
- # Step 1: Download package
- FILENAME=$(basename "$pkg_url") # get name of file
- if ! wget -q --show-progress --progress=bar:force $pkg_url
- then
- # clean up directory
- rm -R -f * # clean up everything in tmp folder
- echo "Package '$pkg_name' could not be downloaded from $pkg_url!"; exit -1;
- fi
- # Step 2: Unpack package according to suffix
- if file --mime-type "$FILENAME" | grep -q ".tar.gz"; then
- if ! tar xfz "$FILENAME" -C "." --strip 1; then
- echo "ERROR: could not unpack $FILENAME!"
- continue;
- fi
- elif file --mime-type "$FILENAME" | grep ".tar.xz"; then
- if ! tar xf "$FILENAME" -C "." --strip 1; then
- echo "ERROR: could not unpack $FILENAME!"
- continue;
- fi
- elif file --mime-type "$FILENAME" | grep ".zip"; then
- if ! unzip "$FILENAME" -d "."; then
- echo "ERROR: could not unpack $FILENAME!"
- continue;
- fi
- else
- echo "ERROR: not supported file format!"
- continue;
- fi
- # Step 3: Check Checksum
- # need more information to perform checksum, sha1 md5 BSD which checksum to use?
- # Step 4: install it
- if ! /bin/bash ./configure; then
- echo "ERROR: configure!"
- continue
- fi
- if ! make; then
- echo "ERROR: make!"
- continue
- fi
- # if ! make install; then
- # echo "ERROR: make install"
- # continue
- # fi
- # Step 5: copy everything to location
- cp -R * $MY_LIBS
- # Step 6: delete files and continue
- rm -R -f *
- let PKG_INSTALLED=PKG_INSTALLED+1
- done < $CONFIG_FILE
- # remove all temp files
- rm -R -f $TMP_DIR
- echo "Installed $PKG_INSTALLED/$PKG_NUMBER packages."
- echo "Checkout $MY_LIBS for the packages!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement