Advertisement
3v1n0

importer.sh

Jun 29th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.40 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # sudo apt install devscripts ubuntu-dev-tools git-remote-bzr
  4. #
  5.  
  6. project="$1"
  7. merge_version="$2"
  8.  
  9. if [ -z "$project" ]; then
  10. echo "Provide project name to import"
  11. echo " $(basename $0) <project> [debian_merge_version]"
  12. exit 1
  13. fi
  14.  
  15. declare -A ubuntu_aliases=(["gdm"]="gdm3"
  16. ["gtk"]="gtk+3.0"
  17. ["vte"]="vte2.91")
  18. declare -A ubuntu_bzr_aliases=(["gnome-calculator"]="gcalctool")
  19. declare -A ubuntu_bzr_sufix_aliases=(["vte"]="-vte2.91"
  20. ["gtk"]="gtk3")
  21. declare -A debian_team=(["empathy"]="telepathy-team"
  22. ["simple-scan"]="debian")
  23. declare -A debian_aliases=(["vte"]="vte2.91"
  24. ["gtk"]="gtk3")
  25.  
  26. source="$project"
  27. debsource="$project"
  28. bzr_repo=$project
  29. debian_team="gnome-team"
  30. launchpad_owner="ubuntu-desktop"
  31.  
  32. if [ -n "${ubuntu_aliases[$project]}" ]; then
  33. source="${ubuntu_aliases[$project]}"
  34. fi
  35.  
  36. if [ -n "${debian_aliases[$project]}" ]; then
  37. debsource="${debian_aliases[$project]}"
  38. fi
  39.  
  40. if [ -n "${debian_team[$project]}" ]; then
  41. debian_team="${debian_team[$project]}"
  42. fi
  43.  
  44. if [ -n "${ubuntu_bzr_aliases[$project]}" ]; then
  45. bzr_repo="${ubuntu_bzr_aliases[$project]}"
  46. fi
  47.  
  48. if [ -n "$LAUNCHPAD_OWNER" ]; then
  49. launchpad_owner="$LAUNCHPAD_OWNER"
  50. fi
  51.  
  52. set -xe
  53. export GIT_PAGER=''
  54.  
  55. if [ ! -d $source/.git ]; then
  56. gbp clone git@salsa.debian.org:$debian_team/$debsource.git $source --postclone="git remote rename origin salsa"
  57. fi
  58.  
  59. cd $source
  60.  
  61. git remote add -f gnome git@gitlab.gnome.org:GNOME/$project.git
  62. git remote add origin "lp:~$launchpad_owner/ubuntu/+source/$source"
  63. git config push.followTags true
  64.  
  65. last_distro=$(ubuntu-distro-info --latest)
  66. IFS=" | " project_db=($(rmadison -s "$last_distro"{,-{proposed,backports,updates,security}} "$source"))
  67. unset IFS
  68.  
  69. if [ "${#project_db[@]}" -gt 2 ]; then
  70. last_version="${project_db[1]}"
  71. if [[ "$last_version" =~ ^[0-9]+: ]]; then
  72. last_version="$(echo "$last_version" | cut -d: -f2)"
  73. has_epoch=true
  74. fi
  75. component=$(echo "${project_db[2]}" | cut -d/ -f2)
  76. if [ "$component" == "$last_distro" ]; then
  77. component="main"
  78. fi
  79. fi
  80.  
  81. if [ -z "$merge_version" ]; then
  82. if [ -n "$last_version" ]; then
  83. if [[ "$project" == lib* ]]; then
  84. intial=${project:0:4}
  85. else
  86. intial=${project:0:1}
  87. fi
  88.  
  89. project_changelog=$(wget -O - \
  90. http://changelogs.ubuntu.com/changelogs/pool/$component/$intial/$source/${source}_${last_version}/changelog);
  91.  
  92. if [ -n "$project_changelog" ]; then
  93. for ((i = 0; ; i += 1)); do
  94. version="$(echo "$project_changelog" | dpkg-parsechangelog -l - -S Version -o $i -c 1)";
  95.  
  96. if [[ "$version" =~ -[0-9]+ubuntu[0-9]+ ]]; then
  97. continue
  98. elif [[ "$version" =~ -[0-9]+$ ]]; then
  99. merge_version=$version
  100. echo "Last debian version found at $version (salsa tag is debian/${version/:/%})"
  101. break
  102. elif [ -z "$version" ]; then
  103. break;
  104. fi
  105. done
  106. fi
  107. fi
  108.  
  109. if [ -z "$merge_version" ]; then
  110. echo "Impossible to find debian fork, please provide it as script parameter"
  111. exit 1
  112. fi
  113. fi
  114.  
  115. # checkout to the latest debian merge and move as ubuntu/master
  116. merge_tag=${merge_version/:/%}
  117. git checkout -b ubuntu/master "debian/$merge_tag"
  118.  
  119. bzr_uri="lp:~ubuntu-desktop/$bzr_repo/ubuntu${ubuntu_bzr_sufix_aliases[$project]}"
  120. bzr_repo_uri="bzr::$bzr_uri"
  121.  
  122. if [ "$has_epoch" == true ]; then
  123. # while read -r line; do
  124. # tag="$(echo "${line/:/%}" | sed -n "s,\([a-f0-9]\+\) releasing package $source version \(.*[0-9]\+ubuntu[0-9]\+.*\),\2 \1,p")"
  125. # [ -n "$tag" ] && ! git show-ref $tag &> /dev/null && git tag $tag
  126. # done < <(git log ubuntu-bzr/master --oneline)
  127.  
  128. ubuntu_bzr_repo=$(mktemp --suffix="-$project-ubuntu-bzr-repo" --dry-run)
  129. bzr branch "$bzr_uri" "$ubuntu_bzr_repo"
  130. bzr_repo_uri="$ubuntu_bzr_repo"
  131.  
  132. (
  133. cd "$bzr_repo_uri"
  134. git init
  135. bzr fast-export --plain --rewrite-tag-names . | git fast-import
  136.  
  137. for t in $(git tag); do
  138. if [[ "$t" =~ ^[0-9]+_ ]]; then
  139. if git tag "$(echo "$t" | sed "s,^\([0-9]\+\)_,\1%,")" "$t"; then
  140. git tag -d "$t"
  141. fi
  142. fi
  143. done
  144. )
  145. fi
  146.  
  147. git remote add ubuntu-bzr "$bzr_repo_uri"
  148. git fetch ubuntu-bzr
  149. # for t in $(git tag -l '[0-9]*[0-9]ubuntu[0-9]*'); do git tag "ubuntu/$t" "$t"; git tag -d "$t"; done
  150.  
  151. for t in $(git tag --merged ubuntu-bzr/master); do
  152. if git tag "ubuntu/$t" "$t"; then
  153. git tag -d "$t"
  154. fi
  155. done
  156.  
  157. git merge -s ours --no-commit ubuntu-bzr/master --allow-unrelated-histories
  158. git rm -rf --ignore-unmatch debian
  159. git read-tree --prefix=/ -u ubuntu-bzr/master
  160. git rm -rf --ignore-unmatch .bzr*
  161. git commit -m "Importing $bzr_uri"
  162.  
  163. # Since we want to import a dsc now, we need to remove the tag it already provides or gbp will complain
  164. last_tag=$(git describe --tags --abbrev=0 ubuntu-bzr/master)
  165. # last_version="$(echo "${last_tag//%/:}" | cut -f2 -d/)"
  166. # git tag ubuntu/bzr-last-release "$last_tag"
  167. bzr_last_release="$last_tag-bzr"
  168. git tag "$bzr_last_release" "$last_tag"
  169. git tag -d "$last_tag"
  170.  
  171. dsc_dir="$(mktemp -d --suffix="-$project-lp-source")"
  172. dsc_file="$dsc_dir/${source}_$(echo "$last_version" | sed "s,^[0-9]\+:,,").dsc"
  173. (cd "$dsc_dir" && pull-lp-source -d --no-conf "$source" "$last_version")
  174.  
  175. if ! [ -e "$dsc_file" ]; then
  176. echo "No $dsc_file found, please download it for $source $last_version"
  177. exit 1
  178. fi
  179.  
  180. if [ "$(git branch --remote --list 'salsa/upstream' | wc -l)" -gt 0 ]; then
  181. upstream_branch="upstream"
  182. else
  183. upstream_branch="upstream/latest"
  184. last_packaged_version=$(echo "$last_version" | cut -d'-' -f1)
  185. last_packaged_major_version=$(echo "$last_packaged_version" | cut -d. -f-2)
  186. last_upstream_version=$(git describe --tags --abbrev=0 upstream/latest | cut -d'/' -f2)
  187. last_upstream_major_version=$(echo "$last_upstream_version" | cut -d. -f-2)
  188.  
  189. if dpkg --compare-versions "$last_packaged_major_version" lt "$last_upstream_major_version"; then
  190. upstream_branch="upstream/${last_packaged_major_version}.x"
  191. fi
  192.  
  193. if ! git branch --remote --list 'salsa/*' | grep -qs "$upstream_branch"; then
  194. echo "$project expects to use $upstream_branch as branch, but that can't be found."
  195. echo "Please, make sure that salsa has it, or import the orig to generate that."
  196. exit 1
  197. fi
  198. fi
  199.  
  200. gbp import-dsc --debian-branch=ubuntu/master --debian-tag='ubuntu/%(version)s' --upstream-branch="$upstream_branch" "$dsc_file"
  201.  
  202. cat << EOF > debian/gbp.conf
  203. [DEFAULT]
  204. debian-branch=ubuntu/master
  205. upstream-branch=$upstream_branch
  206. debian-tag=ubuntu/%(version)s
  207. upstream-vcs-tag=%(version)s
  208. pristine-tar=True
  209. EOF
  210.  
  211. git add debian/gbp.conf
  212. git commit debian/gbp.conf -m "Add debian/gbp.conf with ubuntu settings"
  213.  
  214. set +e
  215. read -r -d '' VCS <<EOF
  216. XS-Debian-Vcs-Browser: https://salsa.debian.org/$debian_team/$project
  217. XS-Debian-Vcs-Git: https://salsa.debian.org/$debian_team/$project
  218. Vcs-Browser: https://git.launchpad.net/~ubuntu-desktop/ubuntu/+source/$project
  219. Vcs-Git: https://git.launchpad.net/~ubuntu-desktop/ubuntu/+source/$project
  220. EOF
  221. set -e
  222.  
  223. # VCS="$(echo "$VCS" | sed -e 's/[\/&]/\\&/g')"
  224. # VCS="$(echo "$VCS" | awk -vORS="\\\n" '1')"
  225. # sed "s,^Vcs-Bzr:.*,$VCS,g" -i debian/control*
  226.  
  227. for ctrl in debian/control*; do
  228. awk -v r="$VCS" '{gsub(/^Vcs-Bzr:.*/,r)}1' $ctrl > $ctrl.tmp
  229. mv $ctrl.tmp $ctrl
  230. done
  231.  
  232. if [ -n "$(git --no-pager diff)" ]; then
  233. git commit debian/control* -m "debian/control*: update VCS informations"
  234. fi
  235.  
  236. for commit in $(git log "$bzr_last_release"..ubuntu-bzr/master --reverse --format=format:%H); do
  237. if ! git format-patch --stdout $commit | git am -3; then
  238. echo "Failed to re-apply bzr-change"
  239. git show $commit --shortstat
  240. git am --abort
  241. continue
  242. fi
  243. # if ! git show $commit | git apply -3; then
  244. # echo "Failed to re-apply bzr-change"
  245. # git show $commit --shortstat
  246. # continue
  247. # fi
  248. # if [ -n "$(git diff --cached)" ]; then
  249. # git commit -C $commit
  250. # fi
  251. done
  252.  
  253. git remote prune ubuntu-bzr
  254. git remote remove ubuntu-bzr
  255.  
  256. git gc --prune=now --aggressive
  257.  
  258. if [ -n "$ubuntu_bzr_repo" ] && [ -d "$ubuntu_bzr_repo" ]; then
  259. rm -rf "$ubuntu_bzr_repo"
  260. fi
  261.  
  262. if [ -n "$dsc_dir" ] && [ -d "$dsc_dir" ]; then
  263. rm -rf "$dsc_dir"
  264. fi
  265.  
  266. # # Create local branches
  267. # git checkout "$upstream_branch"
  268. # git checkout pristine-tar
  269. # git checkout ubuntu/master
  270. # # gbp push --verbose origin
  271.  
  272. # git push -u origin ubuntu/master
  273. # git push -u origin "$upstream_branch"
  274. # git push -u origin pristine-tar
  275.  
  276. # git tag | grep -E "^ubuntu/|^debian/|^upstream/" | xargs --no-run-if-empty git push origin
  277.  
  278. # Remove unused tags
  279. # git tag | grep -Ev "^ubuntu/|^debian/|^upstream/" | xargs --no-run-if-empty git push --delete
  280.  
  281. (cd .. && touch $project.DONE)
  282.  
  283. # If the debian upstream/latest is more updated and you want to improt a new tarball....
  284. # git tag -d upstream/3.28.2
  285.  
  286. # 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
  287. # and `git gc --aggressive` as per git bzr usage.
  288.  
  289. # Set gbp.conf
  290.  
  291. ### Importing upstream revision to ubuntu branch
  292. # gbp import-orig --uscan
  293.  
  294.  
  295. ## Rename debianv ersione before release
  296.  
  297. exit $?
  298.  
  299. N=5
  300. (
  301. 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
  302. ((i=i%N)); ((i++==0)) && wait
  303. env LAUNCHPAD_OWNER=canonical-desktop-team script -f -a -c "bash /data/GNOME/ubuntu-git-importer/importer.sh $e" $e.log &
  304. done
  305. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement