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@canonical.com>
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 "/etc/$PKG/socketdir" ] && . "/etc/$PKG/socketdir" || SOCKETDIR="/var/run/screen"
24
RUN="$SOCKETDIR/S-$USER"
25
FLAG="$RUN/$PKG.reload-required"
27
# Exit immediately, if we're not forced, and there is no reload flag
28
if [ "$1" != "--force" ] && [ ! -e "$FLAG" ]; then
32
# Set the rest of the variables
33
DEFAULT_PROFILE="light"
34
PROFILE="$HOME/.$PKG/profile"
36
# Establish ssh-agent socket, helps when reconnecting to a detached session
37
if [ -S "$SSH_AUTH_SOCK" ] && [ ! -h "$SSH_AUTH_SOCK" ] && [ -w "$RUN" ]; then
38
rm -f "$RUN/$PKG.ssh-agent"
39
ln -sf "$SSH_AUTH_SOCK" "$RUN/$PKG.ssh-agent"
42
# Create byobu-exchange buffer file, with secure permissions, if it doesn't exist
43
if [ -w "$RUN" ] && [ ! -e "$RUN/$PKG-exchange" ]; then
44
install -m 600 /dev/null "$RUN/$PKG-exchange"
47
# Affects: users who launched using sudo, such that their config dir
48
# is not writable by them
49
if [ -d "$HOME/.$PKG" ] && [ ! -w "$HOME/.$PKG" ]; then
50
echo "ERROR: [$HOME/.$PKG] is not writable by the current user" 1>&2
54
# Affects: First runs with no configuration
55
# Seed the configuration
56
[ -d "$HOME/.$PKG" ] || mkdir -p "$HOME/.$PKG"
57
[ -r "$HOME/.$PKG/color" ] || printf "BACKGROUND=k\nFOREGROUND=w\nMONOCHROME=0" > "$HOME/.$PKG/color"
58
[ -r "$PROFILE" ] || ln -sf /usr/share/$PKG/profiles/common "$PROFILE"
60
# Affects: Symlinks pointing to color profiles
61
if [ -h "$PROFILE" ] && \
62
stat "$PROFILE" | grep -qs "File:.*->.*/usr/share/byobu/profiles/" && \
63
! stat "$PROFILE" | grep -qs "File:.*->.*/usr/share/byobu/profiles/common" ; then
67
color=$(ls -l "$PROFILE" | sed "s/^.*\///")
69
black|dark) BG=k; FG=W;;
70
dark_blue) BG=b; FG=W;;
71
dark_cyan) BG=c; FG=W;;
72
dark_green) BG=g; FG=W;;
73
dark_purple) BG=m; FG=W;;
74
dark_red) BG=r; FG=W;;
75
dark_yellow) BG=y; FG=W;;
77
light_blue) BG=B; FG=k;;
78
light_cyan) BG=C; FG=k;;
79
light_green) BG=G; FG=k;;
80
light_purple) BG=M; FG=k;;
81
light_red) BG=R; FG=k;;
82
light_yellow) BG=Y; FG=k;;
85
rm -f "$PROFILE" 2>/dev/null
86
byobu-select-profile -b $BG -f $FG >/dev/null 2>&1
89
[ -s "$HOME/.$PKG/keybindings" ] || echo "source /usr/share/$PKG/keybindings/common" > "$HOME/.$PKG/keybindings"
90
[ -r "$HOME/.$PKG/status" ] || $(grep -A 999999 BEGIN_CUT_HERE /etc/$PKG/statusrc | grep -B 999999 END_CUT_HERE | grep -v CUT > "$HOME/.$PKG/status")
91
[ -r "$HOME/.$PKG/windows" ] || touch "$HOME/.$PKG/windows"
92
[ -r "$HOME/.screenrc" ] || touch "$HOME/.screenrc"
94
# Affects: Upgrades from <= byobu-2.11
95
# The status scripts used to have hyphens in their name, but now use
96
# underscores such that we can source the file as a shell snippet;
97
# fix existing status configuration.
98
sed -i "s/\(.*\)-\(.*\)=/\1_\2=/g" "$HOME/.$PKG/status"
99
sed -i "s/^disk-.*=/disk=/" "$HOME/.$PKG/status"
100
sed -i "s/^network-.*=/network=/" "$HOME/.$PKG/status"
102
# Affects: Upgrades from <= byobu-2.16
103
# screen-launcher was renamed byobu-launcher; if the user has byobu
104
# set to auto-launch, update their configuration to use the byobu-launcher
105
if grep -qs "screen-launcher$" "$HOME/.profile"; then
106
byobu-launcher-install
109
# Affects: Upgrades from <= byobu-2.25
110
# Collapse separate status config files into the sourced config
111
for i in disk network distro logo; do
112
if [ -r "$HOME/.$PKG/$i" ]; then
113
val=`cat $HOME/.$PKG/$i`
114
uc=`echo "$i" | tr "[:lower:]" "[:upper:]"`
117
key="MONITORED_"$uc ;;
121
echo "$key=\"$val\"" >> "$HOME/.$PKG/statusrc"
126
# Affects: Upgrades from <= byobu-2.57 that autolaunch
127
# If the global autolaunch is on, then remove duplicate entry in ~/.profile
128
if [ -h "/etc/profile.d/Z98-$PKG.sh" ]; then
129
sed -i "/$PKG-launcher$/d" "$HOME"/.profile || true
132
# Affects: Upgrades from <= byobu-2.70 that autolaunch
133
# Update the byobu-launch line, if necessary
134
if grep -qs "^\`echo \$- | grep -qs i\` && $PKG-launcher$" "$HOME"/.profile; then
135
$PKG-launcher-uninstall && $PKG-launcher-install