# /etc/profile - executed by login shell
# originally from Puppy Linux, this file is re-written for Fatdog64 600
# Copyright (C) James Budiono 2012,2013,2014,2019 
# with bits and pieces are from original authors, as noted, and licensed differently
# License: GNU GPL Version 3 or later
# 
# boot time parameters handled:
# - pfix=xorgwizard - start xorgwizard before launching desktop
# - pfix=nox - don't start X automatically
# DONT_START_X environment
#
# Note: this file is sourced by login shell, do "return" instead of "exit"

### configuration
export BOOTSTATE_PATH=/etc/BOOTSTATE
export FATDOG_STATE_DIR=$HOME/.fatdog	# Fatdog state directory
LANG_CONFIG=$FATDOG_STATE_DIR/language	# defined by chooselocale
TZ_CONFIG=$FATDOG_STATE_DIR/timezone	# managed by fatdog-set-timezone

# defaults
LANG=en_US.UTF-8
TZ=":/etc/localtime"            # use whatever is specified in /etc/localtime
EDITOR=vi                       # console editor, changed by xinitrc to geany
OUTPUT_CHARSET=UTF-8            # default output charset for gettext
TEXTDOMAINDIR=/usr/share/locale # default location for localised messages

######## critical per-user settings #########
# need to do these as early as possible
mkdir -p $FATDOG_STATE_DIR 2> /dev/null		# make our config directory if it doesn't exist
[ -e $LANG_CONFIG ] && read LANG < $LANG_CONFIG 
[ -e $TZ_CONFIG ] && read TZ < $TZ_CONFIG 
export LANG TZ EDITOR OUTPUT_CHARSET TEXTDOMAINDIR



############# generic settings ###############

### path, libraries, and pkg-config - listed from most to least commonly used

# standard path
PATH="/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
LD_LIBRARY_PATH="/lib64:/usr/lib64:/usr/local/lib64"
PKG_CONFIG_PATH="/usr/lib64/pkgconfig"

# firefox/seamonkey
[ -e /usr/lib64/firefox ]   && LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:"/usr/lib64/firefox"
[ -e /usr/lib64/seamonkey ] && LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:"/usr/lib64/seamonkey"

# lastly 32-bit library path
LIB32_LD_LIBRARY_PATH="/lib:/usr/lib:/lib32:/usr/lib32:/usr/local/lib:/usr/local/lib32"
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIB32_LD_LIBRARY_PATH}

# export all of them
export PATH LD_LIBRARY_PATH PKG_CONFIG_PATH



############# application settings ###############

### default user limits and umask
ulimit -c 0 # no core files
umask 022   # all rights to me, read/execute rights to my group, no rights for others

# XDG settings (standards.freedesktop.org/basedir-spec/latest/) from rarsa since 2.0.2
export XDG_DATA_DIRS=/usr/share:/usr/local/share
export XDG_CONFIG_DIRS=/etc/xdg #v2.14 changed from /usr/etc
export XDG_DATA_HOME=$HOME/.local/share
export XDG_CONFIG_HOME=$HOME/.config
export XDG_CACHE_HOME=$HOME/.cache
export XDG_RUNTIME_DIR=/tmp/runtime-$USER
mkdir -p $XDG_DATA_HOME $XDG_CONFIG_HOME $XDG_CACHE_HOME $XDG_RUNTIME_DIR
chmod 0700 $XDG_RUNTIME_DIR # for my eyes only

# shell configurations
HISTFILESIZE=1000
HISTCONTROL=erasedups
ENV=/etc/shinit	# for user-specific settings that can change after login (via su)
INPUTRC=/etc/inputrc
read HOSTNAME < /etc/hostname
export ENV HISTFILESIZE HISTCONTROL INPUTRC HOSTNAME

# glib
export G_FILENAME_ENCODING=@locale  # use current locale instead of utf8

# make update-mime-database run a lot faster
export PKGSYSTEM_ENABLE_FSYNC=0

# mozilla
export MOZ_PLUGIN_PATH="/usr/lib64/mozilla/plugins"
export MOZ_DISABLE_PANGO=1 # sm/firefox speed-up - I'm not sure this still has effect?
export MOZ_LEGACY_PROFILES=1 # disable 'one-profile per installation' recently added "feature"

# libreoffice >= 6.2 defaults to gtk3, need this to force it to run with gtk2; Now no longer supports gtk2 so qt5 now
export SAL_USE_VCLPLUGIN=gtk

# Java >= 12 has ugly fonts, this fixes it
export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on'

# stop blinking X11 mouse cursor in SDL fullscreen apps
export SDL_VIDEO_X11_DGAMOUSE=0

# gtk3
export GTK_OVERLAY_SCROLLING=0 # disable auto-hide scrollbar

#2d acceleration by opengl
#export VDPAU_DRIVER=va_gl


############# puppy DEFAULT* stuff ###############

DEFAULTARCHIVER=/usr/local/bin/defaultarchiver
DEFAULTBROWSER=/usr/local/bin/defaultbrowser
DEFAULTDRAW=/usr/local/bin/defaultdraw
DEFAULTHTMLEDITOR=/usr/local/bin/defaulthtmleditor
DEFAULTMEDIAPLAYER=/usr/local/bin/defaultmediaplayer
DEFAULTPAINT=/usr/local/bin/defaultpaint
DEFAULTSPREADSHEET=/usr/local/bin/defaultspreadsheet
DEFAULTTEXTEDITOR=/usr/local/bin/defaulttexteditor
DEFAULTWORDPROCESSOR=/usr/local/bin/defaultwordprocessor
export DEFAULTARCHIVER DEFAULTBROWSER DEFAULTDRAW DEFAULTHTMLEDITOR DEFAULTMEDIAPLAYER DEFAULTPAINT DEFAULTSPREADSHEET DEFAULTTEXTEDITOR DEFAULTWORDPROCESSOR
export BROWSER=$DEFAULTBROWSER	# xdg-open uses this variable


########## additional profile scripts ############

# source additional profiles from /etc/profile.d/*
#v2.16 BarryK - this need arose when considering SFS files that may require special env. variables.
# this code is lifted straight from Vector...
for profile_script in /etc/profile.d/*.sh ; do
  if [ -x $profile_script ]; then
    . $profile_script
  fi
done
unset profile_script

# source local profile and per-user profile last, so that it can override all previous settings
[ -r /etc/profile.local ] && . /etc/profile.local
[ -r $FATDOG_STATE_DIR/profile ] && . $FATDOG_STATE_DIR/profile


############# command line handling ###############

### pfix handling - understands "xorgwizard" and "nox" here
pfix=$(sed -n '/pfix/ {s/^.*pfix=//; s/ .*$//; p}' /proc/cmdline) # get "pfix" (no longer declared - /etc/profile is not part of init)
case "$pfix" in
	*xorgwizard*)
		#{ rm /etc/X11/no-xorg.conf; rm /etc/X11/xorg.conf; } 2> /dev/null
		if ! pidof X Xorg > /dev/null; then
			# run in another vt so our display is not clobbered with messages from background processes
			busybox openvt -sw /usr/sbin/xorgwizard 
			chvt 1
		fi
		;;
	*nox*)
		# dont start X
		return
		;;
esac

# start X if it's not already running and we're not under ssh
# don't exec, so that we can exit to terminal later.
! pidof X Xorg > /dev/null && [ -z "$DISPLAY" ] && [ -z "$DONT_START_X" ] &&
[ -z "$SSH_CONNECTION" ] && xwin 

# end - next stop /etc/shinit 
