<commit_before>#!/bin/bash

### BEGIN INIT INFO
# Provides:          CFS_Boot
# Required-Start:    $local_fs $time $network $syslog
# Required-Stop:     $local_fs $time $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the CFS
# Description:       script to start the CFS on boot with the 
#                    daemon command. To setup the script type 
#                    "sudo ./CFS_Boot.sh setup" 
#                   
### END INIT INFO

# Change the next 3 lines to suit where you install your script and what you want to call it
DIR=/home/pi/TRAPSat/TRAPSat_cFS/cfs/build/cpu1/exe
DAEMON=$DIR/core-linux.bin
DAEMON_NAME=CFS_Boot

# Change the next 3 lines to suit log location  
LOG=/home/pi/logs
OUT=$LOG/$DAEMON_NAME.out
ERR=$LOG/$DAEMON_NAME.err
DBG=$LOG/$DAEMON_NAME.dbg

#checks for log dir
if [ ! -d "$LOG" ]; then
   mkdir -p "$LOG"
fi

# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_USER=root

# The process ID and priority of the script when it runs is stored here:
  PIDFILE=/var/run/$DAEMON_NAME.pid

. /lib/lsb/init-functions

do_start () {
    read index < $LOG/reboot.txt
    declare -i tmp=index+1
    printf "%03d" $tmp > $LOG/reboot.txt

    log_daemon_msg "Starting system $DAEMON_NAME daemon"
    echo
    daemon --pidfile=$PIDFILE --user $DAEMON_USER --foreground --stdout=$OUT --stderr=$ERR -- $DAEMON  
    #log_end_msg $?
}

do_stop () {
    log_daemon_msg "Stopping system $DAEMON_NAME daemon"
    start-stop-daemon --stop --pidfile $PIDFILE --retry 10
    log_end_msg $?
}

set(){
    log_daemon_msg "Seting up $DAEMON_NAME"
    sudo cp CFS_Boot.sh /etc/init.d/CFS_Boot.sh
    cd /etc/init.d/
    sudo apt-get install daemon
    sudo apt-get update daemon
    sudo apt-get upgrade daemon
    sudo insserv $DAEMON_NAME.sh
    log_end_msg $?
}

case "$1" in

    start|stop)
        do_${1}  
        ;;

    restart|reload|force-reload)
        do_stop
        do_start
        ;;
    
    setup)
        set
        ;;<commit_msg>Fixed CFS_Boot.sh. Modifies permissions on core-linux.bin and now works at boot.<commit_after>#!/bin/bash

### BEGIN INIT INFO
# Provides:          CFS_Boot
# Required-Start:    $local_fs $time $network $syslog
# Required-Stop:     $local_fs $time $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the CFS
# Description:       script to start the CFS on boot with the 
#                    daemon command. To setup the script type 
#                    "sudo ./CFS_Boot.sh setup" 
#                   
### END INIT INFO

# Change the next 3 lines to suit where you install your script and what you want to call it
DIR=/home/pi/TRAPSat/TRAPSat_cFS/cfs/build/cpu1/exe
DAEMON=$DIR/core-linux.bin
DAEMON_NAME=CFS_Boot

# Change the next 3 lines to suit log location  
LOG=/home/pi/logs
OUT=$LOG/$DAEMON_NAME.out
ERR=$LOG/$DAEMON_NAME.err
DBG=$LOG/$DAEMON_NAME.dbg

#checks for log dir
if [ ! -d "$LOG" ]; then
   mkdir -p "$LOG"
fi

# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_USER=root

# The process ID and priority of the script when it runs is stored here:
  PIDFILE=/var/run/$DAEMON_NAME.pid

. /lib/lsb/init-functions

do_start () {
    read index < $LOG/reboot.txt
    declare -i tmp=index+1
    printf "%03d" $tmp > $LOG/reboot.txt

    log_daemon_msg "Starting system $DAEMON_NAME daemon"
    echo
    cd $DIR
    daemon --pidfile=$PIDFILE --user $DAEMON_USER --foreground --stdout=$OUT --stderr=$ERR -- $DAEMON  
    #log_end_msg $?
}

do_stop () {
    log_daemon_msg "Stopping system $DAEMON_NAME daemon"
    start-stop-daemon --stop --pidfile $PIDFILE --retry 10
    log_end_msg $?
}

set(){
    log_daemon_msg "Seting up $DAEMON_NAME"
    sudo cp CFS_Boot.sh /etc/init.d/CFS_Boot.sh
    cd /etc/init.d/
    sudo apt-get install daemon
    #sudo apt-get update daemon -- causes errors
    #sudo apt-get upgrade daemon -- install will always install the latest version
    sudo insserv $DAEMON_NAME.sh
    # fix daemon group write error -- maybe this should be in start? not sure
    sudo chmod g-w $DAEMON
    log_end_msg $?
}

case "$1" in

    start|stop)
        do_${1}  
        ;;

    restart|reload|force-reload)
        do_stop
        do_start
        ;;
    
    setup)
        set
        ;;
{'fraction_non_alphanumeric': 0.10241631567279982, 'fraction_numerical': 0.007537131456439814, 'mean_word_length': 2.566798418972332, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5383967', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1550, 'n_words': 474}