3
# byobu-janitor - a collection of byobu tasks that ensure a clean
4
# environtment and smooth upgrades
6
# Copyright (C) 2009 Canonical Ltd.
8
# Authors: Dustin Kirkland <kirkland@byobu.org>
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation, version 3 of the License.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
[ -r "$HOME/.byoburc" ] && . "$HOME/.byoburc"
24
[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="@prefix@" || export BYOBU_PREFIX
25
. "${BYOBU_PREFIX}/lib/${PKG}/include/common"
27
# Ensure that all updates get run immediately
28
rm -rf "$BYOBU_RUN_DIR/.last.$BYOBU_BACKEND"
30
# Ensure that we re-check metadata service
31
rm -f "$BYOBU_CONFIG_DIR/.metadata_available" "$BYOBU_RUN_DIR/.metadata_available"
33
# Exit immediately, if we're not forced, and there is no reload flag
34
FLAG="$BYOBU_RUN_DIR/reload-required"
35
if [ "$1" != "--force" ] && [ ! -e "$FLAG" ]; then
39
# Set the rest of the variables
40
DEFAULT_PROFILE="light"
41
PROFILE="$BYOBU_CONFIG_DIR/profile"
43
# Create byobu-exchange buffer file, with secure permissions, if it doesn't exist
44
if ! [ -e "$BYOBU_RUN_DIR/printscreen" ]; then
45
if eval $BYOBU_TEST install >/dev/null 2>&1; then
46
install -m 600 /dev/null "$BYOBU_RUN_DIR/printscreen"
48
cp /dev/null "$BYOBU_RUN_DIR/printscreen"
49
chmod 600 "$BYOBU_RUN_DIR/printscreen"
53
# Affects: users who launched using sudo, such that their config dir
54
# is not writable by them
55
if [ -d "$BYOBU_CONFIG_DIR" ] && [ ! -w "$BYOBU_CONFIG_DIR" ]; then
56
echo "ERROR: [$BYOBU_CONFIG_DIR] is not writable by the current user" 1>&2
60
# Affects: Upgrades from <= byobu 4.30
61
# Clear out old style status configuration
62
if ! grep -qs "^screen_upper_left=" "$BYOBU_CONFIG_DIR/status"; then
63
rm -f "$BYOBU_CONFIG_DIR/status" "$BYOBU_CONFIG_DIR/statusrc"
66
# NOTE: Older version of Screen have an arbitrary limit of only being able
67
# to change colors 16 times in this 'hardstatus string'.
68
# Also committed in Upstream git, but not yet released.
69
# * http://savannah.gnu.org/bugs/?22146
70
# If we could reliably tell if we had a patched screen, we'd do so here...
73
# Affects: First runs with no configuration
74
# Seed the configuration
75
# Setup initial local user configuration
76
[ -r "$BYOBU_CONFIG_DIR/color" ] || printf "BACKGROUND=k\nFOREGROUND=w\nMONOCHROME=$MC" > "$BYOBU_CONFIG_DIR/color"
77
[ -r "$BYOBU_CONFIG_DIR/color.tmux" ] || sed -e "s/^#.*//" -e "/^\s*$/d" -e "s/^export //" "$BYOBU_PREFIX/lib/$PKG/include/colors" > "$BYOBU_CONFIG_DIR/color.tmux"
78
[ -r "$BYOBU_CONFIG_DIR/datetime.tmux" ] || printf 'BYOBU_DATE="%%Y-%%m-%%d "\nBYOBU_TIME="%%H:%%M:%%S"\n' > "$BYOBU_CONFIG_DIR/datetime.tmux"
79
[ -r "$BYOBU_CONFIG_DIR/profile" ] || echo "source \$BYOBU_PREFIX/share/$PKG/profiles/common" > "$BYOBU_CONFIG_DIR/profile"
80
[ -r "$BYOBU_CONFIG_DIR/profile.tmux" ] || echo "source \$BYOBU_PREFIX/share/$PKG/profiles/tmux" > "$BYOBU_CONFIG_DIR/profile.tmux"
81
[ -r "$BYOBU_CONFIG_DIR/keybindings" ] || echo "source \$BYOBU_PREFIX/share/$PKG/keybindings/common" > "$BYOBU_CONFIG_DIR/keybindings"
82
[ -r "$BYOBU_CONFIG_DIR/keybindings.tmux" ] || touch "$BYOBU_CONFIG_DIR/keybindings.tmux"
83
[ -r "$BYOBU_CONFIG_DIR/windows" ] || touch "$BYOBU_CONFIG_DIR/windows"
84
[ -r "$BYOBU_CONFIG_DIR/windows.tmux" ] || touch "$BYOBU_CONFIG_DIR/windows.tmux"
85
[ -r "$BYOBU_CONFIG_DIR/backend" ] || echo "BYOBU_BACKEND=$BYOBU_BACKEND" > "$BYOBU_CONFIG_DIR/backend"
86
[ -r "$BYOBU_CONFIG_DIR/.screenrc" ] || touch "$BYOBU_CONFIG_DIR/.screenrc"
87
[ -r "$BYOBU_CONFIG_DIR/.tmux.conf" ] || touch "$BYOBU_CONFIG_DIR/.tmux.conf"
88
for f in status statusrc; do
89
if [ ! -r "$BYOBU_CONFIG_DIR/$f" ]; then
90
# Copy from skeleton, if possible
91
cp -f "$BYOBU_PREFIX/share/$PKG/status/$f" "$BYOBU_CONFIG_DIR/$f"
95
# Affects: Upgrades from <= byobu-2.70 that autolaunch
96
# Update the byobu-launch line, if necessary
97
if grep -qs " $PKG-launch$" "$HOME"/.profile; then
101
# Affects: Upgrades from <= byobu-2.78 which might have "motd+shell"
102
# in their window list; update this to just "shell"
103
if grep -qs "motd+shell" "$BYOBU_CONFIG_DIR/windows"; then
104
$BYOBU_SED_INLINE -e "s/motd+shell/shell/g" "$($BYOBU_READLINK -f $BYOBU_CONFIG_DIR/windows)" || true
107
# Affects: Upgrades from <= byobu 4.3, remove ec2_rates
108
rm -f "$BYOBU_CONFIG_DIR/ec2_rates"
110
# Affects: Upgrades from <= byobu 4.4, update "shell" -> "byobu-shell"
111
if grep -qs " shell$" "$BYOBU_CONFIG_DIR/windows"; then
112
$BYOBU_SED_INLINE -e "s/ shell$/ $PKG-shell/g" "$($BYOBU_READLINK -f $BYOBU_CONFIG_DIR/windows)" || true
115
# Affects: Upgrades from <= byobu 4.22
116
killall -u $USER byobu-statusd >/dev/null 2>&1 || true
118
# Clean up flag (new and old)
119
rm -f "$FLAG" "/var/run/screen/S-$USER/$PKG.reload-required"
121
# Affects: Upgrades from <= byobu 5.50, install byobu prompt if using stock bashrc
122
if [ -r /etc/skel/.bashrc ] && [ -r "$HOME/.bashrc" ] && [ -w "$HOME/.bashrc" ] && \
123
! (grep -qs "#byobu-prompt#$" "$HOME/.bashrc") && ! [ -e "$BYOBU_CONFIG_DIR/prompt" ]; then
124
if eval $BYOBU_TEST diff >/dev/null 2>&1; then
125
if diff /etc/skel/.bashrc "$HOME/.bashrc" >/dev/null 2>&1; then
126
printf "[ -r $BYOBU_CONFIG_DIR/prompt ] && . $BYOBU_CONFIG_DIR/prompt #byobu-prompt#\n" >> "$HOME/.bashrc"
128
elif eval $BYOBU_TEST md5sum >/dev/null 2>&1; then
129
if [ "$(cat /etc/skel/.bashrc | md5sum)" = "$(cat $HOME/.bashrc | md5sum)" ]; then
130
printf "[ -r $BYOBU_CONFIG_DIR/prompt ] && . $BYOBU_CONFIG_DIR/prompt #byobu-prompt#\n" >> "$HOME/.bashrc"
134
[ -r "$BYOBU_CONFIG_DIR/prompt" ] || printf "[ -r ${BYOBU_PREFIX}/share/${PKG}/profiles/bashrc ] && . ${BYOBU_PREFIX}/share/${PKG}/profiles/bashrc #byobu-prompt#\n" > "$BYOBU_CONFIG_DIR/prompt"
136
# Affects: Upgrades from <= byobu 5.126, clear out ec2/rcs cost statuses
137
rm -f "$BYOBU_RUN_DIR"/cache.tmux/ec2_cost* "$BYOBU_RUN_DIR"/cache.tmux/rcs_cost* "$BYOBU_RUN_DIR"/status.tmux/ec2_cost* "$BYOBU_RUN_DIR"/status.tmux/rcs_cost*
139
# vi: syntax=sh ts=4 noexpandtab