#!/bin/bash
printf '\e[8;45;65t'
clear
BLACK="\033[0;30m"  
DARK_GRAY="\033[1;30m"  
BLUE="\033[0;34m"  
LIGHT_BLUE="\033[1;34m"  
GREEN="\033[0;32m"  
LIGHT_GREEN="\033[1;32m"  
CYAN="\033[0;36m"  
LIGHT_CYAN="\033[1;36m"  
RED="\033[0;31m"  
LIGHT_RED="\033[1;31m"  
PURPLE="\033[0;35m"  
LIGHT_PURPLE="\033[1;35m"  
BROWN="\033[0;33m"  
YELLOW="\033[0;33m"  
LIGHT_GRAY="\033[0;37m"  
WHITE="\033[1;37m" 
NC="\033[0m"
echo ""
echo -e "${LIGHT_PURPLE}泓创智诚 - 档案脱机存档${NC}"
echo ""

parentPath=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$parentPath"
appPath=$( find "$parentPath" -name '*.app' -not -name '*Crack.app' -maxdepth 1)
if [[ -z "$appPath" ]]
then
    echo -e "😅 ${LIGHT_RED}安装包已经损坏,请重新下载!${NC}"
    echo -e "✌️  本窗口可以关闭啦！"
else
appName=${appPath##*/}
appBashName=${appName// /\ }
appDIR="/Applications/${appBashName}"
echo -e "『${RED}${appBashName%.*} ${NC}已损坏,无法打开/来自身份不明的开发者』等问题修复工具"
echo ""
#未安装APP时提醒安装，已安装绕过公证
if [ ! -d "$appDIR" ];then
  echo -e "😅 ${LIGHT_RED}您还未安装 ${appBashName%.*}, 请先将软件拷贝到【${NC}${LIGHT_BLUE}应用程序${NC}${LIGHT_RED}】目录${NC}"
  else
  #绕过公证
  echo -e "👇 ${LIGHT_RED}请输入开机密码, 输入完成后按下回车键(输入过程中密码是看不见的)${NC}"
  sudo spctl --master-disable
  sudo xattr -rd com.apple.quarantine /Applications/"$appBashName"
  echo ""
  echo -e "😁 ${LIGHT_GREEN}修复成功！${NC}您现在可以正常运行 ${LIGHT_GREEN}${appBashName%.*} ${NC}了。"
fi
echo ""
echo -e "✌️  操作已成功完成, 本窗口可以关闭啦！"
fi
