~kirkland/byobu/trunk

« back to all changes in this revision

Viewing changes to usr/bin/byobu-janitor.in

  • Committer: kirkland at ubuntu
  • Date: 2023-11-22 22:45:43 UTC
  • Revision ID: kirkland@ubuntu.com-20231122224543-v5igclwtj4xga8tm
Permanently moved Byobu source code repository to https://github.com/dustinkirkland/byobu

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh -e
2
 
#
3
 
#    byobu-janitor - a collection of byobu tasks that ensure  a clean
4
 
#                    environtment and smooth upgrades
5
 
#
6
 
#    Copyright (C) 2009 Canonical Ltd.
7
 
#
8
 
#    Authors: Dustin Kirkland <kirkland@byobu.org>
9
 
#
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.
13
 
#
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.
18
 
#
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/>.
21
 
 
22
 
PKG="byobu"
23
 
[ -r "$HOME/.byoburc" ] && . "$HOME/.byoburc"
24
 
[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="@prefix@" || export BYOBU_PREFIX
25
 
. "${BYOBU_PREFIX}/lib/${PKG}/include/common"
26
 
 
27
 
# Ensure that all updates get run immediately
28
 
rm -rf "$BYOBU_RUN_DIR/.last.$BYOBU_BACKEND"
29
 
 
30
 
# Ensure that we re-check metadata service
31
 
rm -f "$BYOBU_CONFIG_DIR/.metadata_available" "$BYOBU_RUN_DIR/.metadata_available"
32
 
 
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
36
 
        exit 0
37
 
fi
38
 
 
39
 
# Set the rest of the variables
40
 
DEFAULT_PROFILE="light"
41
 
PROFILE="$BYOBU_CONFIG_DIR/profile"
42
 
 
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"
47
 
        else
48
 
                cp /dev/null "$BYOBU_RUN_DIR/printscreen"
49
 
                chmod 600 "$BYOBU_RUN_DIR/printscreen"
50
 
        fi
51
 
fi
52
 
 
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
57
 
        exit 1
58
 
fi
59
 
 
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"
64
 
fi
65
 
 
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...
71
 
MC=0
72
 
 
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"
92
 
        fi
93
 
done
94
 
 
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
98
 
        $PKG-launcher-install
99
 
fi
100
 
 
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
105
 
fi
106
 
 
107
 
# Affects: Upgrades from <= byobu 4.3, remove ec2_rates
108
 
rm -f "$BYOBU_CONFIG_DIR/ec2_rates"
109
 
 
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
113
 
fi
114
 
 
115
 
# Affects: Upgrades from <= byobu 4.22
116
 
killall -u $USER byobu-statusd >/dev/null 2>&1 || true
117
 
 
118
 
# Clean up flag (new and old)
119
 
rm -f "$FLAG" "/var/run/screen/S-$USER/$PKG.reload-required"
120
 
 
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"
127
 
                fi
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"
131
 
                fi
132
 
        fi
133
 
fi
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"
135
 
 
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*
138
 
 
139
 
# vi: syntax=sh ts=4 noexpandtab