home · contact · privacy
Update raspi setup.
[config] / buster / setup_scripts / setup_home.sh
1 #!/bin/sh
2 set -e
3
4 if [ "$#" -ne 1 ]; then
5     echo 'Need exactly one argument (system name).'
6     false
7 fi
8 if [ ! "$1" = "eeepc" ] && [ ! "$1" = "x200s" ]&& [ ! "$1" = "x220" ]; then
9     echo "Need legal system name."
10     false
11 fi
12 system_name="$1"
13
14 public_repos_dir="${HOME}/public_repos"
15 config_tree_prefix="${public_repos_dir}/config"
16 path_borgscript="${config_tree_prefix}/all_new_2018/borg.sh"
17 config_tree_buster="${config_tree_prefix}/buster"
18 setup_scripts_dir="${config_tree_buster}/setup_scripts"
19 repos_list_file="${public_repos_dir}/repos"
20 dir_secrets="${HOME}/tmp_secrets"
21 borgkeys_dir=~/.config/borg/keys
22 borgrepos_file=~/.borgrepos
23 ssh_dir=~/.ssh
24 authinfo_file=.authinfo
25 maildir=~/mail/maildir
26
27 ensure_repo() {
28     repo_name="${1}"
29     if [ ! -d "${public_repos_dir}/${repo_name}" ]; then
30         cd "${public_repos_dir}"
31         git clone plom@plomlompom.com:/var/repos/${repo_name}
32     fi
33 }
34
35 # Set up iniitial non-public parts of infrastructure: SSH authentication.
36 cd "${dir_secrets}"
37 mkdir -p "${ssh_dir}"
38 echo "Setting up .ssh"
39 cp id_rsa ~/.ssh
40 stty -echo
41 ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
42 stty echo
43 eval $(ssh-agent)
44 ssh-add
45 ssh-keyscan -H "plomlompom.com" >> ~/.ssh/known_hosts
46
47 # Clone config to copy dotfiles etc. from it.
48 cd
49 mkdir -p "${public_repos_dir}"
50 ensure_repo config
51 cd "${setup_scripts_dir}"
52 ./copy_dirtree.sh "${config_tree_buster}/home_files" "${HOME}" minimal user "${system_name}"
53
54 # Set up native messenger for tridactyl.
55 version='ef9f02d0da258f68d7faf8898707f6d83d90d07a'
56 curl -fsSl "https://raw.githubusercontent.com/tridactyl/tridactyl/${version}/native/install.sh" | bash
57
58 # Set up further non-public parts of infrastructure.
59 cd "${dir_secrets}"
60 script -c 'gpg --import secret_keys.asc' /dev/null
61 tar xf borg_keyfiles.tar
62 mkdir -p "${borgkeys_dir}"
63 mv borg_keyfiles/* "${borgkeys_dir}"
64 # .authinfo may not be present on every secrets drive yet
65 if [ -f "${authinfo_file}" ]; then
66     cp "${authinfo_file}" ~
67 fi
68 cd
69 rm -rf "${dir_secrets}"
70
71 # Sync org dir via borgbackup. For this we need the borgbackup servers
72 # in our .ssh/known_hosts file.
73 cat "${borgrepos_file}" | while read line; do
74     first_char=$(echo "${line}" | cut -c1)
75     if [ "${first_char}" = "#" ]; then
76         continue
77     fi
78     server=$(echo "${line}" | sed 's/.*@//')
79     ssh-keyscan "${server}" >> "${ssh_dir}"/known_hosts
80 done
81 BORG_PASSPHRASE="${SECRETS_PASS}" "${path_borgscript}" orgpull
82
83 # Fill ~/public_repos.
84 cat "${repos_list_file}" | while read line; do
85     first_char=$(echo "${line}" | cut -c1)
86     if [ "${first_char}" = "#" ]; then
87         continue
88     fi
89     ensure_repo "${line}"
90 done
91
92 # Set up e-mail system. Note that we only do mbsync if the imap pass file
93 # is found. It may not be present on every secrets drive yet, so we have to
94 # deal with the possibility of it being absent at this point.
95 mkdir -p "${maildir}"  # expected by mbsync/isync
96 if [ -f "${HOME}/${authinfo_file}" ]; then
97     mbsync -a
98     notmuch new
99 fi
100
101 # Final note on how to integrate tridactyl.
102 echo "TODO: As tridactyl user, don't forget to do :source on the first Firefox run, wait a little while (Tridactyl needs to walk through all commands in the .tridactylrc) and then re-start."