#!/bin/bash # NOT compatible with Rocky9 !!! Ruby gem versions... dir="/usr/src/m2" . /usr/src/m2/framework/bash_functions.sh . /etc/profile.d/rvm.sh VERSION="1.1.0" # based on https://outhereinthefield.wordpress.com/2015/06/14/scripting-gmail-download-and-saving-the-attachments-with-fetchmail-procmail-and-munpack/ install_packets() { local cur_dir=$(pwd) #local mpack_version="1.6-2" local rar_version="5.6.0" local mail_gem_version="2.7.1" local mechanize_gem_version="2.7.4" local nokogiri_gem_version="1.6.8" # http://trac.kolmisoft.com/trac/ticket/17659 if [[ $ROCKY9 == 1 ]]; then rvm use ruby-3.2.2 # newer gems required for link_attachment_downloader.rb nokogiri_gem_version="1.16.0" mechanize_gem_version="2.10.0" yum -y install fetchmail procmail nano unzip wget util-linux ripMIME needs to be cloned and installed manaully git clone https://github.com/inflex/ripMIME.git cd "$cur_dir/ripMIME" make make install rm -rf "$cur_dir/ripMIME" cd "$cur_dir" else yum -y install fetchmail procmail nano unzip wget util-linux ripmime fi report "Checking gems. This can take some time..." 3 if ! rvm @global do gem list mail | grep -Fq $mail_gem_version; then rvm @global do gem install mail -v $mail_gem_version fi if ! rvm @global do gem list nokogiri | grep -Fq $nokogiri_gem_version; then rvm @global do gem install nokogiri -v $nokogiri_gem_version -- --use-system-libraries fi if ! rvm @global do gem list mechanize | grep -Fq $mechanize_gem_version; then rvm @global do gem install mechanize -v $mechanize_gem_version fi #install mpac (munpack) cd /usr/src # if ! rpm -qa | grep -Fq mpack-$mpack_version; then # wget --no-check-certificate http://www.kolmisoft.com/packets/mpack-$mpack_version.el6.rf.x86_64.rpm # rpm -Uvh mpack* # fi # Install rar if [ ! -e /usr/src/rarlinux-x64-$rar_version.tar.gz ]; then wget https://www.rarlab.com/rar/rarlinux-x64-$rar_version.tar.gz tar -zxvf rarlinux-x64-$rar_version.tar.gz &> /dev/null cp -v rar/rar rar/unrar /usr/local/bin/ fi cd "$cur_dir" } update_source() { cp -fr $dir/helpers/email2tariff/get_mail.sh /home/email2tariff/ cp -fr $dir/helpers/email2tariff/email_source_parser.rb /home/email2tariff/ cp -fr $dir/helpers/email2tariff/link_attachment_downloader.rb /home/email2tariff/ cp -fr $dir/helpers/email2tariff/email2tariff_cron /etc/cron.d/ cp -fr $dir/gui/cronjobs/m2_tariff_import_actions /etc/cron.d/ apache_listen_on_https=$(netstat -antp | grep -F http | grep -cF :443) if (( apache_listen_on_https > 0)); then sed -i 's#http:#https:#' /etc/cron.d/m2_tariff_import_actions fi chmod 777 /home/email2tariff/email_source_parser.rb chmod 777 /home/email2tariff/link_attachment_downloader.rb chmod 0644 /etc/cron.d/email2tariff_cron chmod 0644 /etc/cron.d/m2_tariff_import_actions service crond restart > /dev/null # global logrotate handles it now #add_logrotate_if_not_present "/var/log/m2/email2tariff.log" "email2tariff" } install_configs() { cp -fr $dir/helpers/email2tariff/.fetchmailrc /root cp -fr $dir/helpers/email2tariff/.procmailrc /home/email2tariff # Contains password in cleartext chmod 700 /root/.fetchmailrc report "Enter correct email username and password into /root/.fetchmailrc" 3 report "If using different mail provider than gmail, change other details accordingly" 3 } report "Starting email2tariff installation/update" 3 # A bit of explanation for the folders: # • landing is where we first move new mails from procmail’s Maildir prior extracting the attachments # • extract is where we will perform attachment extraction # • store is the final destination of the attachments # • archive is where the mail files are stored after the process is done. If you want to reprocess certain files, just move it back to landing mkdir -p /home/email2tariff/Maildir/process/{landing,extract,store,archive} # Set confline with current date -12 h to account for posible timezone diferences confline_date=$(date +'%Y-%m-%d %H:%M:%S' -d '12 hour ago'); set_confline "Email2tariff_start_date" "$confline_date" install_packets update_source if [ ! -e /root/.fetchmailrc ]; then install_configs fi report "Email2Tariff installation/update has been completed" 3