<commit_before>#!/bin/sh
#
# etcetera.sh
# Etc CLI
#

ETC_DIR="${ETC_DIR-$HOME/.etc}"
WORK_DIR="$ETC_DIR/.etc_work"
MAKE_ARG="-C $WORK_DIR"
FORCE=false

#Parse Options
while getopts "hfl:d:" opt
do
	case $opt in
		 h) 
			echo "Usage: etcetera [-hf] (install|update|remove) [modules]"
			echo "install - install deployment"
			echo "update - update deployment"
			echo "remove - remove deployment"
			echo "-h - Print usage infomation"
			echo "-f - Force action, regardless if already action already completed, or if there are any errors"
            echo "[modules] - Limit scope within modules only"
			exit 0;
		 ;;
		 f)
            FORCE=true
		 ;;
	esac
done

shift $((OPTIND -1))

SUBCOMMAND=$1
shift

#Read Modules 
MODULES="$*"

#Update & Setup Workspace
( cd "$ETC_DIR" && git pull -r && rm "$WORK_DIR/source/core.mk") || 
    printf "Updating from upsteam failed. Continuing without updating...\n" 
make -C "$ETC_DIR" work

#Preprocess Markers
if $FORCE
then
    MAKE_ARG="$MAKE_ARG -i"
    
    if [ $MODULES ]
    then
        for MODULE in $MODULES
        do
            rm -f $WORK_DIR/mark/$MODULE*
        done
    else
        rm -rf $WORK_DIR/mark
        mkdir -p $WORK_DIR/mark
        MAKE_ARG="$MAKE_ARG UPDATE_DELAY:=0 UPDATE_COUNT:=999999"
    fi
fi

#Parse Subcommand
case $SUBCOMMAND in
	install)
        printf "\033[1m\033[0;32m[etcetera]: INSTALL BEGIN\033[0m\n"
        if [ "$MODULES" ]
        then
            for MODULE in $MODULES
            do
                time make $MAKE_ARG install_$MODULE
            done
        else
            time make $MAKE_ARG install
        fi
        printf "\033[1m\033[0;32m[etcetera]: INSTALL COMPLETE\033[0m\n"
		;;
	update)
		printf "\033[1m\033[0;32m[etcetera]: UPDATE BEGIN\033[0m\n"

        if [ "$MODULES" ]
        then
            for MODULE in $MODULES
            do
               time make $MAKE_ARG update_$MODULE
                
            done
        else
            time make $MAKE_ARG update
        fi
		printf "\033[1m\033[0;32m[etcetera]: UPDATE COMPLETE\033[0m\n"
		;;
	remove)
		printf "\033[1m\033[0;32m[etcetera]: REMOVAL BEGIN\033[0m\n"
        if [ "$MODULES" ]
        then
            for MODULE in $MODULES
            do
                time make -i $MAKE_ARG remove_$MODULE
            done
        else
            time make -i $MAKE_ARG remove
        fi
		printf "\033[1m\033[0;32m[etcetera]: REMOVAL COMPLETE\033[0m\n"
		;;
	*)
		echo "Unknown subcommand: $1"
		exit 1
		;;
esac<commit_msg>Updated etcetera CLI to new etcetera architecture.<commit_after>#!/bin/sh
#
# etcetera.sh
# Etc CLI
#

# Etcetera directory is define as ~/.etc by default if not already specified as
# enviromental variable
ETC_DIR="${ETC_DIR-$HOME/.etc}"
DEPLOYMENT_PATH="$ETC_DIR/deploy/deployment.etc"
MAKE_ARG=""
FORCE=false

#Parse Options
while getopts "hfd:" opt
do
	case $opt in
		 h) 
			echo "Usage: etcetera [-hi] [-d <deployment>] (install|update|remove) [modules]"
			echo "install - install deployment"
			echo "update - update deployment"
			echo "remove - remove deployment"
			echo "-h - Print usage infomation"
            echo "-i - Ignore any errors, just continue"
            echo "-d - specify the deployment file to use, otherwise uses '~/.etc/deploy/deployment.etc'"
            echo "[modules] - Limit deployment scope to within these modules only"
			exit 0;
		 ;;
         i)
            MAKE_ARG="$MAKE_ARG -i"
         ;;
         d)
            DEPLOYMENT_PATH="$OPTARG"
         ;;
	esac
done

shift $((OPTIND -1))

# Parse subcommand
SUBCOMMAND=$1
shift

# Read Modules - limits the scope of the subcommand over modules
# if modules are specifed, subcommand will only operate on the specified modles
MODULES="$*" 

# Contruct working directory
WORK_DIR="$ETC_DIR/.work"
mkdir -p "$WORK_DIR"

# Generate deployment makefile from ETC deployment specification
# Test if deployment specification is newer than deployment makefile
# Triggers a regeneration of deployment makefile if older
DEPLOY_MK_PATH="$WORK_DIR/deployment.mk"

if test -n "$(find -L -- $DEPLOYMENT_PATH -prune -newer $DEPLOY_MK_PATH 2>/dev/null)"
then
    echo "[etcetera]: Generating Build Script..."
    m4 --include="$ETC_DIR/src" "$DEPLOYMENT_PATH" >"$DEPLOY_MK_PATH"
fi

MAKE_ARG="-f $DEPLOY_MK_PATH $MAKE_ARG"

#Execute Subcommand
case $SUBCOMMAND in
	install)
        printf "\033[1m\033[0;32m[etcetera]: Installing...\033[0m\n"

        if [ "$MODULES" ] 
        then
            for MODULE in $MODULES
            do
                # Trigger installation instructions for the module only
                # Full operation also triggers instructions for dependecies
                time make $MAKE_ARG "full_install__$MODULE"
            done
        else
            time make $MAKE_ARG install # Trigger installation of entire deployment
        fi
        printf "\033[1m\033[0;32m[etcetera]: Installed.\033[0m\n"
		;;
	update)
		printf "\033[1m\033[0;32m[etcetera]: Updating...\033[0m\n"

        if [ "$MODULES" ]
        then
            for MODULE in $MODULES
            do
                # Trigger update instructions for the module only
                # Full operation also triggers instructions for dependecies
                time make $MAKE_ARG "full_update__$MODULE"
            done
        else
            time make $MAKE_ARG update # Trigger upgrade of entire deployment
        fi
		printf "\033[1m\033[0;32m[etcetera]: Updated.\033[0m\n"
		;;
	remove)
		printf "\033[1m\033[0;32m[etcetera]: Removing...\033[0m\n"

        if [ "$MODULES" ]
        then
            for MODULE in $MODULES
            do
                # Trigger removal instructions for the module only
                # Full operation also triggers instructions for dependecies
                time make $MAKE_ARG "full_remove__$MODULE"
            done
        else
            time make $MAKE_ARG remove # Trigger removal of entire deployment
        fi
		printf "\033[1m\033[0;32m[etcetera]: Removed.\033[0m\n"
		;;
	*)
		echo "Unknown subcommand: $SUBCOMMAND"
		exit 1
		;;
esac
{'fraction_non_alphanumeric': 0.10463008732904927, 'fraction_numerical': 0.03064755313890262, 'mean_word_length': 2.252947481243301, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2681851', 'n_tokens_mistral': 2165, 'n_tokens_neox': 1962, 'n_words': 565}