2013-09-18 19:27:36 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# main configuration file that is always used
|
|
|
|
|
MAIN_CONF="$HOME/.i3/config"
|
|
|
|
|
# temporary configuration file used for this session
|
|
|
|
|
SESSION_CONF="$HOME/.i3/session.config"
|
|
|
|
|
# directory that contains host specific configuration
|
|
|
|
|
CONF_DIR="$HOME/.i3/config.d"
|
|
|
|
|
# file that should be used when no host specific configuration present
|
2013-09-20 23:28:19 +02:00
|
|
|
DEFAULT_CONF="$CONF_DIR/default"
|
2013-09-18 19:27:36 +02:00
|
|
|
|
2014-04-22 22:15:26 +02:00
|
|
|
LOGFILE="$LOGDIR/i3/genconfig.log"
|
|
|
|
|
|
|
|
|
|
mkdir -p "$(dirname $LOGFILE)"
|
|
|
|
|
|
|
|
|
|
log() {
|
|
|
|
|
echo "[$(date +%FT%T)] $*" >> "$LOGFILE"
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 23:28:19 +02:00
|
|
|
host="$(hostname)"
|
|
|
|
|
|
|
|
|
|
host_specific_conf="$CONF_DIR/$host.config"
|
2013-09-18 19:27:36 +02:00
|
|
|
|
|
|
|
|
# if it's a symlink to $MAIN_CONF, cat will fail
|
|
|
|
|
[[ -f "$SESSION_CONF" ]] && rm "$SESSION_CONF"
|
|
|
|
|
|
|
|
|
|
if [[ ! -f "$host_specific_conf" ]] && [[ ! -f "$DEFAULT_CONF" ]]; then
|
|
|
|
|
# if there is no host-specific configuration and no default one, just use
|
|
|
|
|
# the main config
|
2014-04-22 22:15:26 +02:00
|
|
|
log "neither config for host $host nor default config at $DEFAULT_CONF found, using main only"
|
2013-09-18 19:27:36 +02:00
|
|
|
ln -sf "$MAIN_CONF" "$SESSION_CONF"
|
|
|
|
|
else
|
|
|
|
|
# either use the host specific config if present, or the default if not
|
|
|
|
|
if [[ -f "$host_specific_conf" ]]; then
|
2014-04-22 22:15:26 +02:00
|
|
|
log "found config for host $host at $host_specific_conf"
|
2013-09-18 19:27:36 +02:00
|
|
|
conf_to_use="$host_specific_conf"
|
|
|
|
|
else
|
2014-04-22 22:15:26 +02:00
|
|
|
log "no config for host $host found, using default one"
|
2013-09-18 19:27:36 +02:00
|
|
|
conf_to_use="$DEFAULT_CONF"
|
|
|
|
|
fi
|
2013-09-20 23:28:19 +02:00
|
|
|
cat "$MAIN_CONF" <(echo -e "\n###\n### host-specific configuration for host \"$host\"\n###\n") "$conf_to_use" > "$SESSION_CONF"
|
2014-04-22 22:15:26 +02:00
|
|
|
log "created session config at $SESSION_CONF"
|
2013-09-18 19:27:36 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "$SESSION_CONF"
|
2014-04-17 19:35:04 +02:00
|
|
|
|
|
|
|
|
# if we got any parameters, tell i3 to reload the config
|
|
|
|
|
# so the script can be used both on startup without reload (as i3 is not even
|
|
|
|
|
# running yet) and later when reloading
|
2014-04-22 22:15:26 +02:00
|
|
|
if [[ -n "$1" ]] ; then
|
|
|
|
|
log "telling i3 to reload the config file"
|
|
|
|
|
i3-msg reload
|
|
|
|
|
fi
|