#!/bin/bash 
set -x 
copy_list=("passwd" "shadow" "group" "gshadow" "subgid" "subuid" "passwd-" "shadow-" "group-" "gshadow-" "subgid-" "subuid-" "uid_list" "timezone" "localtime" "locale.gen")
base_env_path="/opt/kare-applications/base/kare-v10sp1"

if [ -d "$base_env_path" ]; then
    for file in  "${copy_list[@]}"; do
        if [ -f "/etc/$file" ]; then
            cp -a "/etc/$file" "$base_env_path/etc/$file"
        fi
    done
    cp /usr/share/kare/container-scripts/* "$base_env_path/usr/bin"
fi

KARE_CUPS_STRING="ServerBin /opt/kare/usr/lib/cups"
cups_file_conf="/etc/cups/cups-files.conf"

cups_src_dir="/usr/lib/cups"
cups_dest_dir="/opt/kare/usr/lib/cups"

mkdir -p "$cups_dest_dir"
mkdir -p "$cups_dest_dir/filter"

for item in "$cups_src_dir"/*; do
	if [ "$(basename "$item")" != "filter" ]; then
		ln -sf "$item" "$cups_dest_dir/"
	fi
done

for item in "$cups_src_dir/filter"/*; do
	ln -sf "$item" "$cups_dest_dir/filter/"
done

if grep -q "$KARE_CUPS_STRING" "$cups_file_conf"; then
    exit 0
fi

echo "$KARE_CUPS_STRING" >> "$cups_file_conf"

exit 0

