# See the License for the specific language governing permissions and
# limitations under the License.
-
-
-
-# for bootstrapping a new machine
-
-# in case we need it,
-# to make ssh interactive shell run better, we run this first.
-sudo bash -c 'source /a/c/.bashrc && source /a/exe/ssh-emacs-setup'
-
-
+# for setting up a new machine
# usage: $0 [-r] HOSTNAME
# tips:
# run any sudo command first so your pass is cached
# set the scrollback to unlimited in case something goes wrong
-if [[ $EUID == 0 ]]; then
- if getent passwd iank || getent passwd ian ; then
- echo "$0: error: running as root. unprivileged user exists. use it."
- exit 1
- else
- echo "$0: warning: running as root. I will setup users then exit"
- fi
-fi
+####### begin setup environment #######
+
+
+### make ssh interactive shell run better. for when running line interactively line by line
+sudo bash -c 'source /a/c/.bashrc && source /a/exe/ssh-emacs-setup'
+
+
+##### setup error handling
interactive=true # set this to false to force set -x
[[ $- == *i* ]] || interactive=false
-
if ! $interactive; then
set -x
set -e -o pipefail
fi
set -E
trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
+for x in /a/bin/errhandle/*-function; do
+ source $x
+done
+set +e
+$interactive || errcatch
+### setup logging
exec &> >(sudo tee -a /var/log/distro-begin)
echo "$0: $(date): starting now)"
-# headless=false # unused atm
+
+### sanity checking
+if [[ $EUID == 0 ]]; then
+ if getent passwd iank || getent passwd ian ; then
+ echo "$0: error: running as root. unprivileged user exists. use it."
+ exit 1
+ else
+ echo "$0: warning: running as root. I will setup users then exit"
+ fi
+fi
+
+
+### arg parsing
recompile=false
# for copying to a new data fs
bootstrapfs=false # old flag, needs new look before using.
-r) recompile=true; shift ;;
esac
done
-
if [[ $1 ]]; then
export HOSTNAME=$1
fi
+
+##### variables/env setup
+script_dir="$(readlink -f "$BASH_SOURCE")"
+source $script_dir/pkgs
+set +x
+source /a/bin/distro-functions/src/identify-distros
+$interactive || set -x
for f in iank-dev htpc treetowl x2 frodo tp li lj demohost kw fz; do
eval "$f() { [[ $HOSTNAME == $f ]]; }"
done
has_btrfs() { ! linode; }
home_network() { ! linode; }
encrypted() { has_p; }
-
shopt -s extglob
export GLOBIGNORE=*/.:*/..
-umask 0002
+umask 022
+PATH="/a/exe:$PATH"
+sed="sed --follow-symlinks"
+
+####### end setup environment #######
-####### end command line parsing
-PATH="/a/exe:$PATH"
-sed="sed --follow-symlinks"
##### begin setup encryption scripts ######
if encrypted; then
##### end setup encryption scripts ######
-install-myqueue
+# disabled until its fixed up
+# install-myqueue
-# this script has been designed to be idempotent
# todo, it would be nice to cut down on some of the output
-
-for x in /a/bin/errhandle/*-function; do
- source $x
-done
-
-
-set +e
-$interactive || errcatch
-set +x
-source /a/bin/distro-functions/src/identify-distros
-$interactive || set -x
-
+##### fedora prereq/fundamental settings
if isfedora; then
# comment out line disallowing calling sudo in scripts
sudo $sed -i 's/^Defaults *requiretty/#\0 # ian commented/' /etc/sudoers
- # turn on magic sysrq commands for this boot cycle
+ # turn on magic sysrq commands
echo 1 > sudo dd of=/proc/sys/kernel/sysrq
echo "kernel.sysrq = 1" > /etc/sysctl.d/90-sysrq.conf
# selinux is not user friendly. Like, you enable samba, but you haven't run the magic selinux commands so it doesn't work
fi
+#### rerun my fai-time scripts
# already ran for pxe installs, but used for vps & updates
distro=$(distro-name)
case $distro in
;;
esac
+###### setup hostname
sudo $sed -i '/^127\.0\.1\.1/d' /etc/hosts
echo "127.0.1.1 $HOSTNAME.b8.nz $HOSTNAME" | sudo tee -a /etc/hosts
+##### exit first stage if running as root
if [[ $EUID == 0 ]]; then
echo "$0: running as root. exiting now that users are setup"
exit 0
fi
-#### begin link bashrc for root ######
+#### setup bash for root
for x in /a/c/{.bashrc,brc,.bash_profile,.profile,.inputrc,path_add_function}; do
sudo -i <<EOF
PATH="/a/exe:$PATH"
lnf $x /root
EOF
done
-#### end link bashrc repo for root ######
+###### do conflink
# li needs the bind group before conflink
if [[ $HOSTNAME == li ]]; then
getent group bind &>/dev/null || sudo groupadd -r bind
# this needs to be before installing pacserve so we have gpg conf.
conflink
+###### bash environment setup
set +x
errallow
source /etc/profile.d/environment.sh
$interactive || set -x
-# passwordless sudo
+#### setup passwordless sudo
tu /etc/sudoers <<EOF
$USER ALL=(ALL) NOPASSWD: ALL
Defaults env_keep += SUDOD
EOF
-# enable magic sysrq keys. debian docs say it is already enabled by default
-isfedora && tu /etc/sysctl.conf 'kernel.sysrq = 1'
-
-
-if isdeb; then
- codename=$(debian-codename)
- ## ian: disabled. backports are not being published atm due to rust packaging issue
- # if isdebian-stable && has_x; then
- # s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
- # deb http://mozilla.debian.net/ $codename-backports firefox-release
- # deb-src http://mozilla.debian.net/ $codename-backports firefox-release
- # EOF
- # p update
- # # take care of mozilla signing errors in previous command
- # pi pkg-mozilla-archive-keyring
- # fi
- p update
-
-fi
+#### setup firefox backport
+## ian: disabled. backports are not being published atm due to rust packaging issue
+# if isdeb; then
+# codename=$(debian-codename)
+# if isdebian-stable && has_x; then
+# s dd of=/etc/apt/sources.list.d/mozilla-iceweasel.list <<EOF
+# deb http://mozilla.debian.net/ $codename-backports firefox-release
+# deb-src http://mozilla.debian.net/ $codename-backports firefox-release
+# EOF
+# p update
+# # take care of mozilla signing errors in previous command
+# pi pkg-mozilla-archive-keyring
+# fi
+# p update
+# fi
-###### begin arch aur wrapper ########
+###### arch aur wrapper setup
if isarch; then
#https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages
sudo pacman -S --noconfirm --needed base-devel jq
sudo systemctl start pacserve.service
fi
-###### end arch aur wrapper ########
+#### update all packages
pup
-###### begin trash cli install ######
+###### p1 packages install ######
if isarch; then
- # strange error if just installing trash-cli: "pyalpm requires python",
+ # requirement for trash-cli.
+ # background: strange error if just installing trash-cli: "pyalpm requires python",
# so I see that it requires python2, and installing that manually fixes it.
# I didn\'t see this on earlier installation, main thing which changed was
# pacserve, so not sure if it\'s related.
pi python2
fi
-pi trash-cli
-###### end trash cli install ######
+pi ${p1[@]}
-######## begin fix evbug bug ######
+######## fix evbug bug ######
case $distro in
trisquel|ubuntu)
# noticed in flidas.
fi
;;
esac
-######## end fix evbug bug ######
-
-###### begin link files ###########
+###### link files
# convenient to just do all file linking in one place
-
-
s lnf -T /a/bin /b
s lnf -T /nocow/t /t
-
if has_p; then
lnf -T /p/News ~/News
fi
-
s lnf /q/root/.editor-backups /q/root/.undo-tree-history \
/a/opt /a/c/.emacs.d $HOME/mw_vars /k/backup /root
-
rootsshsync
-
s lnf /a/c/.vim /a/c/.vimrc /a/c/.gvimrc /root
-
-# machine is going away
-# if [[ $HOSTNAME == htpc ]]; then
-# lnf -T /i/Videos ~/Downloads
-# fi
-
if has_p; then
# for dovecot
lnf -T /i/k/mboxes ~/mail
fi
-###### end link files ###########
-
##### basic needed packages
fi
### end setup for keyboard and redshift ###
-
-pi cryptsetup lvm2
# enables trim for volume delete, other rare commands.
sudo $sed -ri 's/( *issue_discards\b).*/\1 = 1/' /etc/lvm/lvm.conf
fi
- pi ghc sakura
+ pi ${p2[@]}
# todo, also note for work comp, scp opt/org-mode bin/build-scripts
# use the package manger version to install the cabal version
- pi cabal-install
cabal update
PATH="$PATH:$HOME/.cabal/bin"
# todo, on older ubuntu I used cabal xmonad + xfce,
# see /a/bin/old-unused/xmonad-cabal.sh
- # trying out the distros versions newer distros
- pi xmonad
if isarch; then
# for displaying error messages.
# optional dependency in arch, standard elsewhere.