#!/bin/bash
#url="https://vault.centos.org/8.3.2011/infra/Source/buildtools-common/pygobject3-3.38.0-3.el8.src.rpm"
url=$1
file_name=$2
REPO=`echo $1 | awk -F "/" '{print $1}'`
rm -rf ~/rpmbuild/SOURCES/*
rm -rf ~/rpmbuild/SPECS/*
rpm -ivh $url
if [ -z $file_name ]
then
	file_name=`ls ~/rpmbuild/SPECS/ | awk -F "." '{print $1}'`
else
	file_name=$file_name
fi
echo "url=$url"
echo "init file:$file_name"

echo 'git clone "ssh://houfangdong@10.40.41.24:29418/$file_name" && scp -p -P 29418 houfangdong@10.40.41.24:hooks/commit-msg "$file_name/.git/hooks/"'
git clone "ssh://houfangdong@10.40.41.24:29418/$REPO/$file_name" && scp -p -P 29418 houfangdong@10.40.41.24:hooks/commit-msg "$file_name/.git/hooks/"
if [ $? -ne 0 ]
then
	echo "git clone error!!!"
	exit 1
fi

cd $file_name

git checkout remotes/origin/lns8.4 -b lns8.4

rm -rf project.config

if [ `ls | wc -l` -ne 0 ]
then
    read -p "init force(y) ?" input
    if [ $input != y ]
    then	
        echo $file_name >> faile_init.txt
        exit 1
    fi
fi
cp -r ~/rpmbuild/SOURCES/ .
cp -r ~/rpmbuild/SPECS/ .

wget ftp://10.2.5.21/os/.5000_push.sh.x

chmod 755 .5000_push.sh.x

./.5000_push.sh.x $file_name

if [ `ls SOURCES | wc -l` -eq 0 ]
then
    touch SOURCES/.gitkeep
fi
git add .
git commit -m "init $file_name"
git push origin HEAD:refs/for/lns8.4
sync
