Skip to content

Instantly share code, notes, and snippets.

@jasonmorganson
Last active December 12, 2015 06:48
Show Gist options
  • Save jasonmorganson/4731470 to your computer and use it in GitHub Desktop.
Save jasonmorganson/4731470 to your computer and use it in GitHub Desktop.
System configuration
#!/bin/bash
#
# Install with the following command:
#
#
# wget -q -O - https://gist.github.com/jmorganson/4731470/raw/system.sh | sh
# wget -q -O - http://files.morganson.net/system.sh | sh
# Ensure that the script is run as root
if [[ $EUID -ne 0 ]]; then
echo "Need to root privledges going forward, please login as root or sudo before running."
exit 1
fi
# Set system time to EST
sudo cp /usr/share/zoneinfo/US/Eastern /etc/localtime
# Check if tmux is installed before beginning
command -v tmux >/dev/null 2>&1
if [[ $? -ne 0 ]] ; then
echo -n "tmux not found. Installing... "
USE="-vim-syntax" emerge tmux >/dev/null 2>&1 &
wait
echo " tmux installed."
fi
# If a tmux session does not exist then create one
SESSION=system
tmux has-session -t $SESSION >/dev/null 2>/dev/null
if [[ $? -ne 0 ]] ; then
# Start the process in tmux
echo "Starting process in a new tmux session..."
tmux new-session -s $SESSION -d
tmux new-window -t $SESSION:1
tmux rename-window -t $SESSION:1 "Downloads"
tmux send -t $SESSION:1 "tail -f /var/log/emerge-fetch.log" C-m
tmux new-window -t $SESSION:2
tmux rename-window -t $SESSION:2 "Progress"
tmux send -t $SESSION:2 "tail -f /var/log/emerge.log" C-m
tmux select-window -t $SESSION:0
fi
# Send script to tmux session
tmux send -t $SESSION:0 "wget -q -O - https://gist.github.com/jmorganson/4731470/raw/system.sh | sh" C-m
# If inside a tmux session, then execute commands
if [[ -n "$TMUX" ]]; then
# Update configuration files
tmux rename-window -t $SESSION:0 "Update configuration files"
echo -n "Updating configuration files... "
# Emerge etckeeper before beginning
command -v etckeeper >/dev/null 2>&1
if [[ $? -ne 0 ]] ; then
emerge etckeeper >/dev/null 2>&1 &
wait
fi
# Setup etckeeper
echo "*" >> /etc/.gitignore
etckeeper init -d /etc >/dev/null 2>&1
etckeeper vcs remote add origin https://github.com/jmorganson/etc.git >/dev/null 2>&1
etckeeper vcs fetch origin >/dev/null 2>&1
etckeeper vcs reset --hard origin/master >/dev/null 2>&1
echo "done."
# Update portage
tmux rename-window -t $SESSION:0 "Update portage"
echo -n "Updating portage... "
emerge --sync >/dev/null 2>&1
emerge -u portage >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "done."
else
echo "ERROR!!!"
exit 1
fi
# Update profile
#* Hack around upgrading from default rackspace Gentoo version
tmux rename-window -t $SESSION:0 "Update profile"
echo -n "Updating profile... "
eselect profile set default/linux/amd64/13.0
# Set /var/lib/portage/world
wget -q https://gist.github.com/jmorganson/4997197/raw/world -O /var/lib/portage/world
echo "done."
# Update world
tmux rename-window -t $SESSION:0 "Update world"
echo -n "Updating world... "
emerge world >/dev/null 2>&1
echo "done."
# Finished
tmux rename-window -t $SESSION:0 ""
echo "Finished."
exit
fi
# Attach to tmux session
tmux attach-session -t $SESSION
if [[ $? -ne 0 ]]; then
echo "Could not attach to tmux session automatically"
echo "To attach, run:"
echo "tmux attach -t $SESSION"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment