I would like to start this post by saying I’m not that bright. Further, there are way, way, way brighter people, of whom you should be following their blog. However, for what it is worth, this is my script for automagically updating my clickable app for Ubuntu Touch. You can take it and use it however you see fit.

In particular, the jq arguments for json editing on the fly with variables might be useful to others.


# Go to my downloads folder.
cd ~/Downloads/

# Remove any updating folder.
rm -rf ./updating

# Create and enter the updating folder.
mkdir updating
cd ./updating

# Use wget to procure the updated zip file.
wget http://thebookwurm.com/the_book.zip

# Unzip the zip file.
unzip ./the_book.zip 

# Remove the zip file.
rm the_book.zip 

# Clone the repository.
git clone https://gitlab.com/alaskalinuxuser/app_ubport_thebookwurm.git

# Enter the repository.
cd app_ubport_thebookwurm/www

# Move the new readme and htm file.
mv ../../readme.txt ./
mv ../../go_book.htm ./

# Remove the web folder for the book.
rm -rf the_book

# Copy the new web folder for the book.
cp -Rav ../../the_book ./

# Go up one directory.
cd ..

# Export today's date.
export today="$(date '+%Y%m%d')"
echo $today

# Use today's date and update the version number with jq.
jq --arg today $today '.version |= $today' ./manifest.json |tee ./temp.json
cat temp.json 
mv temp.json ./manifest.json
rm ./temp.json

# Run clickable to build the latest version.

# Move the built updated file to the Downloads directory.
cp ./build/all/app/*.click ~/Downloads/

# Update the repository automatically-ish
git status
git add .
git commit -m "Updated " -m "$today"
# You will be prompted for the password.
git push

# Go to the downloads folder.
cd ~/Downloads/
# Remove any updating folder.
rm -rf ./updating

# And gracefully exit.
exit 0

Jq, by default just outputs the modified json text to the stdout, so it doesn’t actually edit the file itself. You could use stdin with cat or something, but I like using tee to display the output and put it into a file that I then move over the original, but that’s just me.

This allows me to *just about* completely automate the building and updating process for a web app that I maintain on Ubuntu Touch. I would like to note that the website maintainer updates the content of the website that my web app captures, and I use this by permission for folks on Ubuntu Touch who want the Bible and resources available in a web app form without having to burn data to access them.

So far, this works pretty well. The date variable stored as $today is useful for the version number since I put it in a YYYYMMDD format, always ensuring that it increments upwards over time. This is also useful for the commit message which will read “Updated ” and if on Gitlab/hub, you press the three dots (…) to see the date.

It is not completely automated, since I have to type my password and username, however, if you use ssh keys, you could completely automated this, or you can pass your login credentials via plain text (which is a really bad idea) with:

git push https://username:password@myrepository --all

But I don’t prefer to do that. I would also note that it will store username and password in plaintext in the git configuration, supposedly, which is also another good reason not to do that.

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *