
This is a bash script for uploading hugo public folder to server automatically.
English | 中文文档
You need to pre-install some tools on your own computer
Please make sure you have installed some basic ones like SSH, SCP which will not be mentioned related installation and usage.
sshpass will make you feel relaxed when inputting password required, that we gonna impose in the script.
You can install by yourself or following this tutorial
Since I am using macOS, here's the simple way to install on it.
homebrew has forbade installing the sshpass by default, whereas we can install the unofficial brew package for it.
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
You can find sshpass.rb here
Download publi.sh
Modify variables to your own:
hugoRoot='/Users/xxxxxx/hugo/blog/' # your local hugo website root
publicFolder='/Users/xxxxxx/hugo/blog/public' # your hugo website PUBLIC root
zipName='Archive.zip' # the zip name
zipLoc=$publicFolder/$zipName # No need to change
hostname='xxx.xxx.xxx.xxx' # server address
upTo='/www/wwwroot/webxxx' # the root of the website on server
The ssh login is root by default, you may need to change it by yourself.
When you run the script the hugo will generate the public files. There's no need to hugo again.
I take the simple way to update the website which means the script only upload files without checking the files may needed be removed.
Generally, the script do:
- Generate Hugo public files
- Compress the public files in one file
- Upload the zip package
- Decompress the zip and Delete it
and not do:
- Check files iteration, it just covers the same file.
- Do nothing with files exists.
For security I set ssh password shall be entered every execution.
Of course, you can set a variable named sshpw at the front of script, and comment out line 26 ~ 29 .
I found somehow it generated __MACOSX in the zip file. Hence I remove it after uploadding by line 42 rmdir __MACOSX
Perhaps it's not right command because failure occurs when the folder is not empty, using rm -rf __MACOSX is better.
But it's not a really issuse so I ignored even as you can just remove this command.