Last active
April 11, 2019 06:48
-
-
Save bartoszek/a2913e28f6cdef035fd07ffa4b13797b to your computer and use it in GitHub Desktop.
Move AUR packages to github.com and post message to package comment section informing users about the switch.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
# configuration: github user(required), github token(optional) | |
token="" #https://developer.github.com/v3/guides/getting-started/#oauth | |
user="" | |
#test if user non-zero | |
[ -z "$user" ] && { | |
echo "fill user variable in configuration section" >&2; | |
read -p "github username:" user; | |
} | |
#test if inside clone of aur repo | |
git remote get-url origin|grep -q aur.archlinux.org || { echo "run `basename $0` for within clone of aur repo" >&2; exit 1; } | |
#test if has jq | |
hash jq || { echo "jq(1) is requred" >&2; exit 1; } | |
#repo name from pwd | |
repo_name="AUR-$(basename $(pwd))" | |
#test if repo already exist befor poking the API | |
#add "API rate limit exceeded" | |
message=$(curl -s https://api.github.com/repos/${user}/${repo_name}|jq -r .message) | |
expr match "$message" "API rate limit exceeded.*" && { echo $message >&2; exit 1; } | |
[ "$message" = "Not Found" ] && { | |
[ -n "$token" ] \ | |
&& curl -H "Authorization: token ${token}" https://api.github.com/user/repos -d "{\"name\":\"${repo_name}\"}" \ | |
|| curl -u "${user}" https://api.github.com/user/repos -d "{\"name\":\"${repo_name}\"}" | |
} >&2 | |
#test if remote already exist before trying to add one | |
git remote get-url github || git remote add github https://github.com/${user}/${repo_name}.git | |
git push github master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
#wip: probe for ID alongside $token | |
# configuration | |
aur_username="" | |
git_username="" | |
_message_eval_template='Please+report+%60issues%60+and+%60patches%60+to+%5B${pkgname}%40github.com%5D%28https%3A%2F%2Fgithub.com%2F${git_username}%2FAUR-${pkgname}%29' | |
#trap 'rm /tmp/aur_cookie.txt' EXIT | |
#test if configured | |
[ -z "&aur_username" -or -z "&git_username" ] && { echo "fill configuration variable in script header" &>2; exit 1; } | |
# define evals for `curl` | |
_curl='curl -s -b /tmp/aur_cookie.txt "https://aur.archlinux.org/pkgbase/${pkgname}/"' | |
# post comment needs: token, comment, ID ( can be anything, AUR isn't chacking it ) | |
_curl_post_comment=$_curl' -d "action=do_AddComment&ID=141089&token=${token}&comment=${message}"' | |
# pin comment needs: token, comment_id | |
_curl_pin_comment=$_curl' -d "action=do_PinComment&comment_id=${comment_id}&token=${token}"' | |
# message base on PKGBUILD | |
[ ! -f PKGBUILD ] && { echo "PKGBUILD missing, run $(basename "$0") inside package folder" >&2; exit 1; } | |
pkgname=$(. PKGBUILD; echo $pkgname) | |
message="$(eval echo $_message_eval_template)" | |
# check if cookie.txt exist | |
# get cookie with: curl -c cookie.txt -d "user=" -d "password=" https://aur.archlinux.org/login | |
[ -f /tmp/aur_cookie.txt ] || { | |
read -p "password for ${aur_username}@aur:" pass | |
curl -s -c /tmp/aur_cookie.txt 'https://aur.archlinux.org/login' -d "user=${aur_username}&passwd=$pass" >/dev/null | |
} | |
# get post token by probing comment FORM | |
token=$(eval ${_curl}|grep -Po 'name="token" value="\K[a-z0-9]*'|head -n1) | |
# post a comment | |
eval ${_curl_post_comment} | |
# get $comment_id | |
comment_id=$(eval ${_curl}|grep -Po 'name="comment_id" value="\K[0-9]*'|head -n1) | |
# ping comment base on $comment_id | |
eval ${_curl_pin_comment} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment