bash to python

From cm3l1k1, 5 Years ago, written in Bash, viewed 368 times.
URL http://paste.security-portal.cz/view/3eb2fa3b Embed
Download Paste or View Raw
  1. # variables
  2. STAGE3BASEURL="http://distfiles.gentoo.org/releases/${ARCH}/autobuilds/"
  3. STAGE3LATESTTXT="latest-stage3-${SUBARCH}-hardened.txt"
  4. PORTAGEFILE="http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2"
  5.  
  6. # funkce na download
  7. f_download() {
  8.     #usage: f_download $link $backup-link
  9.     #example: f_download http://x.y.z/file.tgz http://mirror.x.y.z/file.tgz
  10.     #idea fitnr.com
  11.     local downlink="$1"
  12.     local backuplink="$2"
  13.     local downfile=${downlink##*/}
  14.     local backupfile=${backuplink##*/}
  15.     echo "Downloading: ${downlink}"
  16.     echo -n "Status:     "
  17.     wget --timeout=30 --no-cache --progress=dot ${downlink} 2>&1 | grep --line-buffered "%" |
  18.         sed -u -e "s,.,,g" | awk '{printf("bbbb%4s", $2)}'
  19.     echo " DONE"
  20.     if [ -f $downfile ]; then
  21.         downloaded="yes"
  22.         return 0
  23.     else
  24.         if [ ! -z $backuplink ]; then
  25.             echo "Downloading from mirror: ${backuplink}"
  26.             echo -n "Status:     "
  27.             wget --timeout=30 --no-cache --progress=dot ${backuplink} 2>&1 | grep --line-buffered "%" |
  28.                 sed -u -e "s,.,,g" | awk '{printf("bbbb%4s", $2)}'
  29.             echo " DONE"
  30.             if [ -f $backupfile ]; then
  31.                 downloaded="yes"
  32.                 return 0
  33.             else
  34.                 downloaded="no"
  35.                 return 1
  36.             fi
  37.         else
  38.             downloaded="no"
  39.             return 1
  40.         fi
  41.     fi
  42. }
  43.  
  44. # nejdriv stahne file, ve kterym je napsano, kde se nachazi nejaktualnejsi soubor
  45. # ten se pak stahne
  46.  
  47. # download stage3 and portage
  48. f_msg info "###-### Step: Downloading hardened stage ---"
  49. f_download ${STAGE3BASEURL}${STAGE3LATESTTXT}
  50. STAGE3FILE=${STAGE3BASEURL}$(grep -v '#' ${STAGE3LATESTTXT})
  51. f_download ${STAGE3FILE}
  52. statusd=$?
  53. f_download ${STAGE3FILE}.DIGESTS
  54.  
  55. # check SHA512
  56. STAGE3SUM=$(sha512sum ${STAGE3FILE##*/})
  57. grep ${STAGE3SUM} ${STAGE3FILE##*/}.DIGESTS >/dev/null
  58. statusc=$?
  59. if [ $statusd -ne 0 -o $statusc -ne 0 ]; then
  60.     f_msg error "ERROR: There was problem with download or checksum of stage3 file. Exit codes: "
  61.     f_msg warn "download: ${statusd} checksum: ${statusc}"
  62.     exit_on_error
  63. else
  64.     echo "-- SHA512 checksum: OK"
  65. fi
  66.  
  67. f_msg info "###-### Step: Downloading Portage ---"
  68. f_download ${PORTAGEFILE}
  69. statusd=$?
  70. f_download ${PORTAGEFILE}.md5sum
  71. md5sum --status -c ${PORTAGEFILE##*/}.md5sum
  72. statusc=$?
  73. if [ $statusd -ne 0 -o $statusc -ne 0 ]; then
  74.     f_msg error "ERROR: There was problem with download or checksum of Portage. Exit codes: "
  75.     f_msg warn "download: ${statusd} checksum: ${statusc}"
  76.     exit_on_error
  77. else
  78.     echo "-- MD5 checksum: OK"
  79. fi
  80.  

Reply to "bash to python"

Here you can reply to the paste above