2012-01-24 20:35:16 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# import_srpm.sh: Import SRPM packages to git repo
|
|
|
|
|
|
|
|
# Input data
|
|
|
|
srpm_path=$1
|
|
|
|
git_path=$2
|
|
|
|
git_branch=$3
|
2012-01-24 21:25:16 +00:00
|
|
|
name=$(rpm -q --qf '[%{Name}]' -p $srpm_path)
|
2012-08-07 21:23:30 +01:00
|
|
|
version=$(rpm -q --qf '[%{Version}-%{Release}]' -p $srpm_path)
|
2012-01-24 21:25:16 +00:00
|
|
|
tmp_dir=/tmp/$name-$version-$RANDOM
|
2012-01-24 20:35:16 +00:00
|
|
|
|
|
|
|
# Clone destination repo
|
|
|
|
mkdir -p $tmp_dir
|
|
|
|
git clone $git_path $tmp_dir
|
|
|
|
|
|
|
|
# Switch to import branch
|
|
|
|
cd $tmp_dir
|
|
|
|
git branch --track $git_branch origin/$git_branch # Try track remote
|
|
|
|
git branch $git_branch # Try create local
|
|
|
|
git checkout $git_branch
|
|
|
|
|
|
|
|
# Remove all files except .git
|
|
|
|
rm -rf $tmp_dir/*
|
|
|
|
mv $tmp_dir/.git $tmp_dir/git
|
|
|
|
rm -rf $tmp_dir/.*
|
|
|
|
mv $tmp_dir/git $tmp_dir/.git
|
|
|
|
|
|
|
|
# Unpack srpm
|
|
|
|
rpm2cpio $srpm_path > srpm.cpio
|
|
|
|
cpio -idv < srpm.cpio
|
|
|
|
rm -f srpm.cpio
|
|
|
|
|
|
|
|
# Commit and push changes
|
|
|
|
git add -A .
|
2012-01-30 16:23:10 +00:00
|
|
|
git commit -m "Automatic import for version $version"
|
|
|
|
git branch $git_branch # Ensure branch exists
|
|
|
|
git push origin master $git_branch
|
2012-01-24 20:35:16 +00:00
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
rm -rf $tmp_dir
|