#!/bin/sh -e

[ -n "$GLOBAL_HOMEROS" ] || exit 0

AUTOSTART_DIR='/home/altlinux/.config/autostart'

if [ -n "$GLOBAL_HOMEROS_FRIEND" ]; then
    subst s/'^\(1:2345:respawn.*\)$'/'#\1'/ /etc/inittab 
    cat <<EOF >> /etc/inittab
# emacspeak is always available on 1-st console;
espk:2345:respawn:/bin/openvt -w -f -c 1 -- su - -c /usr/local/bin/emacs-with-linux-term
EOF
    cat <<EOF > /usr/local/bin/emacs-with-linux-term
#!/bin/sh
TERM=linux /usr/bin/emacs "\$@"
exit \$?
EOF
    chmod 755 /usr/local/bin/emacs-with-linux-term
else 
    /bin/mkdir -p "$AUTOSTART_DIR"
    /bin/cp /usr/share/applications/orca.desktop "$AUTOSTART_DIR/orca.desktop"
    echo 'X-GNOME-Autostart-enabled=true' >> "$AUTOSTART_DIR/orca.desktop"
fi
