#!/usr/bin/env bash

_pkgname=iventoy

all_off="$(tput sgr0)"
bold="${all_off}$(tput bold)"
blue="${bold}$(tput setaf 4)"
yellow="${bold}$(tput setaf 3)"

note() {
    printf "${blue}==>${yellow} NOTE:${bold} $1${all_off}\n"
}

post_install() {
    if [[ "$LANG" == "zh_CN.UTF-8" ]]; then
        note "请将你的镜像文件放置在 \"/var/lib/${_pkgname}/iso\" 下...
          或将存放镜像文件的目录手动软链接为 \"/var/lib/${_pkgname}/iso\"...
          然后以命令 \"sudo systemctl start ${_pkgname}.service\" 来启动...
          请访问 http://127.0.0.1:26000 来进行 ${_pkgname} 的配置...
          一些无人值守、自动安装部署的示例脚本/示例模板存放在 \"/usr/share/${_pkgname}/scripts\"...
          帮助文档见： https://www.iventoy.com/cn/doc_start.html"
    else
        note "Please put your image file under \"/var/lib/${_pkgname}/iso\" ...
          Or manually symbolic link the directory where the image file is stored to \"/var/lib/${_pkgname}/iso\" ...
          Subsequently, start ${_pkgname} with the command \"sudo systemctl start ${_pkgname}.service\"...
          Please visit http://127.0.0.1:26000 to configure ${_pkgname} ...
          Some example scripts / templates for unattended deployment are stored in \"/usr/share/${_pkgname}/scripts\" ...
          Help document see: https://www.iventoy.com/en/doc_start.html"
    fi
}

post_upgrade() {
    if [[ "$LANG" == "zh_CN.UTF-8" ]]; then
        note "重载 ${_pkgname} systemd 配置：\"sudo systemctl daemon-reload\" ...
          重启 ${_pkgname} 服务：\"sudo systemctl restart ${_pkgname}.service\" ..."
    else
        note "Reload systemd manager configuration: \"sudo systemctl daemon-reload\" ...
          Restart ${_pkgname} daemon service:\"sudo systemctl restart ${_pkgname}.service\" ..."
    fi
}

post_remove() {
    rm -rf /opt/$_pkgname/
    if [[ "$LANG" == "zh_CN.UTF-8" ]]; then
        note "${_pkgname} 的配置文件和镜像文件残留在 \"/var/lib/${_pkgname}\"，
          日志文件残留在 \"/var/log/iventoy\"，如果需要，请手动删除它们..."
    else
        note "The configuration files and image files of ${_pkgname} are left in \"/var/lib/${_pkgname}\",
          and the log files are left in \"/var/log/${_pkgname}\" ...
          If necessary, please manually delete them ..."
    fi
}
