Created
September 28, 2017 15:47
-
-
Save phizaz/7796f891fe8c44d9ab885801f23a8dae to your computer and use it in GitHub Desktop.
Try to create a bash script for recursively building sources from arch linux repo for MSYS2
This file contains hidden or 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
# To the extent possible under law, the author(s) have dedicated all | |
# copyright and related and neighboring rights to this software to the | |
# public domain worldwide. This software is distributed without any warranty. | |
# You should have received a copy of the CC0 Public Domain Dedication along | |
# with this software. | |
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | |
# ~/.bash_profile: executed by bash(1) for login shells. | |
# The copy in your home directory (~/.bash_profile) is yours, please | |
# feel free to customise it to create a shell | |
# environment to your liking. If you feel a change | |
# would be benifitial to all, please feel free to send | |
# a patch to the msys2 mailing list. | |
# User dependent .bash_profile file | |
# source the users bashrc if it exists | |
if [ -f "${HOME}/.bashrc" ] ; then | |
source "${HOME}/.bashrc" | |
fi | |
# Set PATH so it includes user's private bin if it exists | |
# if [ -d "${HOME}/bin" ] ; then | |
# PATH="${HOME}/bin:${PATH}" | |
# fi | |
# Set MANPATH so it includes users' private man if it exists | |
# if [ -d "${HOME}/man" ]; then | |
# MANPATH="${HOME}/man:${MANPATH}" | |
# fi | |
# Set INFOPATH so it includes users' private info if it exists | |
# if [ -d "${HOME}/info" ]; then | |
# INFOPATH="${HOME}/info:${INFOPATH}" | |
# fi | |
clearinstall() { | |
install_visited="" | |
} | |
wrapped_install() { | |
ignores="None sh tzdata linux-api-headers awk" | |
# get the name | |
if [[ $1 =~ ([^>=]+).* ]]; then | |
local pack=${BASH_REMATCH[1]} | |
else | |
echo "wrong name pattern $1" | |
return 1 | |
fi | |
# mark visited | |
if [ -z "$install_visited" ]; then | |
install_visited="$pack" | |
else | |
# skip visited | |
if [ ! -z "`echo $install_visited | grep $pack`" ]; then | |
echo "visited $pack" | |
return 0 | |
fi | |
install_visited="$install_visited $pack" | |
fi | |
# skip ignored | |
if [ ! -z "`echo $ignores | grep $pack`" ]; then | |
echo "ignore $pack" | |
return 0 | |
fi | |
# skip installed | |
if [ ! -z "`have | grep -x $pack`" ]; then | |
echo "installed $pack" | |
return 0 | |
fi | |
# try to install from msys first | |
if [ ! -z "$(searchmsys $pack)" ]; then | |
echo "install $pack from msys" | |
installmsys $pack | |
return 0 | |
fi | |
echo "going to build $pack" | |
# recursively install dependencies | |
local deps=`dep $1` | |
for line in $deps; do | |
wrapped_install $line | |
done | |
# update & build | |
local tmp=`pwd` \ | |
&& cd $(repodir $(repo $pack)) \ | |
&& pull $pack \ | |
&& cd $pack \ | |
&& cd `find ./ -name "*x86_64" -o -name "*any" | head -n 1` \ | |
&& makepkg -i --nodeps --skippgpcheck \ | |
# go back | |
cd $tmp | |
} | |
install() { | |
install_visited="" | |
wrapped_install $1 | |
} | |
installmsys() { | |
pacman -S "msys/$1" | |
} | |
search() { | |
pacman -Ss ^$1$ | |
} | |
searchmsys() { | |
search $1 | grep msys | |
} | |
repo() { | |
res=`search $1` | |
count=`echo $res | wc -l` | |
if [ $count -gt 2 ]; then | |
# error | |
exit 1 | |
else | |
echo $res | cut -d "/" -f 1 | |
fi | |
} | |
repodir() { | |
packages_repo="core extra" | |
packages_dir="$HOME/packages" | |
community_dir="$HOME/community" | |
if [ -z "`echo $packages_repo | grep $1`" ]; then | |
echo $community_dir | |
else | |
echo $packages_dir | |
fi | |
} | |
pull() { | |
svn update $1 | |
} | |
dep() { | |
pacman -Si $1|sed -n '/Depends\ On/,/:/p'|sed '$d'|cut -d: -f2|while read line; do for word in $line; do echo $word; done; done | |
} | |
have() { | |
pacman -Q | cut -d ' ' -f 1 | |
} | |
export TERM=cygwin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment