stages:
  - deploy

deploy-job:
  stage: deploy
  image: ubuntu:latest
  before_script:
    - apt-get update
    - apt-get install -y rsync openssh-client hugo git sshpass

  script:
    - ls
    - git submodule foreach --recursive git reset --hard && git submodule init && git submodule update --recursive
    - hugo
    - mkdir ~/.ssh
    - ssh-keyscan -p 69 fzorb.xyz >> ~/.ssh/known_hosts
    - sshpass -p "$PASSWD" ssh -p 69 git@fzorb.xyz "rm -rf /var/www/fzorb.xyz/*"
    - sshpass -p "$PASSWD" rsync -avzh ./public -e 'ssh -p 69' git@fzorb.xyz:/var/www/fzorb.xyz
    - sshpass -p "$PASSWD" ssh -p 69 git@fzorb.xyz "mv /var/www/fzorb.xyz/public/* /var/www/fzorb.xyz"
    - sshpass -p "$PASSWD" ssh -p 69 git@fzorb.xyz "rm -rf /var/www/fzorb.xyz/public"

  only:
    - main
