#!/bin/sh

### BEGIN INIT INFO
# Provides:         antiX-restore-services 
# Required-Start:   antiX-disable-services
# Required-Stop:     
# Should-Start:      
# Should-Stop:       
# Default-Start:     S 
# Default-Stop:
# Short-Description: restore service symlinks
# Description:       restore service symlinks that were temporarily disabled
### END INIT INFO

# We replace all the service symlinks we moved so the system
# wakes up looking like nothing happened.
#
# See antiX-disable-services for how the symlinks got moved.
# This undoes all the symlink moving that was done there.

# GETTEXT_KEYWORD="echo_live"
# GETTEXT_KEYWORD="echo_script"

case "$1" in
    start)
        ;;
    stop)
        exit 0;
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac
    

CMDLINE=${CMDLINE:-$(cat /proc/cmdline)}
for param in $CMDLINE; do
    case "$param" in
        antiX=*|aX=*|nodbus) MUST_RUN=true ;;
         lean|mean|Xtralean) MUST_RUN=true ;;
    esac
done

[ "$MUST_RUN" ] || exit 0

. /usr/share/antiX/lib/antiX-init-utils.sh

from=$DISABLED_RC_DIR

[ -d "$from" ] || exit 0

start_init_logging
load_translation

{
    echo_script "$_restoring_service_links_" $0

     for rc_dir in $from/rc?.d; do
        [ -d "$rc_dir" ] || continue

        # Strip off leading directories
        rc_dir=${rc_dir##*/}
        dest=/etc/$rc_dir
    
        # Skip if destination directory is missing
        [ -d "$dest" ] || continue
        
        mv $from/$rc_dir/* $dest
    done
    
    rmdir $from/* $from  

} 2>&1 | tee -a $INIT_LOG_FILE

exit 0
