squidpm

the squid package manager
git clone git://squid-tech.com/squidpm.git
Log | Files | Refs | README | LICENSE

commit c170396e6a08731b7c246badd4e902780782526d
parent f138214b186f2dc8ed7dd2bca1b7ebc34d8f4979
Author: Josh Moore <jxm5210@g.rit.edu>
Date:   Thu, 16 Jan 2020 20:40:18 -0500

Merge pull request #18 from joshiemoore/generalize

Generalization overhaul
Diffstat:
MREADME.md | 2+-
Apackage_exec.sh | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/all | 33++++++++++++++++++---------------
Mpackages/busybox | 31++++++++++++-------------------
Mpackages/direwolf | 33+++++++++++++--------------------
Mpackages/dmenu | 32++++++++++++--------------------
Mpackages/dwm | 32++++++++++++--------------------
Dpackages/example | 48------------------------------------------------
Mpackages/farbfeld | 32++++++++++++--------------------
Mpackages/godwordshappy | 31++++++++++++-------------------
Mpackages/linux | 32++++++++++++--------------------
Mpackages/neofetch | 31++++++++++++-------------------
Apackages/package_base | 17+++++++++++++++++
Mpackages/quark | 31++++++++++++-------------------
Mpackages/sent | 32+++++++++++++-------------------
Mpackages/slock | 32++++++++++++--------------------
Mpackages/squidpm | 31++++++++++++++++---------------
Mpackages/st | 31++++++++++++-------------------
Msquidpm.sh | 77+++++++++++++----------------------------------------------------------------
19 files changed, 280 insertions(+), 377 deletions(-)

diff --git a/README.md b/README.md @@ -1,5 +1,5 @@ # squidpm -The Squid Package Manager is a utility for easily managing local copies of git repositories. Package management scripts are located in the `packages/` directory. See `packages/example` and other packages for examples of how you could add your own packages. +The Squid Package Manager is a utility for easily managing local copies of git repositories. Package management scripts are located in the `packages/` directory. This tool is designed to be extremely modular and extensible, you should be able to add your own packages with ease. This is intended primarily to be a tool for personal use, but I will accept pull requests and add packages to this repository if they are genuinely libre software. diff --git a/package_exec.sh b/package_exec.sh @@ -0,0 +1,69 @@ +# verify that the package exists +if [ ! -f $SPMDIR/packages/$2 ]; then + echo "Unrecognized package '$2'." + exit +fi + +source $SPMDIR/packages/$2 + +if [ $1 = "install" ]; then + # verify that the package isn't already installed + if [ -d $SPMDIR/repos/$2 ]; then + echo "Package '$2' is already installed." + exit + fi + + # create a repo for this package if it doesn't exist + if [ $2 != "squidpm" ] && [ $2 != "all" ] && [ ! $GITURL = "" ]; then + mkdir -p $SPMDIR/repos/$2 + cd $SPMDIR/repos/$2 + + # clone the repo + if [ $2 = "linux" ]; then + # do a shallow clone, linux is huge... + git clone --depth 1 $GITURL . + else + git clone $GITURL . + fi + fi + + install +elif [ $1 = "uninstall" ]; then + # verify that the package is installed + if [ ! -d $SPMDIR/repos/$2 ] && [ $2 != "all" ]; then + echo "Package '$2' is not installed." + exit + fi + + if [ $2 = "all" ]; then + uninstall + exit + fi + + cd $SPMDIR/repos/$2 + uninstall + + [ $2 = "squidpm" ] && exit + + cd .. + rm -rf $SPMDIR/repos/$2 +elif [ $1 = "update" ]; then + # verify that the package is installed + if [ ! -d $SPMDIR/repos/$2 ] && [ $2 != "all" ]; then + echo "Package '$2' is not installed." + exit + fi + + [ $2 != "all" ] && cd $SPMDIR/repos/$2 + update +elif [ $1 = "check" ]; then + # check whether the package is installed + + if [ -d $SPMDIR/repos/$2 ]; then + exit 1 + else + exit 0 + fi +else + echo "Unrecognized operation '$1'." +fi diff --git a/packages/all b/packages/all @@ -1,39 +1,42 @@ # This is a special package that performs the specified operation # on all available packages. -# the name of this package -me=$(basename "$0") -# the directory of this package -mydir=$(dirname "$0") +source $SPMDIR/packages/package_base -if [ $1 = "install" ]; then +install() +{ # installation behavior for this package - # make, make install, etc echo "Installing all squidpm packages..." - for f in $mydir/* + for f in $SPMDIR/packages/* do - if [ $(basename $f) != $me ]; then + if [ ! $(basename $f) = "all" ]; then squidpm install $(basename $f) fi done -elif [ $1 = "uninstall" ]; then +} + +uninstall() +{ # uninstallation behavior for this package echo "Uninstalling all installed packages..." - for f in $mydir/../repos/* + for f in $SPMDIR/repos/* do - if [ $(basename $f) != $me ]; then + if [ ! $(basename $f) = "all" ]; then squidpm uninstall $(basename $f) fi done -elif [ $1 = "update" ]; then +} + +update() +{ # update behavior for this package echo "Updating all installed packages..." - for f in $mydir/../repos/* + for f in $SPMDIR/repos/* do - if [ $(basename $f) != $me ]; then + if [ ! $(basename $f) = "all" ]; then squidpm update $(basename $f) fi done -fi +} diff --git a/packages/busybox b/packages/busybox @@ -1,31 +1,24 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://github.com/mirror/busybox.git -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package make defconfig && make make install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package make clean +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull make -fi +} diff --git a/packages/direwolf b/packages/direwolf @@ -1,31 +1,22 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://github.com/wb2osz/direwolf.git -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - # create a repo dir for this package if it doesn't exist - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package make sudo make install make install-conf echo "Installed direwolf." -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me +} + +uninstall() +{ # uninstallation behavior for this package make clean - cd .. - rm -rf $me - rm -f ~/direwolf.conf rm -f ~/dw-start.sh rm -f ~/sdr.conf @@ -34,10 +25,12 @@ elif [ $1 = "uninstall" ]; then rm -f ~/telem-m0xer-3.txt echo "Uninstalled direwolf." -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +} + +update() +{ # update behavior for this package git pull make sudo make install -fi +} diff --git a/packages/dmenu b/packages/dmenu @@ -1,31 +1,23 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://git.suckless.org/dmenu -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - # create a repo dir for this package if it doesn't exist - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package sudo make clean install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make clean uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull sudo make clean install -fi +} diff --git a/packages/dwm b/packages/dwm @@ -1,33 +1,25 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://git.suckless.org/dwm -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - # create a repo dir for this package if it doesn't exist - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package sudo make clean install echo "Note that additional config may be required to run dwm." echo "See https://dwm.suckless.org/tutorial/" -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make clean uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull sudo make clean install -fi +} diff --git a/packages/example b/packages/example @@ -1,48 +0,0 @@ -# -# This is an example package management script that could serve as a -# "template" for how you could add some of your own packages to squidpm. -# Set GITURL to the public URL of the git repo, then fill out each of the -# "install", "uninstall", and "update" sections with the expected behavior -# for each of these operations. -# -# When you reach the install/uninstall/update sections, your working directory -# will be the directory of the local git repo for your package. -# -# If your package has dependencies, you will need to check whether they are installed -# using: -# squidpm check <dependency> -# in the install section, and install them as necessary. -# The check operation returns 1 if the package is installed, and 0 otherwise. -# - -# set this to the public git url of the package -GITURL= - -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - # create a repo dir for this package if it doesn't exist - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - #git clone $GITURL . - - # installation behavior for this package - # make, make install, etc - echo "Installed example package!" -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package - - cd .. - rm -rf $me - - echo "Uninstalled example package!" -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me - # update behavior for this package - echo "Updated example package!" -fi diff --git a/packages/farbfeld b/packages/farbfeld @@ -1,31 +1,23 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://git.suckless.org/farbfeld -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - # create a repo dir for this package if it doesn't exist - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package sudo make clean install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make clean uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull sudo make clean install -fi +} diff --git a/packages/godwordshappy b/packages/godwordshappy @@ -1,29 +1,22 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://github.com/joshiemoore/godwordshappy.git -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package sudo make install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull -fi +} diff --git a/packages/linux b/packages/linux @@ -1,31 +1,23 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://github.com/torvalds/linux.git -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - # do a shallow clone, linux is huge... - git clone --depth 1 $GITURL . - +install() +{ # installation behavior for this package make defconfig && make -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make clean +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull make -fi +} diff --git a/packages/neofetch b/packages/neofetch @@ -1,30 +1,23 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://github.com/dylanaraps/neofetch -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package sudo make install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation for this behavior sudo make uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull sudo make install -fi +} diff --git a/packages/package_base b/packages/package_base @@ -0,0 +1,17 @@ +# Packages should override these functions to perform their +# corresponding operations from within their git repos. + +install() +{ + echo "This package has not specified an installation behavior." +} + +uninstall() +{ + echo "This package has not specified an uninstallation behavior." +} + +update() +{ + echo "This package has not specified an update behavior." +} diff --git a/packages/quark b/packages/quark @@ -1,30 +1,23 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://git.suckless.org/quark -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package sudo make clean install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make clean uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull sudo make clean install -fi +} diff --git a/packages/sent b/packages/sent @@ -1,14 +1,11 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://git.suckless.org/sent -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - # create a repo dir for this package if it doesn't exist - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me +install() +{ + # installation behavior for this package # check dependencies squidpm check farbfeld @@ -16,22 +13,19 @@ if [ $1 = "install" ]; then echo "Installing dependency: farbfeld" squidpm install farbfeld fi - # clone the repo - git clone $GITURL . - # installation behavior for this package sudo make clean install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make clean uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull sudo make clean install -fi +} diff --git a/packages/slock b/packages/slock @@ -1,31 +1,23 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://git.suckless.org/slock -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - # create a repo dir for this package if it doesn't exist - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package sudo make clean install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make clean uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull sudo make clean install -fi +} diff --git a/packages/squidpm b/packages/squidpm @@ -1,29 +1,30 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://github.com/joshiemoore/squidpm.git -# the name of this package -me=$(basename "$0") -# the directory of this package -mydir=$(dirname "$0") - -cd $mydir/../ - -if [ $1 = "install" ]; then +install() +{ # installation behavior for this package # create symlinks - sudo ln -s $PWD/squidpm.sh /usr/local/bin/squidpm - sudo ln -s $PWD $PWD/repos/squidpm + sudo ln -s $SPMDIR/squidpm.sh /usr/local/bin/squidpm + sudo ln -s $SPMDIR $SPMDIR/repos/squidpm echo "Installed squidpm!" -elif [ $1 = "uninstall" ]; then - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package # remove symlinks sudo rm -f /usr/local/bin/squidpm - sudo rm -f $PWD/repos/squidpm + sudo rm -f $SPMDIR/repos/squidpm echo "Uninstalled squidpm." -elif [ $1 = "update" ]; then +} + +update() +{ # update behavior for this package git pull -fi +} diff --git a/packages/st b/packages/st @@ -1,30 +1,23 @@ +source $SPMDIR/packages/package_base + # set this to the public git url of the package GITURL=https://git.suckless.org/st -# the name of this package -me=$(basename "$0") -mydir=$(dirname "$0") - -if [ $1 = "install" ]; then - mkdir -p $mydir/../repos/$me - cd $mydir/../repos/$me - - # clone the repo - git clone $GITURL . - +install() +{ # installation behavior for this package sudo make clean install -elif [ $1 = "uninstall" ]; then - cd $mydir/../repos/$me - # uninstallation behavior for this package +} +uninstall() +{ + # uninstallation behavior for this package sudo make clean uninstall +} - cd .. - rm -rf $me -elif [ $1 = "update" ]; then - cd $mydir/../repos/$me +update() +{ # update behavior for this package git pull sudo make clean install -fi +} diff --git a/squidpm.sh b/squidpm.sh @@ -19,10 +19,9 @@ #\TODO clean up commands # resolve the actual squidpm directory -SPMDIR=$(dirname $(readlink -f "$0")) +export SPMDIR=$(dirname $(readlink -f "$0")) if [ "$#" -eq 0 ]; then - #\TODO detailed usage message echo "Squid Package Manager" echo "usage: squidpm <operation> [package]" exit @@ -33,67 +32,17 @@ if [ "$#" -gt 2 ]; then exit fi -if [ "$#" -eq 1 ]; then - if [ $1 = "list" ]; then - # list all installed packages - ls -1 $SPMDIR/repos/ - elif [ $1 = "help" ]; then - # print the help message - cat $SPMDIR/docs/operations.txt - else - echo "Invalid operation '$1'." - fi - - exit -fi - - -# make sure the package exists -if [ ! -f $SPMDIR/packages/$2 ]; then - echo "Unrecognized package '$2'." - exit -fi - -# create the repos/ directory (if it doesn't exist) -mkdir -p $SPMDIR/repos/ - - -if [ $1 = "install" ]; then - # verify the package isn't already installed - if [ -d $SPMDIR/repos/$2 ]; then - echo "Package '$2' already installed." - exit - fi - - # if not, install the package - /bin/sh $SPMDIR/packages/$2 install -elif [ $1 = "uninstall" ]; then - # verify that the package is installed - if [ ! -d $SPMDIR/repos/$2 ] && [ $2 != "all" ]; then - echo "Package '$2' is not installed." - exit - fi - - # if so, uninstall the package - /bin/sh $SPMDIR/packages/$2 uninstall -elif [ $1 = "update" ]; then - # verify that the package is installed - if [ ! -d $SPMDIR/repos/$2 ] && [ $2 != "all" ]; then - echo "Package '$2' is not installed." - exit - fi - - # if so, update the package - /bin/sh $SPMDIR/packages/$2 update -elif [ $1 = "check" ]; then - # check whether the package is installed - - if [ -d $SPMDIR/repos/$2 ]; then - exit 1 - else - exit 0 - fi +if [ $1 = "list" ]; then + # list all installed packages + ls -1 $SPMDIR/repos/ +elif [ $1 = "help" ]; then + # print the help message + cat $SPMDIR/docs/operations.txt else - echo "Invalid operation '$1'." - exit + # create the repos directory (if it doesn't exist) + mkdir -p $SPMDIR/repos/ + + # execute the specified behavior for the selected package + /bin/sh $SPMDIR/package_exec.sh $1 $2 + exit $? fi