Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # sudo apt install devscripts ubuntu-dev-tools git-remote-bzr
- #
- project="$1"
- merge_version="$2"
- if [ -z "$project" ]; then
- echo "Provide project name to import"
- echo " $(basename $0) <project> [debian_merge_version]"
- exit 1
- fi
- declare -A ubuntu_aliases=(["gdm"]="gdm3"
- ["gtk"]="gtk+3.0"
- ["vte"]="vte2.91")
- declare -A ubuntu_bzr_aliases=(["gnome-calculator"]="gcalctool")
- declare -A ubuntu_bzr_sufix_aliases=(["vte"]="-vte2.91"
- ["gtk"]="gtk3")
- declare -A debian_team=(["empathy"]="telepathy-team"
- ["simple-scan"]="debian")
- declare -A debian_aliases=(["vte"]="vte2.91"
- ["gtk"]="gtk3")
- source="$project"
- debsource="$project"
- bzr_repo=$project
- debian_team="gnome-team"
- launchpad_owner="ubuntu-desktop"
- if [ -n "${ubuntu_aliases[$project]}" ]; then
- source="${ubuntu_aliases[$project]}"
- fi
- if [ -n "${debian_aliases[$project]}" ]; then
- debsource="${debian_aliases[$project]}"
- fi
- if [ -n "${debian_team[$project]}" ]; then
- debian_team="${debian_team[$project]}"
- fi
- if [ -n "${ubuntu_bzr_aliases[$project]}" ]; then
- bzr_repo="${ubuntu_bzr_aliases[$project]}"
- fi
- if [ -n "$LAUNCHPAD_OWNER" ]; then
- launchpad_owner="$LAUNCHPAD_OWNER"
- fi
- set -xe
- export GIT_PAGER=''
- if [ ! -d $source/.git ]; then
- gbp clone git@salsa.debian.org:$debian_team/$debsource.git $source --postclone="git remote rename origin salsa"
- fi
- cd $source
- git remote add -f gnome git@gitlab.gnome.org:GNOME/$project.git
- git remote add origin "lp:~$launchpad_owner/ubuntu/+source/$source"
- git config push.followTags true
- last_distro=$(ubuntu-distro-info --latest)
- IFS=" | " project_db=($(rmadison -s "$last_distro"{,-{proposed,backports,updates,security}} "$source"))
- unset IFS
- if [ "${#project_db[@]}" -gt 2 ]; then
- last_version="${project_db[1]}"
- if [[ "$last_version" =~ ^[0-9]+: ]]; then
- last_version="$(echo "$last_version" | cut -d: -f2)"
- has_epoch=true
- fi
- component=$(echo "${project_db[2]}" | cut -d/ -f2)
- if [ "$component" == "$last_distro" ]; then
- component="main"
- fi
- fi
- if [ -z "$merge_version" ]; then
- if [ -n "$last_version" ]; then
- if [[ "$project" == lib* ]]; then
- intial=${project:0:4}
- else
- intial=${project:0:1}
- fi
- project_changelog=$(wget -O - \
- http://changelogs.ubuntu.com/changelogs/pool/$component/$intial/$source/${source}_${last_version}/changelog);
- if [ -n "$project_changelog" ]; then
- for ((i = 0; ; i += 1)); do
- version="$(echo "$project_changelog" | dpkg-parsechangelog -l - -S Version -o $i -c 1)";
- if [[ "$version" =~ -[0-9]+ubuntu[0-9]+ ]]; then
- continue
- elif [[ "$version" =~ -[0-9]+$ ]]; then
- merge_version=$version
- echo "Last debian version found at $version (salsa tag is debian/${version/:/%})"
- break
- elif [ -z "$version" ]; then
- break;
- fi
- done
- fi
- fi
- if [ -z "$merge_version" ]; then
- echo "Impossible to find debian fork, please provide it as script parameter"
- exit 1
- fi
- fi
- # checkout to the latest debian merge and move as ubuntu/master
- merge_tag=${merge_version/:/%}
- git checkout -b ubuntu/master "debian/$merge_tag"
- bzr_uri="lp:~ubuntu-desktop/$bzr_repo/ubuntu${ubuntu_bzr_sufix_aliases[$project]}"
- bzr_repo_uri="bzr::$bzr_uri"
- if [ "$has_epoch" == true ]; then
- # while read -r line; do
- # tag="$(echo "${line/:/%}" | sed -n "s,\([a-f0-9]\+\) releasing package $source version \(.*[0-9]\+ubuntu[0-9]\+.*\),\2 \1,p")"
- # [ -n "$tag" ] && ! git show-ref $tag &> /dev/null && git tag $tag
- # done < <(git log ubuntu-bzr/master --oneline)
- ubuntu_bzr_repo=$(mktemp --suffix="-$project-ubuntu-bzr-repo" --dry-run)
- bzr branch "$bzr_uri" "$ubuntu_bzr_repo"
- bzr_repo_uri="$ubuntu_bzr_repo"
- (
- cd "$bzr_repo_uri"
- git init
- bzr fast-export --plain --rewrite-tag-names . | git fast-import
- for t in $(git tag); do
- if [[ "$t" =~ ^[0-9]+_ ]]; then
- if git tag "$(echo "$t" | sed "s,^\([0-9]\+\)_,\1%,")" "$t"; then
- git tag -d "$t"
- fi
- fi
- done
- )
- fi
- git remote add ubuntu-bzr "$bzr_repo_uri"
- git fetch ubuntu-bzr
- # for t in $(git tag -l '[0-9]*[0-9]ubuntu[0-9]*'); do git tag "ubuntu/$t" "$t"; git tag -d "$t"; done
- for t in $(git tag --merged ubuntu-bzr/master); do
- if git tag "ubuntu/$t" "$t"; then
- git tag -d "$t"
- fi
- done
- git merge -s ours --no-commit ubuntu-bzr/master --allow-unrelated-histories
- git rm -rf --ignore-unmatch debian
- git read-tree --prefix=/ -u ubuntu-bzr/master
- git rm -rf --ignore-unmatch .bzr*
- git commit -m "Importing $bzr_uri"
- # Since we want to import a dsc now, we need to remove the tag it already provides or gbp will complain
- last_tag=$(git describe --tags --abbrev=0 ubuntu-bzr/master)
- # last_version="$(echo "${last_tag//%/:}" | cut -f2 -d/)"
- # git tag ubuntu/bzr-last-release "$last_tag"
- bzr_last_release="$last_tag-bzr"
- git tag "$bzr_last_release" "$last_tag"
- git tag -d "$last_tag"
- dsc_dir="$(mktemp -d --suffix="-$project-lp-source")"
- dsc_file="$dsc_dir/${source}_$(echo "$last_version" | sed "s,^[0-9]\+:,,").dsc"
- (cd "$dsc_dir" && pull-lp-source -d --no-conf "$source" "$last_version")
- if ! [ -e "$dsc_file" ]; then
- echo "No $dsc_file found, please download it for $source $last_version"
- exit 1
- fi
- if [ "$(git branch --remote --list 'salsa/upstream' | wc -l)" -gt 0 ]; then
- upstream_branch="upstream"
- else
- upstream_branch="upstream/latest"
- last_packaged_version=$(echo "$last_version" | cut -d'-' -f1)
- last_packaged_major_version=$(echo "$last_packaged_version" | cut -d. -f-2)
- last_upstream_version=$(git describe --tags --abbrev=0 upstream/latest | cut -d'/' -f2)
- last_upstream_major_version=$(echo "$last_upstream_version" | cut -d. -f-2)
- if dpkg --compare-versions "$last_packaged_major_version" lt "$last_upstream_major_version"; then
- upstream_branch="upstream/${last_packaged_major_version}.x"
- fi
- if ! git branch --remote --list 'salsa/*' | grep -qs "$upstream_branch"; then
- echo "$project expects to use $upstream_branch as branch, but that can't be found."
- echo "Please, make sure that salsa has it, or import the orig to generate that."
- exit 1
- fi
- fi
- gbp import-dsc --debian-branch=ubuntu/master --debian-tag='ubuntu/%(version)s' --upstream-branch="$upstream_branch" "$dsc_file"
- cat << EOF > debian/gbp.conf
- [DEFAULT]
- debian-branch=ubuntu/master
- upstream-branch=$upstream_branch
- debian-tag=ubuntu/%(version)s
- upstream-vcs-tag=%(version)s
- pristine-tar=True
- EOF
- git add debian/gbp.conf
- git commit debian/gbp.conf -m "Add debian/gbp.conf with ubuntu settings"
- set +e
- read -r -d '' VCS <<EOF
- XS-Debian-Vcs-Browser: https://salsa.debian.org/$debian_team/$project
- XS-Debian-Vcs-Git: https://salsa.debian.org/$debian_team/$project
- Vcs-Browser: https://git.launchpad.net/~ubuntu-desktop/ubuntu/+source/$project
- Vcs-Git: https://git.launchpad.net/~ubuntu-desktop/ubuntu/+source/$project
- EOF
- set -e
- # VCS="$(echo "$VCS" | sed -e 's/[\/&]/\\&/g')"
- # VCS="$(echo "$VCS" | awk -vORS="\\\n" '1')"
- # sed "s,^Vcs-Bzr:.*,$VCS,g" -i debian/control*
- for ctrl in debian/control*; do
- awk -v r="$VCS" '{gsub(/^Vcs-Bzr:.*/,r)}1' $ctrl > $ctrl.tmp
- mv $ctrl.tmp $ctrl
- done
- if [ -n "$(git --no-pager diff)" ]; then
- git commit debian/control* -m "debian/control*: update VCS informations"
- fi
- for commit in $(git log "$bzr_last_release"..ubuntu-bzr/master --reverse --format=format:%H); do
- if ! git format-patch --stdout $commit | git am -3; then
- echo "Failed to re-apply bzr-change"
- git show $commit --shortstat
- git am --abort
- continue
- fi
- # if ! git show $commit | git apply -3; then
- # echo "Failed to re-apply bzr-change"
- # git show $commit --shortstat
- # continue
- # fi
- # if [ -n "$(git diff --cached)" ]; then
- # git commit -C $commit
- # fi
- done
- git remote prune ubuntu-bzr
- git remote remove ubuntu-bzr
- git gc --prune=now --aggressive
- if [ -n "$ubuntu_bzr_repo" ] && [ -d "$ubuntu_bzr_repo" ]; then
- rm -rf "$ubuntu_bzr_repo"
- fi
- if [ -n "$dsc_dir" ] && [ -d "$dsc_dir" ]; then
- rm -rf "$dsc_dir"
- fi
- # # Create local branches
- # git checkout "$upstream_branch"
- # git checkout pristine-tar
- # git checkout ubuntu/master
- # # gbp push --verbose origin
- # git push -u origin ubuntu/master
- # git push -u origin "$upstream_branch"
- # git push -u origin pristine-tar
- # git tag | grep -E "^ubuntu/|^debian/|^upstream/" | xargs --no-run-if-empty git push origin
- # Remove unused tags
- # git tag | grep -Ev "^ubuntu/|^debian/|^upstream/" | xargs --no-run-if-empty git push --delete
- (cd .. && touch $project.DONE)
- # If the debian upstream/latest is more updated and you want to improt a new tarball....
- # git tag -d upstream/3.28.2
- # you might want to `git commit --amend`` now to remove the extra lines added to the changelog, but in that case you should update the last tag (ubuntu/3.28.1-0ubuntu2 in this example) to HEAD
- # and `git gc --aggressive` as per git bzr usage.
- # Set gbp.conf
- ### Importing upstream revision to ubuntu branch
- # gbp import-orig --uscan
- ## Rename debianv ersione before release
- exit $?
- N=5
- (
- for e in cheese empathy file-roller gdm gedit gnome-calculator gnome-control-center gnome-keyring gnome-menus gnome-screensaver gnome-session gnome-settings-daemon gnome-shell gnome-software gnome-terminal gnome-themes-extra gtk rhythmbox simple-scan totem vino; do
- ((i=i%N)); ((i++==0)) && wait
- env LAUNCHPAD_OWNER=canonical-desktop-team script -f -a -c "bash /data/GNOME/ubuntu-git-importer/importer.sh $e" $e.log &
- done
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement