├── .gitignore ├── src ├── filter.awk ├── config.sh ├── search.sh ├── description.sh ├── version.sh ├── update.sh ├── download.sh ├── mk.conf.tpl ├── installer.sh ├── tap.sh ├── help.sh └── pkgbrew.sh ├── Makefile ├── bin ├── compile.pl ├── installer └── pkgbrew ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /src/filter.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | flag=0 3 | } 4 | 5 | /^==========/ { 6 | if(flag == 1) { 7 | flag = 0; 8 | print; 9 | } else { 10 | flag = 1; 11 | } 12 | } 13 | 14 | /^=+>/ || flag == 1 { 15 | print; 16 | } 17 | -------------------------------------------------------------------------------- /src/config.sh: -------------------------------------------------------------------------------- 1 | : ${PKGBREW:="https://raw.githubusercontent.com/ta2gch/pkgbrew/master/bin/pkgbrew"} 2 | : ${PKGHOST:="http://cdn.netbsd.org/pub/pkgsrc/stable/pkgsrc.tar.bz2"} 3 | : ${PKGHOME:="${HOME}/.pkgbrew"} 4 | : ${PKGSRC:="${PKGHOME}/src"} 5 | : ${MAKE_JOBS:=1} 6 | : ${CC:=gcc} 7 | -------------------------------------------------------------------------------- /src/search.sh: -------------------------------------------------------------------------------- 1 | #?include src/config.sh 2 | search(){ 3 | packagedir=`dirname "${1}" | tr '/' '_'` 4 | packagename=`basename "${1}"` 5 | find "${PKGSRC}" -maxdepth 2 -mindepth 2 -type d \ 6 | | grep "${packagedir}/${packagename}" \ 7 | | sed -e "s@${PKGSRC}/@@" \ 8 | | tr '_' '/' 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/description.sh: -------------------------------------------------------------------------------- 1 | #?include src/config.sh 2 | description(){ 3 | package="${PKGSRC}/${1}" 4 | if [ ! -n "${1}" -o ! -d "${package}" ]; then 5 | echo No package \'${2}\' found, did you mead: 6 | search "${1}" | sed -e "s/^/ /" 7 | echo pkgbrew: package not found 8 | exit 1; 9 | fi 10 | 11 | cat "${package}/DESCR" 12 | } 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TARGETS = pkgbrew installer 2 | 3 | all: $(TARGETS) 4 | 5 | $(TARGETS): %: src/%.sh 6 | perl bin/compile.pl $^ \ 7 | | sed -e "s/__PKGBREW_REVISION__/`git describe --tags`/g" \ 8 | | sed -e "s/__PKGSRC_VERSION__/trunk/g" \ 9 | > bin/$@ 10 | chmod +x bin/$@ 11 | 12 | .PHONY: clean 13 | 14 | clean: 15 | rm -rf bin/installer bin/pkgbrew *~ */*~ 16 | rm -rf test/ 17 | 18 | test: clean $(TARGETS) 19 | sh bin/test.sh 20 | -------------------------------------------------------------------------------- /src/version.sh: -------------------------------------------------------------------------------- 1 | version(){ 2 | cat<){ 13 | if($line =~ /^#\?include\s+(.+)/){ 14 | &compile($1) unless grep {$_ eq $1} @hist; 15 | }else{ 16 | print $line; 17 | } 18 | } 19 | 20 | close($FILE); 21 | } 22 | 23 | &compile($ARGV[0]); 24 | -------------------------------------------------------------------------------- /src/update.sh: -------------------------------------------------------------------------------- 1 | #?include src/config.sh 2 | #?include src/download.sh 3 | #?include src/tap.sh 4 | 5 | update(){ 6 | download "${PKGHOST}" "-" \ 7 | | tar xj --strip-components 1 -C "${PKGSRC}" 8 | 9 | if [ -f "${PKGHOME}/etc/user-repositories" ]; then 10 | cat "${PKGHOME}/etc/user-repositories" | while read repo ;do 11 | untap "${repo}" 12 | tap "${repo}" 13 | done 14 | fi 15 | 16 | download "${PKGBREW}" "${PKGHOME}/bin/pkgbrew" 17 | 18 | chmod +x "${PKGHOME}/bin/pkgbrew" 19 | } 20 | -------------------------------------------------------------------------------- /src/download.sh: -------------------------------------------------------------------------------- 1 | download_1(){ 2 | from="${1}" 3 | dest="${2}" 4 | if which wget > /dev/null ; then 5 | wget -O "${dest}" "${from}" 6 | elif which curl > /dev/null ; then 7 | if [ "${dest}" = "-" ] ; then 8 | curl -L "${from}" 9 | else 10 | curl -L -o "${dest}" -O "${from}" 11 | fi 12 | fi 13 | } 14 | 15 | download(){ 16 | from="${1}" 17 | dest="${2}" 18 | case "${from}" in 19 | https://*) download_1 "${from}" "${dest}" ;; 20 | http://*) download_1 "${from}" "${dest}" ;; 21 | *) cp "${from}" "${dest}" ;; 22 | esac 23 | } 24 | -------------------------------------------------------------------------------- /src/mk.conf.tpl: -------------------------------------------------------------------------------- 1 | #?include src/config.sh 2 | # Example ${PKGHOME}/etc/mk.conf file produced by pkgbrew 3 | # `date` 4 | 5 | .ifdef BSD_PKG_MK # begin pkgsrc settings 6 | 7 | UNPRIVILEGED= yes 8 | PKG_DBDIR= ${PKGHOME}/var/db/pkg 9 | LOCALBASE= ${PKGHOME} 10 | VARBASE= ${PKGHOME}/var 11 | PKG_TOOLS_BIN= ${PKGHOME}/sbin 12 | PKGINFODIR= info 13 | PKGMANDIR= man 14 | MAKE_JOBS= ${MAKE_JOBS} 15 | PKGSRC_COMPILER= ${CC} 16 | 17 | TOOLS_PLATFORM.awk?= ${PKGHOME}/bin/nawk 18 | TOOLS_PLATFORM.sh?= /bin/bash 19 | 20 | PKG_DEFAULT_OPTIONS= -x11 -gtk2 -gkt3 -gnome -kde 21 | .endif # end pkgsrc settings 22 | -------------------------------------------------------------------------------- /src/installer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | #?include src/config.sh 6 | #?include src/download.sh 7 | 8 | main(){ 9 | 10 | if [ -d "${PKGHOME}" ]; then 11 | echo pkgbrew already installed 12 | exit 1 13 | fi 14 | 15 | workdir=`mktemp -d /tmp/pkgbrew.XXXXXX` 16 | 17 | download "${PKGHOST}" "-" | tar -jx -C "${workdir}" 18 | 19 | prev="${SH}" 20 | export SH="/bin/bash" 21 | ${workdir}/pkgsrc/bootstrap/bootstrap \ 22 | --compiler=${CC} \ 23 | --ignore-user-check \ 24 | --workdir="${workdir}/work" \ 25 | --make-jobs="${MAKE_JOBS}" \ 26 | --prefix="${PKGHOME}" | awk " 27 | #?include src/filter.awk 28 | " 29 | export SH="${prev}" 30 | 31 | mv "${workdir}/pkgsrc" "${PKGSRC}" 32 | 33 | download "${PKGBREW}" "${PKGHOME}/bin/pkgbrew" 34 | chmod +x "${PKGHOME}/bin/pkgbrew" 35 | 36 | cat< "${PKGHOME}/etc/mk.conf" 37 | #?include src/mk.conf.tpl 38 | EOF 39 | } 40 | 41 | main 42 | -------------------------------------------------------------------------------- /src/tap.sh: -------------------------------------------------------------------------------- 1 | #?include src/config.sh 2 | #?include src/download.sh 3 | 4 | convert_repository_name(){ 5 | echo "${PKGSRC}/`echo ${1} | sed -e 's%/%_%g'`" 6 | } 7 | 8 | tap(){ 9 | if [ -d `convert_repository_name "${1}"` ]; then 10 | echo repository already exits: ${1} 11 | exit 1; 12 | fi 13 | 14 | mkdir `convert_repository_name "${1}"` 15 | 16 | echo "${1}" >> "${PKGHOME}/etc/user-repositories" 17 | 18 | download "https://github.com/${1}/archive/master.tar.gz" "-" \ 19 | | tar xz \ 20 | --strip-components 1 \ 21 | -C `convert_repository_name "${1}"` 22 | } 23 | 24 | untap(){ 25 | if [ -z `echo ${1} | tr -d -c '/'` ]; then 26 | echo \'${1}\' is not user repository 27 | exit 1; 28 | elif [ ! -d `convert_repository_name "${1}"` ]; then 29 | echo repository already removed: ${1} 30 | exit 1; 31 | fi 32 | 33 | echo Deleting repository... 34 | 35 | rm -r `convert_repository_name "${1}"` 36 | 37 | echo Completed. 38 | 39 | cp "${PKGHOME}/etc/user-repositories" \ 40 | "${PKGHOME}/etc/user-repositories.bak" 41 | 42 | cat "${PKGHOME}/etc/user-repositories.bak" \ 43 | | sed -e "s%${1}%##%g" \ 44 | | sed -e "/##/d" \ 45 | > "${PKGHOME}/etc/user-repositories" 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, TANIGUCHI Masaya 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /src/help.sh: -------------------------------------------------------------------------------- 1 | help(){ 2 | cat< [] 4 | command: 5 | 6 | help : show usage 7 | search : search packages 8 | tap : add user repository 9 | untap : remove user repository 10 | version : output version information 11 | update : update repositories 12 | description : show description of pacakge 13 | 14 | Build pkgsrc package 15 | 16 | depends : build and install dependencies 17 | fetch : fetch distribution file(s) 18 | checksum : fetch and check distribution file(s) 19 | extract : look at unmodified source 20 | patch : look at initial source 21 | configure : stop after configure stage 22 | all or build : stop after build stage 23 | stage-install : install under stage directory 24 | test : run package's self-tests, if any exist and supported 25 | package : create binary package before installing it 26 | replace : change (upgrade, downgrade, or just replace) installed package in-place 27 | deinstall : deinstall previous package 28 | package-install : install package and build binary package 29 | install : install package 30 | bin-install : attempt to skip building from source and use pre-built binary package 31 | show-depends : print dependencies for building 32 | show-options : print available options from options.mk 33 | 34 | Cleanup targets (in separate section because of importance): 35 | 36 | clean-depends : remove work directories for dependencies 37 | clean : remove work directory 38 | distclean : remove distribution file(s) 39 | package-clean : remove binary package 40 | 41 | Package Development 42 | 43 | makesum : fetch and generate checksum for distributed file(s) 44 | makepatchsum : (re)generate checksum for patches 45 | makedistinfo : (re)generate distinfo file (creating checksums for distributed file and patches) 46 | print-PLIST : attempt to generate correct packaging list (NB! It helps, but it doesn't eliminate manual work.) 47 | 48 | EOF 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pkgbrew 2 | 3 | non-root package manager 4 | 5 | ## Usage 6 | 7 | ### Install a package 8 | 9 | ``` 10 | $ pkgbrew install editors/emacs-nox11 11 | ``` 12 | 13 | ### Uninstall a package 14 | 15 | ``` 16 | $ pkgbrew deinstall editors/emacs-nox11 17 | ``` 18 | 19 | ### Upgrade a package 20 | 21 | ``` 22 | $ pkgbrew replace editors/emacs-nox11 23 | ``` 24 | 25 | ### Show build parameters 26 | 27 | ``` 28 | $ pkgbrew show-options editors/emacs24 29 | ``` 30 | 31 | ### Search a package 32 | 33 | ``` 34 | $ pkgbrew search emacs 35 | ``` 36 | 37 | ### Manage user repository (tap/untap) 38 | 39 | ``` 40 | $ pkgbrew tap / # Github 41 | $ pkgbrew untap / 42 | $ pkgbrew update # for all repository 43 | ``` 44 | 45 | For example, 46 | 47 | ``` 48 | $ pkgbrew tap NetBSD/pkgsrc-wip 49 | ``` 50 | 51 | ### Show Usage 52 | 53 | ``` 54 | $ pkgbrew help 55 | ``` 56 | 57 | ## Installation 58 | 59 | ``` 60 | $ export MAKE_JOBS=4 # Optional 61 | $ wget -O- https://raw.githubusercontent.com/tani/pkgbrew/master/bin/installer | /bin/sh 62 | $ echo 'export PATH=$HOME/.pkgbrew/bin:$PATH' >> ~/.bashrc 63 | $ echo 'export MANPATH=$HOME/.pkgbrew/man:$MANPATH' >> ~/.bashrc 64 | ``` 65 | 66 | ## Supported platforms 67 | 68 | - NetBSD 69 | - Solaris 70 | - Linux (test environment) 71 | - Darwin(Mac OS X) (Travis CI) 72 | - FreeBSD 73 | 74 | (see also pkgsrc.org) 75 | 76 | ## Software requirements 77 | 78 | - wget or curl 79 | - gcc (and libstdc++) 80 | - libncurses-devel 81 | - zlib and zlib-devel 82 | 83 | This software is written only in /bin/sh and awk, which means that POSIX compatibe. 84 | 85 | ### Debian/Ubuntu 86 | 87 | ``` 88 | $ sudo apt-get install build-essential 89 | ``` 90 | 91 | ### Mac OSX 92 | 93 | Set the CC variable in the environment before the script the starts. (`export CC=clang`) 94 | 95 | ## Author 96 | 97 | TANIGUCHI Masaya 98 | 99 | ## Copyright 100 | 101 | Copyright(c) 2016-2020 TANIGUCHI Masaya 102 | 103 | ## License 104 | 105 | BSD License (2 clause) 106 | 107 | -------------------------------------------------------------------------------- /bin/installer: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | : ${PKGBREW:="https://raw.githubusercontent.com/ta2gch/pkgbrew/master/bin/pkgbrew"} 6 | : ${PKGHOST:="http://cdn.netbsd.org/pub/pkgsrc/stable/pkgsrc.tar.bz2"} 7 | : ${PKGHOME:="${HOME}/.pkgbrew"} 8 | : ${PKGSRC:="${PKGHOME}/src"} 9 | : ${MAKE_JOBS:=1} 10 | : ${CC:=gcc} 11 | download_1(){ 12 | from="${1}" 13 | dest="${2}" 14 | if which wget > /dev/null ; then 15 | wget -O "${dest}" "${from}" 16 | elif which curl > /dev/null ; then 17 | if [ "${dest}" = "-" ] ; then 18 | curl -L "${from}" 19 | else 20 | curl -L -o "${dest}" -O "${from}" 21 | fi 22 | fi 23 | } 24 | 25 | download(){ 26 | from="${1}" 27 | dest="${2}" 28 | case "${from}" in 29 | https://*) download_1 "${from}" "${dest}" ;; 30 | http://*) download_1 "${from}" "${dest}" ;; 31 | *) cp "${from}" "${dest}" ;; 32 | esac 33 | } 34 | 35 | main(){ 36 | 37 | if [ -d "${PKGHOME}" ]; then 38 | echo pkgbrew already installed 39 | exit 1 40 | fi 41 | 42 | workdir=`mktemp -d /tmp/pkgbrew.XXXXXX` 43 | 44 | download "${PKGHOST}" "-" | tar -jx -C "${workdir}" 45 | 46 | prev="${SH}" 47 | export SH="/bin/bash" 48 | ${workdir}/pkgsrc/bootstrap/bootstrap \ 49 | --compiler=${CC} \ 50 | --ignore-user-check \ 51 | --workdir="${workdir}/work" \ 52 | --make-jobs="${MAKE_JOBS}" \ 53 | --prefix="${PKGHOME}" | awk " 54 | BEGIN { 55 | flag=0 56 | } 57 | 58 | /^==========/ { 59 | if(flag == 1) { 60 | flag = 0; 61 | print; 62 | } else { 63 | flag = 1; 64 | } 65 | } 66 | 67 | /^=+>/ || flag == 1 { 68 | print; 69 | } 70 | " 71 | export SH="${prev}" 72 | 73 | mv "${workdir}/pkgsrc" "${PKGSRC}" 74 | 75 | download "${PKGBREW}" "${PKGHOME}/bin/pkgbrew" 76 | chmod +x "${PKGHOME}/bin/pkgbrew" 77 | 78 | cat< "${PKGHOME}/etc/mk.conf" 79 | # Example ${PKGHOME}/etc/mk.conf file produced by pkgbrew 80 | # `date` 81 | 82 | .ifdef BSD_PKG_MK # begin pkgsrc settings 83 | 84 | UNPRIVILEGED= yes 85 | PKG_DBDIR= ${PKGHOME}/var/db/pkg 86 | LOCALBASE= ${PKGHOME} 87 | VARBASE= ${PKGHOME}/var 88 | PKG_TOOLS_BIN= ${PKGHOME}/sbin 89 | PKGINFODIR= info 90 | PKGMANDIR= man 91 | MAKE_JOBS= ${MAKE_JOBS} 92 | PKGSRC_COMPILER= ${CC} 93 | 94 | TOOLS_PLATFORM.awk?= ${PKGHOME}/bin/nawk 95 | TOOLS_PLATFORM.sh?= /bin/bash 96 | 97 | PKG_DEFAULT_OPTIONS= -x11 -gtk2 -gkt3 -gnome -kde 98 | .endif # end pkgsrc settings 99 | EOF 100 | } 101 | 102 | main 103 | -------------------------------------------------------------------------------- /src/pkgbrew.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | #?include src/config.sh 6 | #?include src/version.sh 7 | #?include src/help.sh 8 | #?include src/search.sh 9 | #?include src/tap.sh 10 | #?include src/update.sh 11 | #?include src/description.sh 12 | 13 | run_command(){ 14 | command="${1}" 15 | genre=`dirname "${2}" | tr '/' '_'` 16 | packagename=`basename "${2}"` 17 | packagedir="${PKGSRC}/${genre}/${packagename}" 18 | 19 | if [ ! -n "${2}" -o ! -d "${packagedir}" ]; then 20 | echo No package \'${2}\' found, did you mead: 21 | search "${2}" | sed -e "s/^/ /" 22 | echo pkgbrew: package not found 23 | exit 1; 24 | fi 25 | 26 | cd "${packagedir}" 27 | 28 | case "${command}" in 29 | "show-depends"|"show-options"|"print-PLIST") 30 | ${PKGHOME}/bin/bmake "${command}" ;; 31 | *) ${PKGHOME}/bin/bmake "${command}" | awk " 32 | #?include src/filter.awk 33 | " ;; 34 | esac 35 | } 36 | 37 | main(){ 38 | command="${1}" 39 | package="${2}" 40 | 41 | case "${command}" in 42 | "help") help ;; 43 | "search") search "${package}" ;; 44 | "tap") tap "${package}" ;; 45 | "untap") untap "${package}" ;; 46 | "version") version ;; 47 | "update") update ;; 48 | "description") description "${package}";; 49 | 50 | "help") run_command "${command}" "${package}" ;; 51 | "search") run_command "${command}" "${package}" ;; 52 | "setup") run_command "${command}" "${package}" ;; 53 | "depends") run_command "${command}" "${package}" ;; 54 | "fetch") run_command "${command}" "${package}" ;; 55 | "checksum") run_command "${command}" "${package}" ;; 56 | "extract") run_command "${command}" "${package}" ;; 57 | "patch") run_command "${command}" "${package}" ;; 58 | "configure") run_command "${command}" "${package}" ;; 59 | "all or build") run_command "${command}" "${package}" ;; 60 | "stage-install") run_command "${command}" "${package}" ;; 61 | "test") run_command "${command}" "${package}" ;; 62 | "package") run_command "${command}" "${package}" ;; 63 | "replace") run_command "${command}" "${package}" ;; 64 | "deinstall") run_command "${command}" "${package}" ;; 65 | "package-install") run_command "${command}" "${package}" ;; 66 | "install") run_command "${command}" "${package}" ;; 67 | "bin-install") run_command "${command}" "${package}" ;; 68 | "show-depends") run_command "${command}" "${package}" ;; 69 | "show-options") run_command "${command}" "${package}" ;; 70 | 71 | "clean-depends") run_command "${command}" "${package}" ;; 72 | "clean") run_command "${command}" "${package}" ;; 73 | "distclean") run_command "${command}" "${package}" ;; 74 | "package-clean") run_command "${command}" "${package}" ;; 75 | 76 | "makesum") run_command "${command}" "${package}" ;; 77 | "makepatchsum") run_command "${command}" "${package}" ;; 78 | "makedistinfo") run_command "${command}" "${package}" ;; 79 | "print-PLIST") run_command "${command}" "${package}" ;; 80 | *) echo Invalid command: ${1} 81 | help ;; 82 | esac 83 | } 84 | 85 | main "${1}" "${2}" 86 | -------------------------------------------------------------------------------- /bin/pkgbrew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | : ${PKGBREW:="https://raw.githubusercontent.com/ta2gch/pkgbrew/master/bin/pkgbrew"} 6 | : ${PKGHOST:="http://cdn.netbsd.org/pub/pkgsrc/stable/pkgsrc.tar.bz2"} 7 | : ${PKGHOME:="${HOME}/.pkgbrew"} 8 | : ${PKGSRC:="${PKGHOME}/src"} 9 | : ${MAKE_JOBS:=1} 10 | : ${CC:=gcc} 11 | version(){ 12 | cat< [] 26 | command: 27 | 28 | help : show usage 29 | search : search packages 30 | tap : add user repository 31 | untap : remove user repository 32 | version : output version information 33 | update : update repositories 34 | description : show description of pacakge 35 | 36 | Build pkgsrc package 37 | 38 | depends : build and install dependencies 39 | fetch : fetch distribution file(s) 40 | checksum : fetch and check distribution file(s) 41 | extract : look at unmodified source 42 | patch : look at initial source 43 | configure : stop after configure stage 44 | all or build : stop after build stage 45 | stage-install : install under stage directory 46 | test : run package's self-tests, if any exist and supported 47 | package : create binary package before installing it 48 | replace : change (upgrade, downgrade, or just replace) installed package in-place 49 | deinstall : deinstall previous package 50 | package-install : install package and build binary package 51 | install : install package 52 | bin-install : attempt to skip building from source and use pre-built binary package 53 | show-depends : print dependencies for building 54 | show-options : print available options from options.mk 55 | 56 | Cleanup targets (in separate section because of importance): 57 | 58 | clean-depends : remove work directories for dependencies 59 | clean : remove work directory 60 | distclean : remove distribution file(s) 61 | package-clean : remove binary package 62 | 63 | Package Development 64 | 65 | makesum : fetch and generate checksum for distributed file(s) 66 | makepatchsum : (re)generate checksum for patches 67 | makedistinfo : (re)generate distinfo file (creating checksums for distributed file and patches) 68 | print-PLIST : attempt to generate correct packaging list (NB! It helps, but it doesn't eliminate manual work.) 69 | 70 | EOF 71 | } 72 | search(){ 73 | packagedir=`dirname "${1}" | tr '/' '_'` 74 | packagename=`basename "${1}"` 75 | find "${PKGSRC}" -maxdepth 2 -mindepth 2 -type d \ 76 | | grep "${packagedir}/${packagename}" \ 77 | | sed -e "s@${PKGSRC}/@@" \ 78 | | tr '_' '/' 79 | } 80 | 81 | download_1(){ 82 | from="${1}" 83 | dest="${2}" 84 | if which wget > /dev/null ; then 85 | wget -O "${dest}" "${from}" 86 | elif which curl > /dev/null ; then 87 | if [ "${dest}" = "-" ] ; then 88 | curl -L "${from}" 89 | else 90 | curl -L -o "${dest}" -O "${from}" 91 | fi 92 | fi 93 | } 94 | 95 | download(){ 96 | from="${1}" 97 | dest="${2}" 98 | case "${from}" in 99 | https://*) download_1 "${from}" "${dest}" ;; 100 | http://*) download_1 "${from}" "${dest}" ;; 101 | *) cp "${from}" "${dest}" ;; 102 | esac 103 | } 104 | 105 | convert_repository_name(){ 106 | echo "${PKGSRC}/`echo ${1} | sed -e 's%/%_%g'`" 107 | } 108 | 109 | tap(){ 110 | if [ -d `convert_repository_name "${1}"` ]; then 111 | echo repository already exits: ${1} 112 | exit 1; 113 | fi 114 | 115 | mkdir `convert_repository_name "${1}"` 116 | 117 | echo "${1}" >> "${PKGHOME}/etc/user-repositories" 118 | 119 | download "https://github.com/${1}/archive/master.tar.gz" "-" \ 120 | | tar xz \ 121 | --strip-components 1 \ 122 | -C `convert_repository_name "${1}"` 123 | } 124 | 125 | untap(){ 126 | if [ -z `echo ${1} | tr -d -c '/'` ]; then 127 | echo \'${1}\' is not user repository 128 | exit 1; 129 | elif [ ! -d `convert_repository_name "${1}"` ]; then 130 | echo repository already removed: ${1} 131 | exit 1; 132 | fi 133 | 134 | echo Deleting repository... 135 | 136 | rm -r `convert_repository_name "${1}"` 137 | 138 | echo Completed. 139 | 140 | cp "${PKGHOME}/etc/user-repositories" \ 141 | "${PKGHOME}/etc/user-repositories.bak" 142 | 143 | cat "${PKGHOME}/etc/user-repositories.bak" \ 144 | | sed -e "s%${1}%##%g" \ 145 | | sed -e "/##/d" \ 146 | > "${PKGHOME}/etc/user-repositories" 147 | } 148 | 149 | update(){ 150 | download "${PKGHOST}" "-" \ 151 | | tar xj --strip-components 1 -C "${PKGSRC}" 152 | 153 | if [ -f "${PKGHOME}/etc/user-repositories" ]; then 154 | cat "${PKGHOME}/etc/user-repositories" | while read repo ;do 155 | untap "${repo}" 156 | tap "${repo}" 157 | done 158 | fi 159 | 160 | download "${PKGBREW}" "${PKGHOME}/bin/pkgbrew" 161 | 162 | chmod +x "${PKGHOME}/bin/pkgbrew" 163 | } 164 | description(){ 165 | package="${PKGSRC}/${1}" 166 | if [ ! -n "${1}" -o ! -d "${package}" ]; then 167 | echo No package \'${2}\' found, did you mead: 168 | search "${1}" | sed -e "s/^/ /" 169 | echo pkgbrew: package not found 170 | exit 1; 171 | fi 172 | 173 | cat "${package}/DESCR" 174 | } 175 | 176 | run_command(){ 177 | command="${1}" 178 | genre=`dirname "${2}" | tr '/' '_'` 179 | packagename=`basename "${2}"` 180 | packagedir="${PKGSRC}/${genre}/${packagename}" 181 | 182 | if [ ! -n "${2}" -o ! -d "${packagedir}" ]; then 183 | echo No package \'${2}\' found, did you mead: 184 | search "${2}" | sed -e "s/^/ /" 185 | echo pkgbrew: package not found 186 | exit 1; 187 | fi 188 | 189 | cd "${packagedir}" 190 | 191 | case "${command}" in 192 | "show-depends"|"show-options"|"print-PLIST") 193 | ${PKGHOME}/bin/bmake "${command}" ;; 194 | *) ${PKGHOME}/bin/bmake "${command}" | awk " 195 | BEGIN { 196 | flag=0 197 | } 198 | 199 | /^==========/ { 200 | if(flag == 1) { 201 | flag = 0; 202 | print; 203 | } else { 204 | flag = 1; 205 | } 206 | } 207 | 208 | /^=+>/ || flag == 1 { 209 | print; 210 | } 211 | " ;; 212 | esac 213 | } 214 | 215 | main(){ 216 | command="${1}" 217 | package="${2}" 218 | 219 | case "${command}" in 220 | "help") help ;; 221 | "search") search "${package}" ;; 222 | "tap") tap "${package}" ;; 223 | "untap") untap "${package}" ;; 224 | "version") version ;; 225 | "update") update ;; 226 | "description") description "${package}";; 227 | 228 | "help") run_command "${command}" "${package}" ;; 229 | "search") run_command "${command}" "${package}" ;; 230 | "setup") run_command "${command}" "${package}" ;; 231 | "depends") run_command "${command}" "${package}" ;; 232 | "fetch") run_command "${command}" "${package}" ;; 233 | "checksum") run_command "${command}" "${package}" ;; 234 | "extract") run_command "${command}" "${package}" ;; 235 | "patch") run_command "${command}" "${package}" ;; 236 | "configure") run_command "${command}" "${package}" ;; 237 | "all or build") run_command "${command}" "${package}" ;; 238 | "stage-install") run_command "${command}" "${package}" ;; 239 | "test") run_command "${command}" "${package}" ;; 240 | "package") run_command "${command}" "${package}" ;; 241 | "replace") run_command "${command}" "${package}" ;; 242 | "deinstall") run_command "${command}" "${package}" ;; 243 | "package-install") run_command "${command}" "${package}" ;; 244 | "install") run_command "${command}" "${package}" ;; 245 | "bin-install") run_command "${command}" "${package}" ;; 246 | "show-depends") run_command "${command}" "${package}" ;; 247 | "show-options") run_command "${command}" "${package}" ;; 248 | 249 | "clean-depends") run_command "${command}" "${package}" ;; 250 | "clean") run_command "${command}" "${package}" ;; 251 | "distclean") run_command "${command}" "${package}" ;; 252 | "package-clean") run_command "${command}" "${package}" ;; 253 | 254 | "makesum") run_command "${command}" "${package}" ;; 255 | "makepatchsum") run_command "${command}" "${package}" ;; 256 | "makedistinfo") run_command "${command}" "${package}" ;; 257 | "print-PLIST") run_command "${command}" "${package}" ;; 258 | *) echo Invalid command: ${1} 259 | help ;; 260 | esac 261 | } 262 | 263 | main "${1}" "${2}" 264 | --------------------------------------------------------------------------------