LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File create-source-archive.sh of Package rubyripper (Project home:Warhammer40k:stuff)

#!/bin/bash
#

git_commit_fallback="1ca0202c7bc0562ad4845f605c8e2216c4942220"
git_commit="$1"
name="rubyripper"
git_remote="https://github.com/bleskodev/rubyripper.git"

script_dir="$( cd "$( dirname "$0" )" && pwd )"
repo_dir="$name-tmp"
[[ -z $git_commit ]] && git_commit="$git_commit_fallback"

check_errors () {
 local status="$?"
 if [ "$status" != "0" ]; then
  echo "ERROR: script failed!"
  exit 1
 fi
}

cd "$script_dir" && mkdir -p "$repo_dir" && cd "$repo_dir"
check_errors
git init
check_errors
git remote add ext "$git_remote"
check_errors

echo "fetching"

git fetch -f --all
check_errors

git checkout -f "$git_commit" || git_commit_failed="true"

if [[ $git_commit_failed = true ]]; then
  echo "failed to checkout requested commit, trying to use branch $git_commit instead"
  git branch -f "temp" "ext/$git_commit"
  check_errors
  git checkout -f "temp"
  check_errors
  git_commit=`git rev-parse HEAD`
fi

cdate=`git show -s --format=%ci $git_commit | cut -d' ' -f 1 | sed 's|-|.|g'`
hash=`git show -s --format=%h $git_commit`
repo_dir_r="$name-$cdate.git.$hash"

git submodule update --init
check_errors

rm -rf .git
check_errors

rm -f .gitattributes
check_errors

rm -f .gitignore
check_errors

rm -f .gitmodules
check_errors

cd "$script_dir"
check_errors

mv "$repo_dir" "$repo_dir_r"
check_errors

tar cf "$repo_dir_r.tar" "$repo_dir_r" --owner=0 --group=0
check_errors

xz -9e "$repo_dir_r.tar"
check_errors

rm -rf "$repo_dir_r"
check_errors