<commit_before>#!/usr/bin/env bash
#
# Copyright 2010-2012 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cat<<EOF

            Arachni packager (experimental)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 It packages a build directory, as generated by 'build.sh', into a self-extracting installer.

     by <NAME> <<EMAIL>>
-------------------------------------------------------------------------

EOF

if [[ "$1" == '-h' ]] || [[ "$1" == '--help' ]]; then
    cat <<EOF
Usage: $0 [installer name] [build directory]

Installer name defaults to 'arachni-installer.sh'.
Build directory defaults to 'arachni'.

EOF
    exit
fi

echo
echo "# Checking for script dependencies"
echo '----------------------------------------'
deps="
    tar
    awk
    tail
    basename
    dirname
    readlink
"
for dep in $deps; do
    echo -n "  * $dep"
    if [[ ! `which "$dep"` ]]; then
        echo " -- FAIL"
        fail=true
    else
        echo " -- OK"
    fi
done

if [[ $fail ]]; then
    echo "Please install the missing dependencies and try again."
    exit 1
fi

if [[ ! -z "$1" ]]; then
    # root path
    instname="$1"
else
    # root path
    instname="arachni-installer.sh"
fi

if [[ ! -z "$2" ]]; then
    # root path
    instdir="$2"
else
    # root path
    instdir="arachni"
fi

echo

if [[ ! -s $instdir ]]; then
    echo "Could not find an installation under $instdir."
    exit 1
fi

root="$(dirname "$(readlink -f "${0}")")"
insttpl="$root/installer.sh.tpl"

if [[ ! -s $insttpl ]]; then
    echo "Could not find installer template: $insttpl."
    exit 1
fi


tmp_archive="$instname.tar.gz"

echo "# Generating installer"
echo '----------------------------------------'

echo "  * Cleaning"
rm -f $tmp_archive
rm -f $instname

echo "  * Copying installer template to '$instname'"
cp -f $insttpl $instname

pattern=`basename $instdir`
sed -i "s/##PKG_NAME##/$pattern/g" $instname

echo "  * Compressing installation dir ($instdir)"
tar czf $tmp_archive $instdir

echo "  * Appending the archive to the installer"
cat $tmp_archive >> $instname

echo "  * Setting installer permisions"
chmod +x $instname

echo
echo "Installer saved at '$instname'."
echo
<commit_msg>updated to work with *BSD's sed<commit_after>#!/usr/bin/env bash
#
# Copyright 2010-2012 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cat<<EOF

            Arachni packager (experimental)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 It packages a build directory, as generated by 'build.sh', into a self-extracting installer.

     by <NAME> <<EMAIL>>
-------------------------------------------------------------------------

EOF

if [[ "$1" == '-h' ]] || [[ "$1" == '--help' ]]; then
    cat <<EOF
Usage: $0 [installer name] [build directory]

Installer name defaults to 'arachni-installer.sh'.
Build directory defaults to 'arachni'.

EOF
    exit
fi

echo
echo "# Checking for script dependencies"
echo '----------------------------------------'
deps="
    tar
    awk
    tail
    basename
    dirname
    readlink
"
for dep in $deps; do
    echo -n "  * $dep"
    if [[ ! `which "$dep"` ]]; then
        echo " -- FAIL"
        fail=true
    else
        echo " -- OK"
    fi
done

if [[ $fail ]]; then
    echo "Please install the missing dependencies and try again."
    exit 1
fi

if [[ ! -z "$1" ]]; then
    # root path
    instname="$1"
else
    # root path
    instname="arachni-installer.sh"
fi

if [[ ! -z "$2" ]]; then
    # root path
    instdir="$2"
else
    # root path
    instdir="arachni"
fi

echo

if [[ ! -s $instdir ]]; then
    echo "Could not find an installation under $instdir."
    exit 1
fi

root="$(dirname "$(readlink -f "${0}")")"
insttpl="$root/installer.sh.tpl"

if [[ ! -s $insttpl ]]; then
    echo "Could not find installer template: $insttpl."
    exit 1
fi


tmp_archive="$instname.tar.gz"

echo "# Generating installer"
echo '----------------------------------------'

echo "  * Cleaning"
rm -f $tmp_archive
rm -f $instname

echo "  * Copying installer template to '$instname'"

pattern=`basename $instdir`
cat $insttpl | sed "s/##PKG_NAME##/$pattern/g" > $instname

echo "  * Compressing build dir ($instdir)"
tar czf $tmp_archive $instdir

echo "  * Appending the archive to the installer"
cat $tmp_archive >> $instname

echo "  * Setting installer permisions"
chmod +x $instname

echo
echo "Installer saved at '$instname'."
echo

{'fraction_non_alphanumeric': 0.18733754177497214, 'fraction_numerical': 0.008540660972892685, 'mean_word_length': 2.514024787997391, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5295299', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1627, 'n_words': 606}