Created
March 6, 2012 20:58
-
-
Save fuzzy/1988934 to your computer and use it in GitHub Desktop.
start of the cpkg system for managing multiple versions of whatever on a session by session basis
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
OS=$(uname -s) | |
LNDIR=$(which lndir) | |
# Setup for our OS, Linux maybe someday. | |
case "${OS}" in | |
Linux) | |
PKG_DIR="${HOME}/.custom/pkgdir/${OS}" | |
GO_DIR="${HOME}/.custom/go/${OS}" | |
PLATFORM="${OS}" | |
SHA1=$(which sha1sum) | |
MKTEMP="$(which mktemp)" | |
if [ -f /etc/slackware-version ]; then | |
VERS=$(cat /etc/slackware-version|awk '{print $2}') | |
PKG_DIR="${PKG_DIR}/Slackware/${VERS}" | |
GO_DIR="${GO_DIR}/Slackware/${VERS}" | |
PLATFORM="${OS} Slackware ${VERS}" | |
elif [ -f '/etc/arch-release' ]; then | |
VERS=$(uname -m) | |
PKG_DIR="${PKG_DIR}/Arch/${VERS}" | |
GO_DIR="${GO_DIR}/Arch/${VERS}" | |
PLATFORM="${OS} Arch ${VERS}" | |
else | |
VERS=$(uname -r) | |
PKG_DIR="${PKG_DIR}/Generic" | |
GO_DIR="${GO_DIR}/Generic" | |
PLATFORM="Linux Generic" | |
fi | |
C_ENTROPY="$(echo '$(date +%S)+${USER}${HOME}$(hostname)+$(dd if=/dev/urandom bs=512 count=1 2>/dev/null)')" | |
HASH="$(echo ${C_ENTROPY}|${SHA1}|awk '{print $1}')" | |
;; | |
FreeBSD) | |
PKG_DIR="${HOME}/.custom/pkgdir/${OS}" | |
GO_DIR="${HOME}/.custom/go/${OS}" | |
PLATFORM="${OS}" | |
SHA1=$(which sha1) | |
MKTEMP="$(which mktemp) -t" | |
HASH="$(echo '$(date +%S)+${USER}${HOME}$(hostname)+$(dd if=/dev/urandom bs=512 count=1 2>/dev/null)'|${SHA1})" | |
;; | |
esac | |
# Build our environment | |
BASE_DIR="${HOME}/.custom/pkg/${HASH}" | |
P_DEFAULTS="${BASE_DIR}/defaults" | |
P_BIN="${BASE_DIR}/bin" | |
P_SBIN="${BASE_DIR}/sbin" | |
P_SHARE="${BASE_DIR}/share" | |
P_LIB="${BASE_DIR}/lib" | |
P_ETC="${BASE_DIR}/etc" | |
P_LIBEXEC="${BASE_DIR}/libexec" | |
P_LIB32="${BASE_DIR}/lib32" | |
P_INCLUDE="${BASE_DIR}/include" | |
# Just ensure that our base directories are present. | |
for i in ${PKG_DIR} ${GO_DIR} ${BASE_DIR} ${P_BIN} ${P_SBIN} ${P_ETC} ${P_SHARE} ${P_LIB} ${P_LIBEXEC} ${P_LIB32} ${P_INCLUDE}; do | |
if [ ! -d ${i} ]; then mkdir -p ${i}; fi | |
done | |
cpkg() { | |
case "${1}" in | |
list|l) | |
if [ -z "${2}" ]; then | |
echo "Usage: ${0} ${1} <pkg>" | |
else | |
echo "Versions for ${2} on ${PLATFORM}:\nDefault: $(grep ${2} ${PKG_DIR}/defaults)" | |
ls ${PKG_DIR}|grep -e "${2}-"|awk -F'-' '{print $2}'|sort | |
fi | |
;; | |
use|u) | |
if [ ! -d ${PKG_DIR}/${2}-${3} ]; then | |
echo "USAGE: ${0} ${1} <pkgname> <pkgvers>" | |
else | |
if [ ! -z "$(grep ${2}-${3} ${PKG_DIR}/defaults)" ]; then | |
echo "${2}-${3} is already the default for this platform." | |
elif [ ! -z "$(grep ${2} ${PKG_DIR}/defaults)" ]; then | |
curr=$(grep ${2} ${PKG_DIR}/defaults) | |
echo "Do you wish to replace ${curr} as default?" | |
select ans in yes no; do | |
case ${ans} in | |
n|no) REPL="no"; break ;; | |
y|yes) REPL="yes"; break ;; | |
*) REPL="no" ; break ;; | |
esac | |
done | |
case "${REPL}" in | |
yes) | |
tmpf=$(${MKTEMP}) #mktemp -t defaults) | |
grep -v ${2} ${PKG_DIR}/defaults >${tmpf} | |
mv ${PKG_DIR}/defaults ${PKG_DIR}/defaults.bak | |
mv ${tmpf} ${PKG_DIR}/defaults | |
echo "Setting ${2}-${3} as the default for ${OS}." | |
echo "${2}-${3}" >> ${PKG_DIR}/defaults | |
cpkg_recycle | |
;; | |
esac | |
else | |
echo "Setting ${2}-${3} as the default for ${OS}." | |
echo "${2}-${3}" >> ${PKG_DIR}/defaults | |
cpkg recycle | |
fi | |
fi | |
;; | |
install|i) ;; | |
purge|p) ;; | |
recycle|r) | |
printf "Please wait while the session paths are being built... " | |
env rm -rf ${BASE_DIR}/* | |
for i in ${P_BIN} ${P_SBIN} ${P_SHARE} ${P_LIB} ${P_ETC} ${P_LIBEXEC} ${P_LIB32} ${P_INCLUDE}; do | |
if [ ! -d ${i} ]; then mkdir -p ${i}; fi | |
done | |
ln -s ${BASE_DIR}/share/man ${BASE_DIR}/man | |
for pkg in $(cat ${PKG_DIR}/defaults); do | |
for dir in $(ls ${PKG_DIR}/${pkg}/); do | |
${LNDIR} -silent ${PKG_DIR}/${pkg}/${dir}/ ${BASE_DIR}/${dir}/ | |
done | |
done | |
echo "Done" | |
temp=$(${MKTEMP}) #mktemp -t path) | |
echo "export PATH=${P_BIN}:${P_SBIN}:${HOME}/.custom/noarch:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/pkg/bin:/usr/pkg/sbin:/usr/X11R6/bin:/usr/X11R6/sbin:/usr/X11R7/bin:/usr/X11R7/sbin" >>${temp} | |
echo "export LDFLAGS=-L${P_LIB}" >>${temp} | |
echo "export CFLAGS=-I${P_INCLUDE}" >>${temp} | |
source ${temp} | |
case "${OS}" in | |
FreeBSD) export MANPATH=$(manpath -q) ;; | |
Linux) export MANPATH="${MANPATH}:${BASE_DIR}/share/man:${BASE_DIR}/man" ;; | |
esac | |
rm -f ${temp} | |
;; | |
help|h) | |
echo "\nCpkg v0.4 by Mike 'Fuzzy' Partin <[email protected]>\n" | |
echo "Usage: ${0} [cmd] <opts>\n" | |
echo "\tl list\t\tList versions for package <pkg> (ie: ruby)" | |
echo "\tu use\t\tUse <pkg> <version> (ie: ${0} u ruby 1.9.0p0)" | |
echo "\ti install\tWrapper around configure/make/make install (CONCEPTUAL)" | |
echo "\tp purge\t\tRemove <pkg> <version> from your archive. (ie: ${0} p ruby 1.9.0p0)" | |
echo "\tr recycle\tRebuild your session paths." | |
echo "\th help\t\tShow this help message.\n" | |
;; | |
usage) cpkg help ;; | |
*) cpkg help ;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment