6 Commits

2 changed files with 18 additions and 17 deletions

View File

@ -1,16 +1,17 @@
# Octozipo
<h2><img align="middle" src="https://raw.githubusercontent.com/odb/official-bash-logo/master/assets/Logos/Icons/PNG/64x64.png" >
Octozipo - Convert Zip package to a repository.
</h2>
Written by Llewellyn van der Merwe (@llewellynvdm)
Convert Zip packages to repositories and if they exist update and tag them.
Linted by [#ShellCheck](https://github.com/koalaman/shellcheck)
## Install
## Get needed access token
Get a token from [https://git.vdm.dev/user/settings/applications](https://git.vdm.dev/user/settings/applications)
```shell
$ export SETUP_TOKEN="xxxxxxxxxxtokenxxxxxxxxxxxxxxxxxxxxxxxx"
$ sudo curl -L "https://git.vdm.dev/api/v1/repos/octoleo/octozipo/raw/src/octozipo?access_token=${SETUP_TOKEN}" -o /usr/local/bin/octozipo
$ sudo curl -L "https://git.vdm.dev/api/v1/repos/octoleo/octozipo/raw/src/octozipo" -o /usr/local/bin/octozipo
$ sudo chmod +x /usr/local/bin/octozipo
```
- Global **environment** file can be set at: `/home/$USER/.config/octozipo/.env`

View File

@ -3,7 +3,7 @@
# Program name
PROGRAM_NAME="Octozipo"
PROGRAM_CODE="octozipo"
PROGRAM_VERSION="2.2.3"
PROGRAM_VERSION="2.2.7"
PROGRAM_V="2.2"
# PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}"
@ -84,7 +84,7 @@ main() {
# get the package details
getPackageDetails "${zip_name}" "${folder_name}"
# check if the repo exist on our system
if git ls-remote --exit-code --heads "git@${VDM_GIT_URL}:${VDM_ORG}/${VDM_REPO_NAME}.git" "${VDM_REPO_BRANCH}" -q >/dev/null 2>&1; then
if git ls-remote --exit-code --heads "git@${VDM_GIT_URL}:${VDM_ORG}/${VDM_REPO_NAME}.git" "${VDM_REPO_BRANCH}" >/dev/null 2>&1; then
# check if repo is locally found
cd "${VDM_PATH_REPO}" >/dev/null 2>&1 || {
git clone "git@${VDM_GIT_URL}:${VDM_ORG}/${VDM_REPO_NAME}.git" \
@ -663,22 +663,22 @@ function getGitCommitComment() {
if [ -z "$current_version" ]; then
message="Update"
# If tag already exist
elif git tag -l "$current_version" | grep -q "^$current_version$"; then
message="Update on $current_version (beta for next version)\n\nHere's an update on the current version, which includes changes towards the next release still in beta."
elif git rev-parse --is-inside-work-tree > /dev/null 2>&1 && git tag -l "$current_version" | grep -q "^$current_version$"; then
message="Update on $current_version (changes towards the next release)\n\nHere's an update on the current version, which includes changes towards the next release still in development."
# if file path exist and the tag was never set before
elif [ -f "${file_path}" ]; then
# Use grep to find the line number of the first heading/version
version_line=$(grep -n "^#" "$file_path" | head -n 1 | cut -d: -f1)
# Extract the first heading/version and assign it to a variable
version=$(sed -n "${version_line}p" "$file_path" | sed -e 's/^#\+ *//' -e 's/^[[:space:]]*//' -e 's/^-* \?//' -e 's/[[:space:]]*$//')
# Use sed to extract the message lines after the first header, but stop at the next header or an empty line
message_lines=$(sed -n "$((version_line + 1)),$ p" "$file_path" | awk '/^#/{exit} /^[[:space:]]*$/{exit} {print}')
# Use awk to extract the message lines after the first header, but stop at the next header or an empty line
message_lines=$(awk -v start=$((version_line + 1)) 'NR > start && (/^#/ || !NF) {exit} NR > start {print}' "$file_path")
cleaned_lines=$(echo "$message_lines" | sed -e '/^[[:space:]]*$/d' -e 's/^[[:space:]]*//' -e 's/^-* \?//' -e 's/[[:space:]]*$//' -e 's/\.*$//' )
formatted_lines=$(echo "$cleaned_lines" | awk '{printf "%s%s",(NR>1?". ":""),$0} END{printf ".\n"}')
# check if this is the same version as the current version
if [ "$current_version" = "$version" ]; then
message="Stable release of ${current_version}\n\n${formatted_lines}"
message="Release of ${current_version}\n\n${formatted_lines}"
fi
fi
@ -806,7 +806,7 @@ function getVersionNumberByFile() {
function rightStrip() {
# Usage: rightStrip "string" "pattern"
printf '%s\n' "${1%%$2}"
printf '%s\n' "${1%%"$2"}"
}
# leftStrip - Removes the specified pattern from the start of a string
@ -824,7 +824,7 @@ function rightStrip() {
# The modified string with the pattern removed from the start
function leftStrip() {
# Usage: leftStrip "string" "pattern"
printf '%s\n' "${1##$2}"
printf '%s\n' "${1##"$2"}"
}
# This function unzips the package located in the `VDM_ZIP_DIR` directory to the specified folder.
@ -934,7 +934,7 @@ function runUpdate() {
sudo mv "/usr/local/bin/${PROGRAM_CODE}" "/usr/local/bin/${PROGRAM_CODE}.bak"
fi
# pull the latest version. Master is always the latest
if sudo curl --fail -L "https://git.vdm.dev/api/v1/repos/octoleo/${PROGRAM_CODE}/raw/src/${PROGRAM_CODE}?ref=${branch:-master}&access_token=${VDM_ACCESS_TOKEN}" -o "/usr/local/bin/${PROGRAM_CODE}" 2>/dev/null; then
if sudo curl --fail -H "Authorization: token ${VDM_ACCESS_TOKEN}" -L "https://git.vdm.dev/api/v1/repos/octoleo/${PROGRAM_CODE}/raw/src/${PROGRAM_CODE}?ref=${branch:-master}" -o "/usr/local/bin/${PROGRAM_CODE}" 2>/dev/null; then
# give success message
_echo "[success] Update was successful."
# do we have a backup