-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_user.sh
executable file
·104 lines (85 loc) · 2.8 KB
/
setup_user.sh
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
#!/bin/bash
#
# This script is meant to be run from the GUI of the user that was just created.
#
# Friendly reminders:
# 1) Run `./dkorolev_setup_system.sh` first, to set up the system before setting up users.
# 2) The recommended way to create users is `sudo adduser --encrypt-home $U`.
# 3) Don't forget to run `sudo ./govern_user.sh $U` right after adding the user.
#
# Please refer to the README for more details.
set -e
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
if ! [ -d /var/dotfiles ] ; then
echo 'Expecting to have the `/var/dotfiles` dir created during the system setup phase.'
exit 1
fi
U=$(whoami)
# Set the shell to zsh.
ZSH=$(which zsh)
if [ "$ZSH" != "$SHELL" ] ; then
chsh -s "$ZSH" $U
else
echo 'The shell is already `zsh`.'
fi
# Install the dotfiles.
for i in $(find /var/dotfiles/ -maxdepth 1 -name '.*' -type f) ; do
cp $i ~
chmod +w ~/$(basename $i)
chown $U: ~/$(basename $i)
done
# Install YCM.
if ! [ -s ~/.ycm_installed ] ; then
T_BEGIN=$(date +%s)
git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/Valloric/YouCompleteMe ~/.vim/pack/plugins/opt/YouCompleteMe
T_YCM_CLONE_DONE=$(date +%s)
echo
echo "YCM clone took $((T_YCM_CLONE_DONE-T_BEGIN))s."
echo
(cd ~/.vim/pack/plugins/opt/YouCompleteMe; ./install.py --all)
T_YCM_DONE=$(date +%s)
echo
echo "YCM build took $((T_YCM_DONE-T_YCM_CLONE_DONE))s."
echo
echo "yes" > ~/.ycm_installed
else
echo 'YCM is already installed.'
fi
# If there is a profile to restore.
if [ -f "/var/userdata/$U.tar.gz.des3" ] ; then
echo 'A profile to restore is present. Restoring.'
DIR=~/.unpacked.$(date +%s)
mkdir $DIR
(cd $DIR; openssl des3 -d -pbkdf2 <"/var/userdata/$U.tar.gz.des3" | tar xz)
# Chrome
CHROME_BASE=$("$SCRIPT_DIR/chrome_default_profile_base_dir.sh" $U)
if [ "$CHROME_BASE" != "" ] ; then
if [ -d "$CHROME_BASE/Default" ] ; then
mv "$CHROME_BASE/Default" "$CHROME_BASE/Default.$(date +%s)"
fi
mv $DIR/Default "$CHROME_BASE"
echo 'Chrome `Default` installed.'
else
echo 'Now seeing Chrome `Default` dir, ignoring Chrome profile setup.'
fi
# Wallpaper.
if [ -f $DIR/Downloads/wall.jpg ] ; then
echo 'Has wallpaper.'
WALL="/home/$U/Pictures/wall-$(date +%s).jpg"
cp $DIR/Downloads/wall.jpg "$WALL"
else
echo 'Using the defaut wallpaper.'
[ -f ~/Pictures/background.jpg ] || (cd ~/Pictures; wget http://dima.ai/static/background.jpg)
WALL="/home/$U/Pictures/background.jpg"
fi
gsettings set org.gnome.desktop.background picture-uri "file://${WALL}"
# Profile pic.
if [ -f $DIR/Downloads/icon.png ] ; then
echo 'Has icon.'
cat $DIR/Downloads/icon.png >/var/lib/AccountsService/icons/$U && echo 'Icon setup OK.' || echo 'Icon fail.'
else
echo 'No icon.'
fi
else
echo 'No profile to restore was found.'
fi