forked from BunsenLabs/bunsen-configs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bl-user-setup
executable file
·130 lines (111 loc) · 3.72 KB
/
bl-user-setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#
# bl-user-setup: a script to populate a new user's HOME directory
# using template files from /usr/share/bunsen/skel/
# Copyright: 2015-2017 John Crawley <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
USAGE="bl-user-setup: a script to populate a new user's HOME directory
using template files from /usr/share/bunsen/skel
Normally this script is run automatically on a user's first login,
and inhibited after that by a flag file:
~/.config/bunsen/bl-setup
It can, however be run again by a user to update their config files
from a new version of bunsen-configs. In this case backups will be made
of any files which are overwritten.
If the user has already made extensive changes to their config files
it would be better to copy in new settings from skel by hand.
Options:
-h --help
Show this message.
--refresh
Copy in any files in /usr/share/bunsen/skel which are different
from those in ~/. Overwritten files will be backed up.
"
readonly USER=${USER}
readonly HOME=${HOME}
readonly GROUP=$(id -ng "$USER")
# Do not apply BL configs to the root account.
if [[ "$USER" = root ]]; then
echo "$0: ERROR: USER is root, abort" >&2
exit 1
fi
# Check for the user home directory
if [[ -z "$HOME" || ! -d "$HOME" ]]; then
echo "$0: ERROR: user home directory <$HOME> is not set or does not exist." >&2
exit 1
fi
bkp_sfx="~$( date +%FT%T )~"
if [[ -n $1 ]]
then
case $1 in
-h|--help)
echo "$USAGE"
exit 0
;;
--refresh)
echo "New versions of files in /usr/share/bunsen/skel will be copied into
$HOME, overwriting files there.
(foo.template files will be copied to foo, if different.)
Any overwritten files will be backed up with a suffix of $bkp_sfx
NB if you have already made many changes to your desktop,
it would be easier to check /usr/share/bunsen/skel
and copy in any new settings to $HOME by hand.
Do you want to continue? (Y)
"
read -r
case ${REPLY^} in
Y|YES)
rs_opt='--verbose'
:
;;
*)
echo 'bye...'
exit 0
;;
esac
;;
*)
echo "$0: $1: bad option" >&2
exit 1
;;
esac
else
# If setup already run, do nothing.
[[ -f "$HOME/.config/bunsen/bl-setup" ]] && exit 0
fi
echo 'Running bl-user-setup to import configuration files.' >> "$HOME/.xsession-errors"
rsync -rlb ${rs_opt-} --checksum --suffix="$bkp_sfx" --safe-links /usr/share/bunsen/skel/ "$HOME"
for i in "$HOME/.gtk-bookmarks" "$HOME/.config/nitrogen/nitrogen.cfg"
do
[[ -f "${i}.template" ]] || continue
sed --in-place "s|%USERHOME%|$HOME|g" "${i}.template"
if [[ -f "$i" ]]
then
if diff -BEbZ "$i" "${i}.template" >/dev/null
then
rm "${i}.template"
else
mv "$i" "${i}${bkp_sfx}"
mv "${i}.template" "$i"
fi
else
mv "${i}.template" "$i"
fi
done
ln -sTf /usr/share/images/bunsen/wallpapers "$HOME/Pictures/wallpapers/bunsen"
mkdir -p "$HOME/.config/bunsen" # this should already exist
touch "$HOME/.config/bunsen/bl-setup"
chown -R "$USER":"$GROUP" "$HOME"
exit 0