#!/bin/sh

# filesharing custom fix installer.
# Place it in microupdate as
# MU<version>-filesharing

prog="`basename $0`"
root_d="/usr/local/psa"
tmp_d="$root_d/var"
sw_cmd="$root_d/bin/sw-engine-pleskrun"
scripts_d="$root_d/admin/plib/scripts"
mu="`echo $prog | awk -F '-' '{print $1}'`"
mu_flag="$tmp_d/${mu}-filesharing_installed.flag"

[ -f "$mu_flag" ] && exit 0

need_upgrade="`plesk db "select version_info from upgrade_history where db_version ='0860'"`"
[ -z "$need_upgrade" ] && touch $mu_flag && exit 0

$sw_cmd $scripts_d/db-update-plesk10.php

plesk db 'update smb_roleServicePermissions rsp, smb_servicePermissions sp, smb_roles sr set rsp.roleId=sr.id where  rsp.servicePermissionId=sp.id and sp.permissionCode="external" and sr.isBuiltIn=1 and sr.name="Admin";'

$sw_cmd $scripts_d/upgrade_filesharing_1011.php

plesk sbin httpdmng --reconfigure-all

touch $mu_flag
exit 0
