
setup_oar_ssh() {
    if [ ! -e ${OARHOMEDIR}/.ssh ]; then
        mkdir -p ${OARHOMEDIR}/.ssh
        ssh-keygen -t rsa -q -f ${OARHOMEDIR}/.ssh/id_rsa -N '' || true
        echo -n 'environment="OAR_KEY=1" ' > ${OARHOMEDIR}/.ssh/authorized_keys || true
        cat ${OARHOMEDIR}/.ssh/id_rsa.pub >> ${OARHOMEDIR}/.ssh/authorized_keys || true
        cat <<-EOF > ${OARHOMEDIR}/.ssh/config || true
	Host *
	ForwardX11 no
	StrictHostKeyChecking no
	PasswordAuthentication no
	AddressFamily inet
	EOF
        chown ${OAROWNER}:${OAROWNERGROUP} ${OARHOMEDIR}/.ssh -R || true
    fi
}

create_phoenix_home() {
    mkdir -p ${OARHOMEDIR}/phoenix
    chown ${OAROWNER}:${OAROWNERGROUP} ${OARHOMEDIR}/phoenix
}

server_setup() {
    install_conffile \
        ${SHAREDIR}/job_resource_manager.pl \
        ${OARCONFDIR}/job_resource_manager.pl \
        0644

    install_conffile \
        ${SHAREDIR}/job_resource_manager_cgroups.pl \
        ${OARCONFDIR}/job_resource_manager_cgroups.pl \
        0644

    install_conffile \
        ${SHAREDIR}/suspend_resume_manager.pl \
        ${OARCONFDIR}/suspend_resume_manager.pl \
        0644

    install_conffile \
        ${SHAREDIR}/oarmonitor_sensor.pl \
        ${OARCONFDIR}/oarmonitor_sensor.pl \
        0644

    install_conffile \
        ${SHAREDIR}/wake_up_nodes.sh \
        ${OARCONFDIR}/wake_up_nodes.sh

    install_conffile \
        ${SHAREDIR}/shut_down_nodes.sh \
        ${OARCONFDIR}/shut_down_nodes.sh

    install_conffile \
        ${SHAREDIR}/server_prologue \
        ${OARCONFDIR}/server_prologue \
        0755

    install_conffile \
        ${SHAREDIR}/server_epilogue \
        ${OARCONFDIR}/server_epilogue \
        0755

    install_conffile \
        ${SHAREDIR}/scheduler_quotas.conf \
        ${OARCONFDIR}/scheduler_quotas.conf

    setup_oar_ssh
    create_phoenix_home

    set_rights ${SBINDIR}/oar_resources_init 6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}
    set_rights ${SBINDIR}/Almighty           6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}
    set_rights ${SBINDIR}/oarnotify          6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}
    set_rights ${SBINDIR}/oarremoveresource  6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}
    set_rights ${SBINDIR}/oaraccounting      6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}
    set_rights ${SBINDIR}/oarproperty        6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}
    set_rights ${SBINDIR}/oarmonitor         6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}
    set_rights ${SBINDIR}/oar_resources_init 6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}
    set_rights ${SBINDIR}/oar_phoenix        6750 ${OARDO_DEFAULTUSER} ${OARDO_DEFAULTGROUP}

}
