#!/bin/bash set -x # put here dirs that must be made persistent list_dirs() { cat < /etc/minidlna.conf echo "friendly_name=$mdFriendlyname" >> /etc/minidlna.conf echo "inotify=$mdInotify" >> /etc/minidlna.conf echo "enable_tivo=$mdEnabletivo" >> /etc/minidlna.conf echo "strict_dlna=$mdStrictdlna" >> /etc/minidlna.conf echo "notify_interval=$mdNotifyinterval" >> /etc/minidlna.conf echo "max_connections=$mdMaxconnections" >> /etc/minidlna.conf # grep all media_* envs & make minidlna.conf media_dir entry env | grep '^media_' | while read -r value; do value=$(echo $value | cut -d= -f2) echo "media_dir=$value" >> /etc/minidlna.conf done [ -e /run/minidlna/minidlna.pid ] && rm /run/minidlna/minidlna.pid } function _dirs { DEST_PATH="/data" # make list of dirs that have to be persistent outListDirs=$(list_dirs | grep -v ^#) if [ ! -z $outListDirs ]; then echo "--------------------------------------" echo " Moving persistent data in $DEST_PATH " echo "--------------------------------------" list_dirs | while read path_name DUMMY; do if [ ! -e ${DEST_PATH}${path_name} ]; then if [ -d $path_name ]; then rsync -Ra ${path_name}/ ${DEST_PATH}/ else rsync -Ra ${path_name} ${DEST_PATH}/ fi else echo "---------------------------------------------------------" echo " No NEED to move anything for $path_name in ${DEST_PATH} " echo "---------------------------------------------------------" fi rm -rf ${path_name} ln -s ${DEST_PATH}${path_name} ${path_name} done fi } custom_bashrc() { cat <<'EOF' export LS_OPTIONS="--color=auto" alias ls='ls $LS_OPTIONS' alias ll='ls $LS_OPTIONS -la' alias l='ls $LS_OPTIONS -lA' # prompt SOLO per shell interattive if [[ $- == *i* ]]; then if [ "$(id -u)" -eq 0 ]; then PS1="\[\e[35m\][\[\e[31m\]\u\[\e[36m\]@\[\e[32m\]\h\[\e[90m\] \w\[\e[35m\]]\[\e[0m\]# " else PS1="\[\e[35m\][\[\e[33m\]\u\[\e[36m\]@\[\e[32m\]\h\[\e[90m\] \w\[\e[35m\]]\[\e[0m\]$ " fi export PS1 fi EOF } setup_bashrc() { for home in /root /home/*; do [ -d "$home" ] || continue bashrc="$home/.bashrc" # crea se manca [ -f "$bashrc" ] || touch "$bashrc" # evita duplicazioni grep -q '### CUSTOM BASHRC ###' "$bashrc" && continue { echo '' echo '### CUSTOM BASHRC ###' custom_bashrc } >> "$bashrc" done } _dirs _main setup_bashrc # print cmd that will be executed echo "Starting: $*" >&2 # launch CMD exec "$@"