#!/bin/bash
set -eu

KEY="$HOME/.ssh/$USER"
FILE="$1"; [[ ! -f "$FILE" ]] && echo "Please gimme a file :drool:" && exit 1

crc32="$(rhash --printf="%c" "$FILE")"
filename="$(basename -- "$FILE")"
extension="${filename##*.}"
filename="${filename%.*}"

scp -i "$KEY" "$FILE" "$USER@msozod.moe:/var/www/msozod.moe/upload/~$USER/${filename}_${crc32}.${extension}"
ssh -i "$KEY" "$USER@msozod.moe" "/usr/local/bin/gen_html"

