const util = require("util");
const pkg = require("./package.json");
const exec = util.promisify(require("child_process").exec);

const argv = require("yargs").options({
  b: {
    alias: "beta",
    describe: "密码",
    type: "boolean",
    default: false,
  },
}).argv;

const beta = argv.beta;

const fullFileName = `${pkg.name}-v${pkg.version}${beta ? "-beta" : ""}.tar.gz`;
const fileName = `${pkg.name}${beta ? "-beta" : ""}.tar.gz`;

(async function () {
  try {
    console.log("上传到 nas");

    // await exec(
    //   `scp -P 5022 dist/RaspiCar.tar.gz itiwll@192.168.50.2:/volume1/web/RaspiCar/download/${fileName}`
    // );

    // await exec(
    //   `scp -P 5022 dist/RaspiCar.tar.gz itiwll@192.168.50.2:/volume1/web/RaspiCar/download/${fullFileName}`
    // );

    console.log("上传 一键安装脚本");

    await exec(
      `scp -P 29168 ./install.sh root@download.esonwong.com:/www/download/RaspiCar/install.sh`
    );

    console.log(`上传 ${fileName} 到 download.esonwong.com`);

    await exec(
      `scp -P 29168 dist/RaspiCar.tar.gz root@download.esonwong.com:/www/download/RaspiCar/${fileName}`
    );

    console.log(`上传 ${fullFileName} 到 download.esonwong.com`);

    await exec(
      `scp -P 29168 dist/RaspiCar.tar.gz root@download.esonwong.com:/www/download/RaspiCar/${fullFileName}`
    );
  } catch (e) {
    console.error(e);
  }
})();
