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siZqX88o0fI5YQB2YhGBjAfH5wSP
MkBBJCR3Qbc9J8ksFp//RWjWcFq/yr1WOCqEQVo1PMSPkeqfqV3ApS6XhVv4ChKL
PlnV27fa6XUK1yjNQlNxYkv15tnxhtKrLs6XiyVJbe6Q1obq0FOpBhv2WIh291BQ
bqgmGbNvABEBAAGJAjwEGAEIACYCGwwWIQQJ5V+vT3hizW1ViZfN+1+lIAe5VAUC
XXEvjgUJH3xmkQAKCRDN+1+lIAe5VJueD/4+6ldtpXYin+lWcMyHM8487GczLi8S
XgxZJu/2GzEpgdke8xoQWv6Jsk2AQaPLciIT7yU7/gTWsOiY7Om+4MGqZY+KqZ/X
eI8nFsGQx2yI7TDUQasN4uB5y6RnMGSH8DbAIWydVP2XWNVCHcVNMbeAoW7IiOOh
I2wT4bCmzrjfVsJRo8VvpykPhm7+svsU2ukMW0Ua77bA1gzdvPpRzN2I1MY/6lJk
x7BwtYsiAZt0+jII31IdCNpz4BlU3eadG+QbEH/q5FrHPBtkRWmziJpKXZDWdAg/
I7yim36xfxjMtcv8CI3YKmy5jYcGKguA2SGApQpPEUkafLZc62v8HVmZZFKmLyXR
XM9YTHz4v4jhruJ80M6YjUtfQv0zDn2HoyZuPxAW4HCys1/9+iAhuFqdt1PnHBs/
AmTFlQPAeMu++na4uc7vmnDwlY7RDPb0uctUczhEO4gT5UkLk5C9hcOKVAfmgF4n
MNgnOoSZO2orPKh3mejj+VAZsr1kfEWMoFeHPrWdxgRmjOhUfy6hKhJ1H306aaSQ
gkE3638Je/onWmnmZrDEZq7zg0Qk3aOOhJXugmRnIjH341y/whxvAdJIyXrjLN4z
qCU0JkA1rVqS6PXZabKb9DOqYa4pr9thGS5rU+Gn3GWiSq2PtVW6Hh83WOFcEsMk
2vTa24LE0J2DQg==
=Qa/n
-----END PGP PUBLIC KEY BLOCK-----
EOF
}

install_deb() {
  LIST_FILE=/etc/apt/sources.list.d/metasploit-framework.list
  PREF_FILE=/etc/apt/preferences.d/pin-metasploit.pref
  echo -n "Adding metasploit-framework to your repository list.."
  echo "deb $DOWNLOAD_URI/apt lucid main" > $LIST_FILE
  print_pgp_key | apt-key add -
  if [ ! -f $PREF_FILE ]; then
    mkdir -p /etc/apt/preferences.d/
    cat > $PREF_FILE <<EOF
Package: metasploit*
Pin: origin downloads.metasploit.com
Pin-Priority: 1000
EOF
  fi
  echo -n "Updating package cache.."
  apt-get update > /dev/null
  echo "OK"
  echo "Checking for and installing update.."
  apt-get install -y --allow-downgrades metasploit-framework
}

install_rpm() {
  echo "Checking for and installing update.."
  REPO_FILE=/etc/yum.repos.d/metasploit-framework.repo
  GPG_KEY_FILE=/etc/pki/rpm-gpg/RPM-GPG-KEY-Metasploit
  echo -n "Adding metasploit-framework to your repository list.."

  cat > /etc/yum.repos.d/metasploit-framework.repo <<EOF
[metasploit]
name=Metasploit
baseurl=$DOWNLOAD_URI/rpm
gpgcheck=1
gpgkey=file://$GPG_KEY_FILE
enabled=1
EOF
  print_pgp_key > ${GPG_KEY_FILE}
  yum install -y metasploit-framework
}

install_pkg()
{
  (
    cd ~/Downloads

    echo "Downloading package..."
    curl -O "$DOWNLOAD_URI/osx/metasploitframework-latest.pkg"

    echo "Checking signature..."

    if pkgutil --check-signature metasploitframework-latest.pkg; then
      echo "Installing package..."
      installer -pkg metasploitframework-latest.pkg -target /
    fi

    echo "Cleaning up..."
    rm -fv metasploitframework-latest.pkg
  )
}

DOWNLOAD_URI=http://downloads.metasploit.com/data/releases/metasploit-framework
PKGTYPE=unknown
ID=`id -u`

if [ -f /etc/redhat-release ] ; then
  PKGTYPE=rpm
elif [ -f /etc/system-release ] ; then
  # If /etc/system-release is present, this is likely a distro that uses RPM.
  PKGTYPE=rpm
else
  if uname -sv | grep 'Darwin' > /dev/null; then
    PKGTYPE=pkg
  else
    PKGTYPE=deb
  fi
fi

if [ "$ID" -ne 0 ]; then
  if ! hash sudo 2>/dev/null; then
    echo "This script must be executed as the 'root' user or with sudo"
    exit 1
  else
    echo "Switching to root user to update the package"
    sudo -E $0 $@
    exit 0
  fi
fi

case $PKGTYPE in
  deb)
    install_deb
    ;;
  rpm)
    install_rpm
    ;;
  *)
    install_pkg
esac


Compiler output:
a.cc:1:2: error: invalid preprocessing directive #!
    1 | #!/bin/sh
      |  ^
a.cc:33:1: error: exponent has no digits
   33 | 0Et/4lBgycaa63jQtG+GK9gN+sf4LkiDgJYkXX2wEOilvZw9zU2VLTGhOUB+e7vR
      | ^~~
a.cc:121:4: error: stray '`' in program
  121 | ID=`id -u`
      |    ^
a.cc:121:10: error: stray '`' in program
  121 | ID=`id -u`
      |          ^
a.cc:126:5: error: invalid preprocessing directive #If; did you mean #if?
  126 |   # If /etc/system-release is present, this is likely a distro that uses RPM.
      |     ^~
      |     if
a.cc:129:23: warning: multi-character literal with 6 characters exceeds 'int' size of 4 bytes
  129 |   if uname -sv | grep 'Darwin' > /dev/null; then
      |                       ^~~~~~~~
a.cc:142:17: error: stray '@' in program
  142 |     sudo -E $0 $@
      |                 ^
a.cc:3:1: error: ISO C++ forbids declaration of 'print_pgp_key' with no type [-fpermissive]
    3 | print_pgp_key() {
      | ^~~~~~~~~~~~~
a.cc: In function 'int print_pgp_key()':
a.cc:4:3: error: 'cat' was not declared in this scope
    4 |   cat <<-EOF
      |   ^~~
a.cc:4:10: error: 'EOF' was not declared in this scope
    4 |   cat <<-EOF
      |          ^~~
a.cc:1:1: note: 'EOF' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | #!/bin/sh
a.cc:5:6: error: 'BEGIN' was not declared in this scope
    5 | -----BEGIN PGP PUBLIC KEY BLOCK-----
      |      ^~~~~
a.cc:58:1: warning: no return statement in function returning non-void [-Wreturn-type]
   58 | }
      | ^
a.cc: At global scope:
a.cc:60:1: error: ISO C++ forbids declaration of 'install_deb' with no type [-fpermissive]
   60 | install_deb() {
      | ^~~~~~~~~~~
a.cc: In function 'int install_deb()':
a.cc:61:3: error: 'LIST_FILE' was not declared in this scope
   61 |   LIST_FILE=/etc/apt/sources.list.d/metasploit-framework.list
      |   ^~~~~~~~~
a.cc:61:13: error: expected primary-expression before '/' token
   61 |   LIST_FILE=/etc/apt/sources.list.d/metasploit-framework.list
      |             ^
a.cc:61:14: error: 'etc' was not declared in this scope
   61 |   LIST_FILE=/etc/apt/sources.list.d/metasploit-framework.list
      |              ^~~
a.cc:61:18: error: 'apt' was not declared in this scope
   61 |   LIST_FILE=/etc/apt/sources.list.d/metasploit-framework.list
      |                  ^~~
a.cc:61:22: error: 'sources' was not declared in this scope
   61 |   LIST_FILE=/etc/apt/sources.list.d/metasploit-framework.list
      |                      ^~~~~~~
a.cc:61:37: error: 'metasploit' was not declared in this scope
   61 |   LIST_FILE=/etc/apt/sources.list.d/metasploit-framework.list
      |                                     ^~~~~~~~~~
a.cc:61:48: error: 'framework' was not declared in this scope
   61 |   LIST_FILE=/etc/apt/sources.list.d/metasploit-framework.list
      |                                                ^~~~~~~~~
a.cc:66:27: error: 'then' was not declared in this scope
   66 |   if [ ! -f $PREF_FILE ]; then
      |                           ^~~~
a.cc:79:1: warning: no return statement in function returning non-void [-Wreturn-type]
   79 | }
      | ^
a.cc: At global scope:
a.cc:81:1: error: ISO C++ forbids declaration of 'install_rpm' with no type [-fpermissive]
   81 | install_rpm() {
      | ^~~~~~~~~~~
a.cc: In function 'int install_rpm()':
a.cc:82:3: error: 'echo' was not declared in this scope
   82 |   echo "Checking for and installing update.."
      |   ^~~~
a.cc:96:3: error: 'yum' was not declared in this scope
   96 |   yum install -y metasploit-framework
      |   ^~~
a.cc:97:1: warning: no return statement in function returning non-void [-Wreturn-type]
   97 | }
      | ^
a.cc: At global scope:
a.cc:99:1: error: ISO C++ forbids declaration of 'install_pkg' with no type [-fpermissive]
   99 | install_pkg()
      | ^~~~~~~~~~~
a.cc: In function 'int install_pkg()':
a.cc:102:5: error: 'cd' was not declared in this scope
  102 |     cd ~/Downloads
      |     ^~
a.cc:102:7: error: expected ')' before '~' token
  102 |     cd ~/Downloads
      |       ^~
      |       )
a.cc:101:3: note: to match this '('
  101 |   (
      |   ^
a.cc:109:66: error: 'then' was not declared in this scope
  109 |     if pkgutil --check-signature metasploitframework-latest.pkg; then
      |                                                                  ^~~~
a.cc:117:1: warning: no return statement in function returning non-void [-Wreturn-type]
  117 | }
      | ^
a.cc: At global scope:
a.cc:119:1: error: 'DOWNLOAD_URI' does not name a type
  119 | DOWNLOAD_URI=http://downloads.metasploit.com/data/releases/metasploit-framework
      | ^~~~~~~~~~~~
a.cc:123:33: error: 'then' does not name a type
  123 | if [ -f /etc/redhat-release ] ; then
      |                                 ^~~~
a.cc:125:35: error: 'then' does not name a type
  125 | elif [ -f /etc/system-release ] ; then
      |                                   ^~~~
a.cc:129:45: error: 'then' does not name a type
  129 |   if uname -sv | grep 'Darwin' > /dev/null; then
      |                                             ^~~~
a.cc:136:21: error: 'then' does not name a type
  136 | if [ "$ID" -ne 0 ]; then
      |                     ^~~~
a.cc:137:31: error: 'then' does not name a type
  137 |   if ! hash sudo 2>/dev/null; then
      |                               ^~~~
a.cc:151:3: error: 'rpm' does not name a type
  151 |   rpm)
      |   ^~~
a.cc:154:4: error: expected unqualified-id before ')' token
  154 |   *)
      |    ^