Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to download the latest official FOSSCAD repo #14

Open
blackfuel opened this issue Aug 2, 2018 · 3 comments
Open

Script to download the latest official FOSSCAD repo #14

blackfuel opened this issue Aug 2, 2018 · 3 comments

Comments

@blackfuel
Copy link

blackfuel commented Aug 2, 2018

Simple Linux script to download the latest official FOSSCAD repo to a local file for backup and mirror support, or for distribution purposes.

Downloaded files are named by the current FOSSCAD release version and the git commit hash, while retaining the git commit timestamp on the file itself. I run it once a month using cron, just in case. :)

fosscad-download.sh

#!/bin/sh
# fosscad-download.sh
# Download the latest official FOSSCAD repository to a local file, for distribution purposes. Compressed archive is prepared by the Github site and downloaded by this script.

set -e
set -x

VERSION=$(wget -q -O - https://raw.githubusercontent.com/maduce/fosscad-repo/master/README.md | grep -A 3 "# Version" | grep -E '\*\s+[0-9]+\.[0-9]+\s+.*' | sed -r 's/\*\s+([0-9]+\.[0-9]+)\s+.*$/\1/')
[ -z "$VERSION" ] && echo "cannot retrieve the release version number" && exit 1

SOURCE_VERSION=$(wget -q -O - https://api.github.com/repos/maduce/fosscad-repo/git/refs/heads/master | grep -A 4 '"object": {' | grep '"sha":' | cut -d'"' -f4)
[ -z "$SOURCE_VERSION" ] && echo "cannot retrieve the git commit hash" && exit 1

SOURCE_TIMESTAMP_X=$(wget -q -O - https://api.github.com/repos/maduce/fosscad-repo/git/commits/${SOURCE_VERSION} | grep -A 4 '"author": {' | grep '"date":' | cut -d'"' -f4)
SOURCE_TIMESTAMP=$(date -u +@%s -d "$SOURCE_TIMESTAMP_X" 2>/dev/null || date -u +@%s -D %Y-%m-%dT%H:%M:%S%Z -d "$SOURCE_TIMESTAMP_X")

FILENAME="FOSSCAD_MEGA_PACK_v${VERSION}+git-${SOURCE_VERSION}"

[ ! -f ${FILENAME}.zip ] && wget -O ${FILENAME}.zip https://github.com/maduce/fosscad-repo/archive/master.zip && touch -d $SOURCE_TIMESTAMP ${FILENAME}.zip

### [ ! -f ${FILENAME}.tar.gz ] && wget -O ${FILENAME}.tar.gz https://github.com/maduce/fosscad-repo/archive/master.tar.gz && touch -d $SOURCE_TIMESTAMP ${FILENAME}.tar.gz
@maduce
Copy link
Owner

maduce commented Aug 9, 2018

This is a lovely script but if you have bash you can get git. Doesn't git defeat the purpose of this script, i.e., git pull?

@blackfuel
Copy link
Author

Yes, git is the best way to stay in sync with the fosscad repo, for desktop computer users.

However, this script can be run on devices with limited system resources that are unable to run the git client or perform data compression on a large archive. This script is run automatically on my home router/NAS. So, if a guy doesn't have the git client, this script would be the next best alternative.

@maduce
Copy link
Owner

maduce commented Mar 21, 2019

Good point and fabulous work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants