Verified Commit 0a02fe68 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add scripts for package management

parent dc51e1c1
Loading
Loading
Loading
Loading
Loading

LICENSE_HEADER

deleted100644 → 0
+0 −24
Original line number Original line Diff line number Diff line
Copyright (C) 2017-2018 Barcelona Supercomputing Center
                        Centro Nacional de Supercomputacion
All rights reserved.

This file is part of the NORNS Data Scheduler, a service that allows
other programs to start, track and manage asynchronous transfers of
data resources transfers requests between different storage backends.

See AUTHORS file in the top level directory for information
regarding developers and contributors.

The NORNS Data Scheduler is free software: you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.

The NORNS Data Scheduler 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General
Public License along with the NORNS Data Scheduler.  If not, see
<http://www.gnu.org/licenses/>.

scripts/NORNS.erb

0 → 100644
+16 −0
Original line number Original line Diff line number Diff line
Copyright (C) <%=copyright_years.join(', ')%> Barcelona Supercomputing Center
                        Centro Nacional de Supercomputacion
All rights reserved.

This file is part of <%=copyright_software%>, <%=copyright_software_description%>.

See AUTHORS file in the top level directory for information regarding developers and contributors.

This software was developed as part of the EC H2020 funded project NEXTGenIO (Project ID: 671951). 
    www.nextgenio.eu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

scripts/syntax.man.yml

0 → 100644
+28 −0
Original line number Original line Diff line number Diff line
#
# Copyright Header - A utility to manipulate copyright headers on source code files
# Copyright (C) 2012-2017 Erik Osterman <e@osterman.com>
#
# This file is part of Copyright Header.
#
# Copyright Header 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
# (at your option) any later version.
#
# Copyright Header 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 Copyright Header.  If not, see <http://www.gnu.org/licenses/>.
#

man:
  ext: ['.in']
  comment:
    open:   '.\"*************************************************************************\n'
    close:  '.\"*************************************************************************\n\n'
    prefix: '.\"  '
    suffix: ' *\n'
    padding: 6

scripts/syntax.yml

0 → 100644
+331 −0
Original line number Original line Diff line number Diff line
#
# Copyright Header - A utility to manipulate copyright headers on source code files
# Copyright (C) 2012-2017 Erik Osterman <e@osterman.com>
#
# This file is part of Copyright Header.
#
# Copyright Header 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
# (at your option) any later version.
#
# Copyright Header 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 Copyright Header.  If not, see <http://www.gnu.org/licenses/>.
#
ruby:
  ext: ['.rb', '.rake']
  after: ['^#!', '^#.*encoding:', '^#.*frozen_string_literal:']
  comment:
    open:   '\n#\n'
    close:  '#\n'
    prefix: '# '
    suffix: ''
    padding: 0

perl:
  ext: ['.pl']
  after: ['^#!', '^#.*encoding:']
  comment:
    open:   '#\n'
    close:  '#\n'
    prefix: '# '
    suffix: ''
    padding: 0

# Support PEP 0263 comments:
# coding=<encoding name>
# -*- coding: <encoding name> -*-
# vim: set fileencoding=<encoding name> :
python:
  ext: ['.py']
  after: ['^#!', '^#.*coding:', '^#.*coding=', '^#.*fileencoding=']
  comment:
    open:   '\n'
    close:  '\n'
    prefix: '# '
    suffix: ''
    padding: 0

html:
  ext: ['.html', '.htm', '.xhtml']
  comment:
    open:   '<!--\n'
    close:  '-->\n'
    prefix: '    '
    suffix: ''
    padding: 0

php:
  ext: ['.php']
  after: [ '^#!' ]
  comment:
    open:   '<?php \n/*\n'
    close:  ' */ ?>\n'
    prefix: ' * '
    suffix: ''
    padding: 0

javacript:
  ext: ['.js', '.jsx']
  comment:
    open:   '/*\n'
    close:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0

qml:
  ext: ['.qml']
  comment:
    open:   '/*\n'
    close:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0

qmake_project:
  ext: ['.pro']
  comment:
    open:   '#\n'
    close:  '#\n'
    prefix: '# '
    suffix: ''
    padding: 0

css:
  ext: ['.css']
  comment:
    open:   '/*\n'
    close:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0

c:
  ext: ['.c', '.h']
  comment:
    open:   '/************************************************************************* \n'
    close:  ' *************************************************************************/\n\n'
    prefix: ' * '
    suffix: ' * \n'
    padding: 6

cpp:
  ext: ['.cpp', '.hpp', '.cc', '.hh']
  comment:
    open:   '/************************************************************************* \n'
    close:  ' *************************************************************************/\n\n'
    prefix: ' * '
    suffix: ' * \n'
    padding: 6

java:
  ext: ['.java']
  comment:
    open:   '/*\n'
    close:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0
    
kotlin:
  ext: ['.kt']
  comment:
    open:   '/*\n'
    clone:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0

golang:
  ext: ['.go']
  comment:
    open:   '/*\n'
    close:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0

groovy:
  ext: ['.groovy']
  comment:
    open:   '/*\n'
    close:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0

haml:
  ext: ['.haml', '.hamlc']
  comment:
    open:   '-#\n'
    close:  '-#\n'
    prefix: '-# '
    suffix: ''
    padding: 0

coffee:
  ext: ['.coffee']
  comment:
    open:   '###\n'
    close:  '###\n'
    prefix: ''
    suffix: ''
    padding: 0

# M4 macro language, use #, not dnl
m4:
  ext:  ['.m4']
  comment:
    open:   '#\n'
    close:  '#\n'
    prefix: '# '
    suffix: ''
    padding: 0

am:
  ext:  ['.am']
  comment:
    open:   '##########################################################################\n'
    close:  '##########################################################################\n\n'
    prefix: '#  '
    suffix: '#\n'
    padding: 5

ac:
  ext:  ['.ac']
  comment:
    open:   '##########################################################################\n'
    close:  '##########################################################################\n\n'
    prefix: '#  '
    suffix: '#\n'
    padding: 5

mk:
  ext:  ['.mk']
  comment:
    open:   '##########################################################################\n'
    close:  '##########################################################################\n\n'
    prefix: '#  '
    suffix: '#\n'
    padding: 5

# Most shells, really
shell:
  ext:  ['.sh']
  after: ['^#!']
  comment:
    open:   '##########################################################################\n'
    close:  '##########################################################################\n'
    prefix: '#  '
    suffix: '#\n'
    padding: 5

# Use "-- " to make sure e.g. MySQL understands it
sql:
  ext:  ['.sql']
  comment:
    open:   '-- \n'
    close:  '-- \n'
    prefix: '-- '
    suffix: ''
    padding: 0

# XML is *not* the same as HTML, and the comments need to go after a
# preprocessing directive, if present.
# FIXME: only supports single line directives
xml:
  ext: ['.xml', '.xsd', '.mxml']
  after: ['^<\?']
  comment:
    open:   '<!--\n'
    close:  '-->\n'
    prefix: '    '
    suffix: ''
    padding: 0

yaml:
  ext:  ['.yml', '.yaml']
  comment:
    open:   '#\n'
    close:  '#\n'
    prefix: '# '
    suffix: ''
    padding: 0

action_script:
  ext: ['.as']
  comment:
    open:   '//\n'
    close:  '//\n\n'
    prefix: '// '
    suffix: ''
    padding: 0

sass:
  ext: ['.sass', '.scss']
  comment:
    open:   '/*\n'
    close:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0

verilog:
  ext: ['.v', '.sv']
  comment:
    open:   '//\n'
    close:  '//\n\n'
    prefix: '// '
    suffix: ''
    padding: 0

vhdl:
  ext: ['.vhd']
  comment:
    open:   '--\n'
    close:  '--\n\n'
    prefix: '-- '
    suffix: ''
    padding: 0

elm:
  ext: ['.elm']
  comment:
    open: '{-\n'
    close: '-}\n\n'
    prefix: '  '
    suffix: ''
    padding: 0

swift:
  ext: ['.swift']
  comment:
    open:   '/*\n'
    close:  ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0

rust:
  ext: ['.rs']
  comment:
    open: '/*\n'
    close: ' */\n\n'
    prefix: ' * '
    suffix: ''
    padding: 0
# Conf files i.e. apache config, splunk.conf files
conf:
  ext:  ['.conf']
  comment:
    open:   '#\n'
    close:  '#\n'
    prefix: '# '
    suffix: ''
    padding: 0
+253 −0
Original line number Original line Diff line number Diff line
#!/bin/bash 

COPYRIGHT_SOFTWARE="NORNS"
COPYRIGHT_DESCRIPTION="a service that allows other programs to start, track and manage asynchronous transfers of data resources between different storage backends"
COPYRIGHT_YEARS="2017-2019"
COPYRIGHT_LICENSE="scripts/NORNS.erb"
COPYRIGHT_SYNTAX="scripts/syntax.yml"
COPYRIGHT_SYNTAX_EXTRA="scripts/syntax.man.yml"

BASE_DIR="."
INCLUDE_PATTERN=( "*.c" "*.h" "*.cpp" "*.hpp" "*.am" "*.ac" "*.py" "*.sh" "*.mk")
EXCLUDE_PATTERN=( ".git" "*build*" "*externals*" "*spdlog*" "*ctypesgen*" "./tests/catch.hpp" )
EXTRA_INCLUDE_PATTERN=( "./doc/*.[0-9].in" ) ## cannot be processed as the ones in INCLUDE_PATTERN
EXTRA_EXCLUDE_PATTERN=( "Makefile.in" )

function help() {
    echo "Usage: `basename $0` COMMAND [OPTIONS] [PATH]..."
    echo ""
    echo "Add or remove license headers for each PATH specified by the user. If "
    echo "no PATH is specified, the specified command is recursively applied to all files"
    echo "in the current directory matching the following expressions:"
    echo "  include_patterns: ${INCLUDE_PATTERN[@]}"
    echo "  exclude_patterns: ${EXCLUDE_PATTERN[@]}"
    echo "  include_extra_patterns: ${EXTRA_INCLUDE_PATTERN[@]}"
    echo "  exclude_extra_patterns: ${EXTRA_EXCLUDE_PATTERN[@]}"
    echo ""
    echo "The following commands can be used:"
    echo "  -a, --add               Add license header to targets"
#    echo "  -u, --update            Update license header in targets"
    echo "  -r, --remove            Remove license header from targets"
    echo ""
    echo "Additionally, the following options are supported:"
    echo "  -n, --dry-run           Don't actually execute, just show what would happen"
    exit 1
}

function find_gem() {
    COPYRIGHT_CMD=`which copyright-header`
    IFS=' .' read -r -a VERSION < <($COPYRIGHT_CMD -v 2>&1 | head -n1)

    if [[ "${VERSION[1]}" -lt 1 ]] ||
       [[ "${VERSION[2]}" -lt 0 ]] ||
       [[ "${VERSION[3]}" -lt 27 ]]; then
        echo "CopyrightHeader gem too old"
        exit 1
    fi
}

function find_targets() {

    if [[ ${#EXCLUDE_PATTERN[@]} -ne 0 ]]; then
        for p in "${EXCLUDE_PATTERN[@]}"; 
        do 
            exclude_args+=( -not \( -path "${p}" -prune \) )
        done
    fi

    if [[ ${#EXTRA_EXCLUDE_PATTERN[@]} -ne 0 ]]; then
        for p in "${EXTRA_EXCLUDE_PATTERN[@]}"; 
        do 
            extra_exclude_args+=( -not \( -path "${p}" -prune \) )
        done
    fi

    if [[ ${#INCLUDE_PATTERN[@]} -ne 0 ]]; then

        include_args=( \( -path "${INCLUDE_PATTERN[0]}" \) )

        for ((i = 1; i < ${#INCLUDE_PATTERN[@]}; ++i));
        do 
            include_args+=( -o \( -path "${INCLUDE_PATTERN[$i]}" \) )
        done
    fi

    if [[ ${#EXTRA_INCLUDE_PATTERN[@]} -ne 0 ]]; then

        extra_include_args=( \( -path "${EXTRA_INCLUDE_PATTERN[0]}" \) )

        for ((i = 1; i < ${#EXTRA_INCLUDE_PATTERN[@]}; ++i));
        do 
            extra_include_args+=( -o \( -path "${EXTRA_INCLUDE_PATTERN[$i]}" \) )
        done
    fi

    #### see https://stackoverflow.com/questions/23356779/how-can-i-store-the-find-command-results-as-an-array-in-bash
    while IFS= read -r -d $'\0';
    do
        TARGETS+=("$REPLY")
    done < <(find "${BASE_DIR}" \( "${exclude_args[@]}" \) -and \( "${include_args[@]}" \) -print0)

    while IFS= read -r -d $'\0';
    do
        EXTRA_TARGETS+=("$REPLY")
    done < <(find "${BASE_DIR}" \( "${exclude_args[@]}" \) -and \( "${extra_exclude_args[@]}" \) -and \( "${extra_include_args[@]}" \) -print0)

    for t in "${TARGETS[@]}";
    do
        git ls-files --error-unmatch "${t}" > /dev/null 2>&1

        if [[ $? -ne 0 ]]; then
            printf 'Adding target %-80s[SKIPPED (not under version control)]\n' "${t}"
        else
            printf 'Adding target %-80s[OK]\n' "${t}"
            PATH_ARGS+="${t}:"
        fi
    done

    for t in "${EXTRA_TARGETS[@]}";
    do
        git ls-files --error-unmatch "${t}" > /dev/null 2>&1

        if [[ $? -ne 0 ]]; then
            printf 'Adding target %-80s[SKIPPED (not under version control)]\n' "${t}"
        else
            printf 'Adding target %-80s[OK]\n' "${t}"
            EXTRA_PATH_ARGS+="${t}:"
        fi
    done
}

function add_header() {

    if [[ -z $PATH_ARGS ]] && [[ -z $EXTRA_PATH_ARGS ]]; then
        echo No targets provided. Nothing to do.
    fi

    ## process PATH_ARGS
    ${COPYRIGHT_CMD} \
        --guess-extension \
        --license-file "${COPYRIGHT_LICENSE}" \
        --syntax "${COPYRIGHT_SYNTAX}" \
        --word-wrap 75 \
        --copyright-software "${COPYRIGHT_SOFTWARE}" \
        --copyright-software-description "${COPYRIGHT_DESCRIPTION}" \
        --copyright-year "${COPYRIGHT_YEARS}" \
        --add-path "${PATH_ARGS::-1}" \
        --output-dir ${BASE_DIR} \
        ${CMD_OPTIONS}

    ## process EXTRA_PATH_ARGS
    ${COPYRIGHT_CMD} \
        --guess-extension \
        --license-file "${COPYRIGHT_LICENSE}" \
        --syntax "${COPYRIGHT_SYNTAX_EXTRA}" \
        --word-wrap 75 \
        --copyright-software "${COPYRIGHT_SOFTWARE}" \
        --copyright-software-description "${COPYRIGHT_DESCRIPTION}" \
        --copyright-year "${COPYRIGHT_YEARS}" \
        --add-path "${EXTRA_PATH_ARGS::-1}" \
        --output-dir ${BASE_DIR} \
        ${CMD_OPTIONS}
}

function remove_header() {

    if [[ -z $PATH_ARGS ]] && [[ -z $EXTRA_PATH_ARGS ]]; then
        echo No targets provided. Nothing to do.
    fi

    ## process PATH_ARGS
    ${COPYRIGHT_CMD} \
        --guess-extension \
        --license-file "${COPYRIGHT_LICENSE}" \
        --syntax "${COPYRIGHT_SYNTAX}" \
        --word-wrap 75 \
        --copyright-software "${COPYRIGHT_SOFTWARE}" \
        --copyright-software-description "${COPYRIGHT_DESCRIPTION}" \
        --copyright-year "${COPYRIGHT_YEARS}" \
        --remove-path "${PATH_ARGS::-1}" \
        --output-dir ${BASE_DIR} \
        ${CMD_OPTIONS}

    ## process EXTRA_PATH_ARGS
    ${COPYRIGHT_CMD} \
        --guess-extension \
        --license-file "${COPYRIGHT_LICENSE}" \
        --syntax "${COPYRIGHT_SYNTAX_EXTRA}" \
        --word-wrap 75 \
        --copyright-software "${COPYRIGHT_SOFTWARE}" \
        --copyright-software-description "${COPYRIGHT_DESCRIPTION}" \
        --copyright-year "${COPYRIGHT_YEARS}" \
        --remove-path "${EXTRA_PATH_ARGS::-1}" \
        --output-dir ${BASE_DIR} \
        ${CMD_OPTIONS}
}


################################################################################
### Script starts here                                                       ###
################################################################################

## Process args
if [[ $# -eq 0 ]]; then
    help
fi

if [[ -z $COPYRIGHT_CMD ]]; then
    find_gem
fi

COMMAND=$1
shift

if [[ ! -z $1 ]] && [[ "$1" =~ -{1,2}.* ]]; then
    case $1 in
        -n | --dry-run)
            CMD_OPTIONS+=( "-n" )
            ;;
        *)
            echo "`basename $0`: invalid option -- '${1//-/}'"
            exit 1
            ;;
    esac

    shift
fi

## Determine targets
TARGETS=()
EXTRA_TARGETS=()

if [[ ! -z $1 ]]; then
    TARGETS=( "$@" )

    for t in "${TARGETS[@]}";
    do
        PATH_ARGS+="${t}:"
    done
else
    find_targets
fi

## Execute selected command
case $COMMAND in
    -a | --add)
        add_header
        ;;
#    -u | --update)
#        update_header
#        ;;
    -r | --remove)
        remove_header
        ;;
    --* | -*)
        echo "`basename $0`: invalid command -- '${1//-/}'"
        exit 1
        ;;
    *)
        echo "`basename $0`: no command provided"
        exit 1
esac

exit 0