diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2017-11-10 19:33:33 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2017-11-10 19:33:33 -0200 |
commit | 53358cef686ccdac63083068fd53a2b61cd6e2aa (patch) | |
tree | 087b47bb668943ed9945c38124a56f0c38ba84d5 /share | |
parent | 2984eee82b89f7b2e86f291f0a73818904d18f43 (diff) | |
download | trashman-53358cef686ccdac63083068fd53a2b61cd6e2aa.tar.gz trashman-53358cef686ccdac63083068fd53a2b61cd6e2aa.tar.bz2 |
Initial operation
Diffstat (limited to 'share')
-rw-r--r-- | share/trashman/trashman/functions | 141 | ||||
-rw-r--r-- | share/trashman/trashman/info | 1 | ||||
-rwxr-xr-x | share/trashman/trashman/unix/install | 24 | ||||
-rwxr-xr-x | share/trashman/trashman/unix/remove | 10 | ||||
-rwxr-xr-x | share/trashman/trashman/unix/test | 25 |
5 files changed, 201 insertions, 0 deletions
diff --git a/share/trashman/trashman/functions b/share/trashman/trashman/functions new file mode 100644 index 0000000..52dbfc6 --- /dev/null +++ b/share/trashman/trashman/functions @@ -0,0 +1,141 @@ +#!/bin/bash +# +# trashman basic functions. +# + +# Make sure we're running git directly and not any existing wrapper +GIT="/usr/bin/git" +DIRNAME="$SHARE/../.." + +# Message +__trashman_echo() { + #echo "" + echo "-> $*" +} + +# Our most common ancestor +__trashman_ancestor() { + echo "unix" +} + +# Determine OS family +__trashman_family() { + uname | tr '[:upper:]' '[:lower:]' +} + +# Determine distro name +__trashman_distro() { + local uname="`__trashman_family`" + + if [ "$uname" = "linux" ]; then + if [ -e "/etc/debian_version" ]; then + echo "debian" + else + echo "linux" + fi + fi +} + +# Return the folder where actions are available for a package +__trashman_actions_folder() { + local package="$1" + local actions="" + local ancestor="`__trashman_ancestor`" + local family="`__trashman_family`" + local distro="`__trashman_distro`" + local findopts="-maxdepth 1 -type f -executable -exec basename {}" + + if [ -z "$package" ]; then + return + fi + + if [ ! -d "$SHARE/$package/$ancestor" ]; then + return + fi + + if [ -d "$SHARE/$package/$ancestor/$family/$distro" ]; then + actions="`find $SHARE/$package/$ancestor/$family/$distro $findopts \; | xargs`" + else + actions="" + fi + + if [ -z "$actions" ]; then + if [ -d "$SHARE/$package/$ancestor/$family" ]; then + actions="`find $SHARE/$package/$ancestor/$family $findopts \; | xargs`" + else + actions="" + fi + + if [ -z "$actions" ]; then + actions="`find $SHARE/$package/$ancestor $findopts \; | xargs`" + + if [ ! -z "$actions" ]; then + echo $ancestor + fi + else + echo $ancestor/$family + fi + else + echo $ancestor/$family/$distro + fi +} + +# Return the list of available actions from a package +__trashman_actions() { + local package="$1" + local findopts="-maxdepth 1 -type f -executable -exec basename {}" + + if [ -z "$package" ]; then + return + fi + + local folder="`__trashman_actions_folder $package`" + + if [ ! -z "$SHARE/$package/$folder" ]; then + find $SHARE/$package/$folder $findopts \; | xargs + fi +} + +# Return list of implementations +__trashman_implementations() { + local actions="" + local implementations="" + + for package in `ls $SHARE`; do + actions="`__trashman_actions $package`" + + if [ ! -z "$actions" ]; then + implementations="$implementations $package" + fi + done + + echo $implementations +} + +# Version information +__trashman_version() { + echo "master branch:" + echo "==============" + echo "" + ( cd $DIRNAME && $GIT log --show-signature -n 1 ) + + echo "" + echo "origin/master branch:" + echo "=====================" + echo "" + ( cd $DIRNAME && $GIT log --show-signature -n 1 --remotes --branches=origin/master ) +} + +# Fetch +__trashman_fetch() { + ( cd $DIRNAME && $GIT fetch --all && $GIT log --show-signature -n 1 --remotes --branches=origin/master ) +} + +# Merge +__trashman_merge() { + ( + cd $DIRNAME && $GIT merge origin/master && \ + $GIT submodule sync --recursive && \ + $GIT submodule update --init --recursive + ) +} diff --git a/share/trashman/trashman/info b/share/trashman/trashman/info new file mode 100644 index 0000000..0ee1124 --- /dev/null +++ b/share/trashman/trashman/info @@ -0,0 +1 @@ +system-wide trashman installation diff --git a/share/trashman/trashman/unix/install b/share/trashman/trashman/unix/install new file mode 100755 index 0000000..289a653 --- /dev/null +++ b/share/trashman/trashman/unix/install @@ -0,0 +1,24 @@ +#!/usr/bin/env sh +# +# Install trashman system-wide. +# + +# Parameters +SHARE="$1" +BASE="$SHARE/../.." +FOLDER="/usr/local" + +# Include basic functions +. $SHARE/trashman/functions || exit 1 + +# Check for rsync +if ! which rsync > /dev/null 2>&1; then + __trashman_echo "Needs rsync to install trashman" + exit 1 +fi + +# Install +rsync -av --delete $BASE/ $FOLDER/share/trashman/ || exit 1 + +# Create symlink +( cd $FOLDER/bin && ln -sf $FOLDER/share/trashman/trashman ) || exit 1 diff --git a/share/trashman/trashman/unix/remove b/share/trashman/trashman/unix/remove new file mode 100755 index 0000000..22c24d7 --- /dev/null +++ b/share/trashman/trashman/unix/remove @@ -0,0 +1,10 @@ +#!/usr/bin/env sh +# +# Remove trashman system-wide. +# + +# Parameters +FOLDER="/usr/local" + +# Remove trashman +rm -rf $FOLDER/bin/trashman $FOLDER/share/trashman diff --git a/share/trashman/trashman/unix/test b/share/trashman/trashman/unix/test new file mode 100755 index 0000000..1614d20 --- /dev/null +++ b/share/trashman/trashman/unix/test @@ -0,0 +1,25 @@ +#!/usr/bin/env sh +# +# Test if trashman is installed system-wide. +# + +# Parameters +SHARE="$1" +BASE="$SHARE/../.." +FOLDER="/usr/local" + +# Include basic functions +. $SHARE/trashman/functions || exit 1 + +# Check if it is installed +if [ -x "$FOLDER/bin/trashman" ] && [ -x "$FOLDER/share/trashman/trashman" ]; then + exit 0 +fi + +# Check if it is not installed +if [ ! -x "$FOLDER/bin/trashman" ] && [ ! -x "$FOLDER/share/trashman/trashman" ]; then + exit 1 +fi + +# It is partially installed +exit 2 |