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 | |
parent | 2984eee82b89f7b2e86f291f0a73818904d18f43 (diff) | |
download | trashman-53358cef686ccdac63083068fd53a2b61cd6e2aa.tar.gz trashman-53358cef686ccdac63083068fd53a2b61cd6e2aa.tar.bz2 |
Initial operation
-rw-r--r-- | CODE_OF_CONDUCT.md | 74 | ||||
-rw-r--r-- | README.md | 48 | ||||
-rw-r--r-- | TODO.md | 4 | ||||
-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 | ||||
-rwxr-xr-x | trashman | 109 |
9 files changed, 424 insertions, 12 deletions
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..234ed0f --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at [INSERT EMAIL ADDRESS]. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + @@ -14,20 +14,20 @@ docker. Some stuff are hard to package or upstream makes the effort to keep it harder and harder to package. Distros are left behind the planned obsolescence. -This alleviates the pain like ff you find yourself in the urge to install that -hyped application but have no choice other than run magic commands and install -untrusted code. +This humble tool alleviates the pain like if you find yourself in the urge to +install that hyped application but have no choice other than run magic commands +and install untrusted code. -It replace curl-pipe-bash statements like +It replaces curl-pipe-bash statements like - curl -L $backdoor_url | bash + curl $backdoor_url | bash by this one: trashman install <package> -Instead of being just a shorthand, `trashman` packages try to be as best as possible -to no fetch keys and scripts from remote locations without some basic checks. So if +Instead of being just a shorthand, `trashman` packages try as best as possible +not to fetch keys and scripts from remote locations without some basic checks. So if you have to add files into `/etc/apt/trusted.gpg.d`, `trashman` will provide those keys or fingerprints instead of donwloading it from somewhere, in which case it could be easily tampered. @@ -102,21 +102,46 @@ do the actual merge: trashman merge +## How it works + +Basically `trashman` is just a dispatcher/router for scripts available under +it's `share/` directory. It scans every available package for the available +implementation that best fits your current distro. + +Say that you're running Debian GNU/Linux. First trashman tries to find scripts +that matches `debian` distro, trying `linux` target next and finally `unix`. + +This ways, it's possible to implement generic package management procedures +as longs as specific to each distro. + ## Writing a package You might use [templater](https://templater.fluxo.info): - cd path/to/trashman/repo && templater share/package/<package_name> dumpster + cd path/to/trashman/repo && templater share/package/<package_name> trashman packages are simply as having the following files: -* `share/trashman/<name>/info`: describe package purpose. -* `share/trashman/<name>/<distro>/<action>`: script that runs on a given action. +* `share/trashman/<package>/info`: describe package purpose. +* `share/trashman/<package>/<ancestor>/<family>/<distro>/<action>`: script that runs on a given action. +* `share/trashman/<package>/<ancestor>/<family>/<action>`: script that runs on a given action, fallback. +* `share/trashman/<package>/<ancestor>/<action>`: script that runs on a given action, fallback. Where actions can be like `install`, `test`, `remove` or `upgrade`. You don't have to implement all actions. Actually, no action is required to create a package, but having no action makes it useless. +### Test action + +The test action may return the following exit codes: + +* 0: the package is installed system-wide. +* 1: the package is not installed system-wide. +* 2: the package is partially installed system-wide. + +Yes. This is far from deterministic builds. We're talking about scripts that might fail +anytime, due to network errors or inconsistencies. + ### Idempotency Shit. I think I can't even spell this word correctly. Idempowhat? So you're saying @@ -131,6 +156,9 @@ You don't need a DSL to do that. It's as simply as It's recommended that you try to make your packaging script to be idempotent. +This way,`trashman` turns into a configuration manager, going beyond the basic +package management. + ## Naming candidates While designing this tools, the following names were considered: @@ -1,8 +1,8 @@ TODO ==== -* Basic functioning. -* Argument passing to distro/action scripts? +* Support more OSes at `__trashman_distro()`. +* Argument passing to distro/action scripts as `--param=value`. * Packages: * docker, nodejs, composer * https://github.com/Crizstian/cinema-microservice 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 diff --git a/trashman b/trashman new file mode 100755 index 0000000..29dc450 --- /dev/null +++ b/trashman @@ -0,0 +1,109 @@ +#!/usr/bin/env sh +# +# Provision: install stuff using scripts. +# +# Copyright (C) 2017 Silvio Rhatto - rhatto at riseup.net +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Parameters +NAME="trashman" +PROGRAM="$0" +BASENAME="`basename $0`" +ACTION="$1" +CWD="`pwd`" + +# Set shared files location +if [ -e "`dirname $(readlink -f $0)`/share/$NAME" ]; then + # Development or local installation layout + SHARE="`dirname $(readlink -f $0)`/share/$NAME" +else + # System installation layout + SHARE="`dirname $(readlink -f $0)`/../share/$NAME" +fi + +# Include basic functions +. $SHARE/trashman/functions || exit 1 + +# Display usage +__trashman_usage() { + echo "$BASENAME: package ports tree and heterodox configuration provisioner" + echo "" + echo "usage: $BASENAME <fetch|merge>" + echo "usage: $BASENAME <action> [<package1> ... <packageN>] [<--param1=value1> ... <--paramM=valueM>]" + echo "" + echo "available packages:" + echo "" + + for package in `__trashman_implementations`; do + if [ -e "$SHARE/$package/info" ]; then + echo "\t $package: `cat $SHARE/$package/info` (`__trashman_actions $package | sed -e 's/ /|/g'`)" + fi + done + + echo "" + exit 1 +} + +# Dispatch +if [ -z "$ACTION" ]; then + __trashman_usage +elif [ "$ACTION" = "fetch" ]; then + __trashman_$ACTION +elif [ "$ACTION" = "merge" ]; then + __trashman_$ACTION +elif [ "$ACTION" = "version" ]; then + __trashman_$ACTION +else + # Get packages param + shift + PACKAGES="$*" + + # Setup packages + if [ -z "$PACKAGES" ]; then + __trashman_usage + else + for package in $PACKAGES; do + if [ ! -z "`__trashman_actions $package`" ]; then + folder="`__trashman_actions_folder $package`" + + if [ -x "$SHARE/$package/$folder/$ACTION" ]; then + if [ "$ACTION" != "test" ]; then + __trashman_echo "Dumpsterizing your system: action $ACTION for $package ($folder)..." + fi + + $SHARE/$package/$folder/$ACTION $SHARE + status="$?" + + if [ "$ACTION" = "test" ]; then + if [ "$status" = "0" ]; then + __trashman_echo "Package trashman is installed system-wide" + elif [ "$status" = "1" ]; then + __trashman_echo "Package trashman is not installed system-wide" + elif [ "$status" = "2" ]; then + __trashman_echo "Package trashman is partially installed system-wide" + fi + fi + else + __trashman_echo "No such action $ACTION for package $package, skipping" + fi + else + __trashman_echo "No such package $package, skipping" + fi + done + + # Exit with the latest return status + exit $status + fi +fi |