SHARE
TWEET

finish_convert.sh

RussianAdmins Aug 14th, 2019 (edited) 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Get usernames old+new and change passwd,shadow,groups
  3. dir=/root/migration
  4. mkdir /usr/local/cwp/.conf/
  5. touch /usr/local/cwp/.conf/mysql_user_prefix.conf
  6. for lUSER in `awk '{print $1}' /root/migration/userlist`; do
  7.   for SHORT in `grep $lUSER /root/migration/userlist | awk '{print $2}'`; do
  8.     #SHORT=`grep $USER /root/migration/userlist | awk '{print $2}'`
  9.     PREFIX=`mysql --skip-column-names -e "SELECT user FROM mysql.user WHERE user LIKE '${SHORT}_%'" | sort| uniq `
  10.     if [ ! -z "$PREFIX" ] && [ ! "$lUSER" == "$SHORT" ] ; then echo "$lUSER:$SHORT" >> /usr/local/cwp/.conf/mysql_user_prefix.conf; fi
  11.   done
  12. done
  13.  
  14.  
  15. echo "Import users data from SQL files"
  16. VERSION=`mysql -V |awk '{print $5}' |sed "s/-[[:alpha:]].*$//"`
  17. if [ -z "`mysql -V |grep -i mariadb`" ]; then # There is MySQL server
  18.  if [[ "$VERSION" > "5.6.9" ]]; then
  19.     NEW=1
  20.     else
  21.     NEW=0
  22.  fi
  23. else # There is MariaDB server 10.4
  24.  if [[ "$VERSION" > "10.4" ]]; then
  25.     NEW=1
  26.     else
  27.     NEW=0
  28.  fi
  29. fi
  30. if [ $NEW = "1" ]; then
  31.     if [ -z "`grep mysqld /etc/my.cnf`" ];
  32.      then
  33.         sed -i '1 a [mysqld]' /etc/my.cnf
  34.         sed -i '/\[mysqld\]/ a sql_mode="ALLOW_INVALID_DATES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"' /etc/my.cnf
  35.     else
  36.         sed -i '/\[mysqld\]/ a sql_mode="ALLOW_INVALID_DATES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"' /etc/my.cnf
  37.    fi
  38. systemctl restart mysqld mariadb
  39. fi
  40. mysql -D root_cwp -e "ALTER TABLE user ALTER setup_date SET default '1970-01-01 00:00:00'" ; echo -n "."
  41. mysql -D root_cwp -e "ALTER TABLE user ALTER last_access SET default '1970-01-01 00:00:00'" ; echo -n "."
  42. mysql -D root_cwp -e "ALTER TABLE subdomains ALTER setup_time SET default '1970-01-01 00:00:00'" ; echo -n "."
  43. mysql -D root_cwp -e "ALTER TABLE subdomains MODIFY user varchar(40)" ; echo -n "."
  44. mysql -D root_cwp -e "ALTER TABLE packages MODIFY reseller varchar(40) NULL" ; echo -n "."
  45. mysql -D root_cwp -e "ALTER TABLE packages MODIFY accounts varchar(40) NULL" ; echo -n "."
  46. mysql -D postfix -e  "ALTER TABLE domain MODIFY transport varchar(255) NULL" ; echo -n "."
  47. mysql -D root_cwp < $dir/packages.sql
  48. for PACK in `cat $dir/packages` ; do
  49.     PACK="`echo $PACK | sed 's/=/ /g'`"
  50.     ID=`mysql --skip-column-names -D root_cwp -e "SELECT id FROM packages WHERE package_name='$PACK'"`
  51.     if [[ "$ID" == "" ]]; then echo "CHECK MIGRATED PACKAGES! EXIT"; exit 1; fi
  52.     sed -i "s/, '$PACK', /, '$ID', /g" $dir/users.sql
  53.     echo -n "."
  54. done
  55. echo -n "." ; mysql -D root_cwp < $dir/domains.sql
  56. echo -n "." ; mysql -D root_cwp < $dir/users.sql
  57. echo -n "." ; mysql -D postfix  < $dir/email_accounts.sql
  58. echo -n "." ; mysql -D postfix  < $dir/mail_autoresponders.sql
  59. echo -n "." ; mysql -D postfix  < $dir/mail_forwarders.sql
  60. echo -n "." ; mysql -D root_cwp < $dir/resellers_double_plans.sql
  61. echo
  62. echo "Done"
  63. echo "Import emails" ; echo
  64. for i in `cat $dir/vmail`; do
  65.     if [ -d $i ]; then
  66.      echo -n "." ; /bin/mv $i /var/vmail
  67.     fi
  68.     chown -R vmail:mail /var/vmail
  69. done
  70. echo "Done."
  71. echo "Converting Cronjobs"
  72. for i in `cd /var/spool/cron/ ; ls`; do
  73.     sed -i '/^SHELL.*$/d' /var/spool/cron/$i ; echo -n "."
  74. done
  75. echo
  76. echo "Done"
  77.  
  78. echo "Fix accounts, webserver configs... Wait."
  79. sh /scripts/update_cwp
  80.  
  81. for USER in `cut -d' ' -f1 $dir/userlist `; do
  82.     sh /scripts/cwp_api account fix_perms $USER
  83.     echo "."
  84. done
  85. cp $dir/ssl/certs/* /etc/pki/tls/certs/
  86. cp $dir/ssl/private/* /etc/pki/tls/private/
  87. while read line; do
  88.  echo ".";
  89.  sh /scripts/cwp_api webservers add_ssl $line
  90. done < $dir/had_ssl
  91.  
  92. while read line; do
  93.  ftpuser=`echo $line | awk '{print $2}' | cut -d ':' -f2`
  94.  homedir=`echo $line | awk '{print $1}' | cut -d ':' -f2`
  95.  mail=`echo $line | awk '{print $3}' | cut -d ':' -f2`
  96. echo "pure-pw useradd `if [ ! -z "$mail" ]; then echo "'$mail'"; fi` -u '${ftpuser}' -g '${ftpuser}' -d '${homedir}' -m"
  97. done < $dir/ftpusers
  98. echo
  99. echo "Done."
  100.  
  101. sh /scripts/phpfpm_rebuild_user_conf
  102. sh /scripts/cwp_api webservers rebuild_all
  103. echo
  104. echo "Done"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top