#!/bin/bash

TS=$(date +20%y%m%d-%H%M%S)

HOSHINOVA_PATH='/root/hoshinova'
HOSHINOVA_BIN_PATH="${HOSHINOVA_PATH}/bin"

npm i -g npm yarn node-gyp && \
cd "${HOSHINOVA_PATH}" && \
git pull && \
cargo test && \
cd "${HOSHINOVA_PATH}/web" && \
rm -f "${HOSHINOVA_PATH}/web/yarn.lock" && \
yarn && \
yarn build && \
cd "${HOSHINOVA_PATH}/web" && \
cargo build && \
cp -p "${HOSHINOVA_PATH}/target/debug/hoshinova" "${HOSHINOVA_BIN_PATH}/hoshinova_${TS}" && \
rm -f "${HOSHINOVA_BIN_PATH}/hoshinova" && \
ln -s "${HOSHINOVA_BIN_PATH}/hoshinova_${TS}" "${HOSHINOVA_BIN_PATH}/hoshinova" && \
systemctl restart hoshinova.service
