Guest User

Patch ebuilds

a guest
Dec 17th, 2024
46
0
147 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.17 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # NOTE:
  4. # for every function:
  5. # $0 -> the name of this script eg. /etc/portage/repo.postsync.d/gentoo.sh
  6. # $1 -> the URL the repository is synced from
  7. # $2 -> the location of the repository
  8.  
  9. function local_einfo() {
  10.     echo -e " \033[1;32m*\033[0m ${1}"
  11. }
  12.  
  13. function local_eerror() {
  14.     echo -e " \033[1;31m*\033[0m ${1}"
  15. }
  16.  
  17. function patch() {
  18.     cd /var/db/repos/febuild || exit
  19.     local PN=
  20.     local inner_patch=
  21.     for patch in "${PATCH_EBUILDS[@]}"; do
  22.         inner_patch="${patch%% *}"
  23.         local_einfo "- Applying ${inner_patch#/etc/portage/patches/repos/"$REPO"/}"
  24.         git apply "${patch%% *}" >/dev/null || echo "$(date '+%s') Applying ${patch%% *} failed while syncing $REPO" >> /home/fabian/.cache/messages
  25.  
  26.         PN=${patch%% *}
  27.         PN=${PN#/etc/portage/patches/repos/"$REPO"/}
  28.         PN=${PN%.patch}
  29.         PN=${PN//%//}
  30.         # Name patches like this: <category>%<package>%version
  31.         ebuild /var/db/repos/"$REPO"/"$PN"/"${PN#*/}"-"${patch#* }".ebuild manifest >/dev/null || echo "$(date '+%s') Updating manifest failed while syncing $REPO" >> /home/fabian/.cache/messages
  32.     done
  33. }
  34.  
  35. function update_patch() {
  36.     # regex to match any ebuild https://projects.gentoo.org/pms/8/pms.html
  37.     # [0-9]+(\.[0-9]+)+([a-z])?(_alpha|_beta|_pre|_rc|_p)?([a-z])?(-r([0-9]))?.ebuild
  38.  
  39.     local PN=
  40.     local current=
  41.     local latest=
  42.     for patch in /etc/portage/patches/repos/"$REPO"/*.patch; do
  43.         PN=${patch#/etc/portage/patches/repos/"$REPO"/}
  44.         PN=${PN%.patch}
  45.         PN=${PN//%//}
  46.         [ ! -d /var/db/repos/febuild/"$PN" ] && mkdir --parent /var/db/repos/febuild/"$PN" && COMMIT_FEBUILD=true
  47.  
  48.         source /home/fabian/coding/bash/etools/etools
  49.         # TODO: should parse current from patch
  50.         current="$(etools_current_version "$PN")"
  51.         latest="$(etools_get_version "$PN")"
  52.  
  53.         if [[ "$current" != "$latest" ]]; then
  54.             COMMIT_FEBUILD=true
  55.             PATCH_EBUILDS+=("$patch $latest")
  56.             cp /var/db/repos/"$REPO"/"$PN"/"${PN#*/}-$latest".ebuild /var/db/repos/febuild/"$PN"/
  57.             [ -d /var/db/repos/"$REPO"/"$PN"/files ] && cp -r /var/db/repos/"$REPO"/"$PN"/files /var/db/repos/febuild/"$PN"/
  58.             rm "/var/db/repos/febuild/$PN/${PN#*/}-$current.ebuild" 2>/dev/null
  59.             local_einfo "- Updating ${patch#/etc/portage/patches/repos/"$REPO"/} from ${PN#*/}-$current to ${PN#*/}-$latest"
  60.             sed -i "s/${PN#*/}-$current/${PN#*/}-$latest/g" "$patch" || \
  61.                 local_eerror "- Updating the patch to the newest version failed" && \
  62.                 echo "$(date '+%s') Updating ${patch#/etc/portage/patches/repos/"$REPO"/} failed" >> /home/fabian/.cache/messages
  63.         else
  64.             if ! ls /var/db/repos/febuild/"$PN" >/dev/null 2>&1; then
  65.                 cp /var/db/repos/"$REPO"/"$PN"/"${PN#*/}-$latest".ebuild /var/db/repos/febuild/"$PN"/ || \
  66.                     local_eerror "Copying $latest to febuild repo failed"
  67.                 [ -d /var/db/repos/"$REPO"/"$PN"/files ] && \
  68.                     cp -r /var/db/repos/"$REPO"/"$PN"/files /var/db/repos/febuild/"$PN"/
  69.                 COMMIT_FEBUILD=true
  70.             fi
  71.         fi
  72.     done
  73. }
  74.  
  75. function commit_febuild() {
  76.     [ $COMMIT_FEBUILD == true ] && cd /var/db/repos/febuild && \
  77.         pkgdev manifest || true && \
  78.             git add . >>/dev/null && git commit -m "Postsync update $REPO" >>/dev/null && git push >>/dev/null || return 0;
  79. }
  80.  
  81.  
  82.  
  83. # array of functions to be called
  84. functions=("update_patch" "patch" "commit_febuild")
  85.  
  86. COMMIT_FEBUILD=false
  87. PATCH_EBUILDS=()
  88. REPO=$(basename "$0" .sh)
  89.  
  90.  
  91. if [ "$1" == "$(basename "$0" .sh)" ]; then
  92.         # for func in "${functions[@]}"; do
  93.     for (( i = 0; i < ${#functions[@]}; i++)); do
  94.                 # call every function with all arguments since the 2nd
  95.                 # NOTE: !!! Not to be passed to the function !!!
  96.                 # $0 -> the scripts name
  97.                 # $1 -> repository name
  98.  
  99.                 # NOTE: !!! passed to the function !!!
  100.                 # $2 -> the URL to sync the repository from
  101.                 # $3 -> the location where the repository is located
  102.         local_einfo "Applying \033[1m${functions[$i]}\033[0m function"
  103.                 ${functions[$i]} "${@:2}"
  104.         if [ "$?" -eq 0 ]; then
  105.             local_einfo "\033[1m${functions[$i]}\033[0m function returned sccuessfully"
  106.         else
  107.             local_eerror "\033[1m${functions[$i]}\033[0m function exited unsuccessfully"
  108.         fi
  109.         (( i < ${#functions[@]} - 1 )) && local_einfo
  110.         done
  111.     exit 0
  112. fi
Tags: BASH
Advertisement
Add Comment
Please, Sign In to add comment