home · contact · privacy
Add missing deps for server to remain accessible.
[config] / bookworm / setup_scripts / setup_home.sh
1 #!/bin/sh
2 set -e
3 . ./misc.sh
4 . ../../misc.sh
5
6 expect_n_args 1 "(system name)" "$@"
7 get_system_name_arg "$1"
8
9 cd $setup_scripts_dir
10 ./copy_dirtree.sh "${config_tree_prefix}/home_files" "${HOME}" minimal user "${system_name}"
11
12 secrets_dev="sdb"
13 source_dir_secrets="/media/${secrets_dev}/to_usb"
14 target_dir_secrets="${HOME}/tmp_secrets"
15 echo "Put secrets drive into slot for /dev/${secrets_dev}."
16 while [ ! -e /dev/"${secrets_dev}" ]; do
17     sleep 1
18 done
19 stty -echo
20 printf "Secrets passphrase: "
21 read SECRETS_PASS 
22 stty echo
23 echo "" # newline so user knows their input return was accepted
24 sudo -v
25 echo "${SECRETS_PASS}" | sudo pmount /dev/"${secrets_dev}"
26 cp -a "${source_dir_secrets}" "${target_dir_secrets}"
27 sudo chown -R plom:plom "${target_dir_secrets}"
28 sudo pumount "${secrets_dev}"
29 echo "You can remove /dev/${secrets_dev} now."
30
31 # Set up iniitial non-public parts of infrastructure: SSH authentication.
32 ssh_dir=~/.ssh
33 cd "${target_dir_secrets}"
34 mkdir -p "${ssh_dir}"
35 echo "Setting up .ssh"
36 cp id_rsa ~/.ssh
37 stty -echo
38 ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
39 stty echo
40 eval $(ssh-agent)
41 ssh-add
42 ssh-keyscan -H "plomlompom.com" >> ~/.ssh/known_hosts
43
44 # Fill ~/public_repos.
45 public_repos_dir="${HOME}/public_repos"
46 repos_list_file="${public_repos_dir}/repos"
47 mkdir -p "${public_repos_dir}"
48 cat "${repos_list_file}" | while read line; do
49     first_char=$(echo "${line}" | cut -c1)
50     if [ "${first_char}" = "#" ]; then
51         continue
52     fi
53     repo_name="${line}"
54     if [ ! -d "${public_repos_dir}/${repo_name}" ]; then
55         cd "${public_repos_dir}"
56         git clone plom@plomlompom.com:/var/repos/${repo_name}
57     fi
58 done
59
60 # Remove redundant config repo copy.
61 config_tree_prefix="${public_repos_dir}/config/${debian_version}"
62 rm -rf ~/config
63
64 # # Set up native messenger for tridactyl.
65 # version='ef9f02d0da258f68d7faf8898707f6d83d90d07a'
66 # curl -fsSl "https://raw.githubusercontent.com/tridactyl/tridactyl/${version}/native/install.sh" | bash
67
68 # Set up further non-public parts of infrastructure.
69 cd "${target_dir_secrets}"
70 script -c 'gpg --import secret_keys.asc' /dev/null
71 path_borgscript="${config_tree_prefix}//borg.sh"
72
73 # borg setup
74 borgkeys_dir=~/.config/borg/keys
75 borgrepos_file=~/.borgrepos
76 tar xf borg_keyfiles.tar
77 mkdir -p "${borgkeys_dir}"
78 mv borg_keyfiles/* "${borgkeys_dir}"
79 # Sync org dir via borgbackup. For this we need the borgbackup servers
80 # in our .ssh/known_hosts file.
81 cat "${borgrepos_file}" | while read line; do
82     first_char=$(echo "${line}" | cut -c1)
83     if [ "${first_char}" = "#" ]; then
84         continue
85     fi
86     server=$(echo "${line}" | sed 's/.*@//')
87     ssh-keyscan "${server}" >> "${ssh_dir}"/known_hosts
88 done
89 BORG_PASSPHRASE="${SECRETS_PASS}" "${path_borgscript}" orgpull
90
91 # .authinfo may not be present on every secrets drive yet
92 authinfo_file=.authinfo
93 if [ -f "${authinfo_file}" ]; then
94     cp "${authinfo_file}" ~
95 fi
96 cd
97
98 maildir=~/mail/maildir
99 # # Set up e-mail system. Note that we only do mbsync if the imap pass file
100 # # is found. It may not be present on every secrets drive yet, so we have to
101 # # deal with the possibility of it being absent at this point.
102 mkdir -p "${maildir}"  # expected by mbsync/isync
103 if [ -f "${HOME}/${authinfo_file}" ]; then
104     mbsync -a
105     notmuch new
106 fi
107
108 # # Final note on how to integrate tridactyl.
109 # 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."