Skip to content

Instantly share code, notes, and snippets.

@heywoodlh
Last active April 2, 2024 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heywoodlh/b7bd4b4d067dd93402b04015a0ee3531 to your computer and use it in GitHub Desktop.
Save heywoodlh/b7bd4b4d067dd93402b04015a0ee3531 to your computer and use it in GitHub Desktop.
Script for installing Linux environments

Usage:

Workstation:

curl -L https://files.heywoodlh.io/scripts/linux.sh | bash -s -- workstation --ansible --home-manager

Server:

curl -L https://files.heywoodlh.io/scripts/linux.sh | bash -s -- server --ansible --home-manager

Working with the Gist:

Source: https://gist.github.com/heywoodlh/b7bd4b4d067dd93402b04015a0ee3531

git clone git@github.com:b7bd4b4d067dd93402b04015a0ee3531.git linux-scripts
pre-commit:
commands:
upload-fastmail:
run: |
./upload.sh
#!/usr/bin/env bash
# Script to setup bare-minimum Linux env
# TESTING
if [[ $EUID -eq 0 ]]
then
echo "This script must not be run as root"
exit 1
fi
if ! uname | grep -iq 'Linux'
then
echo "This script must be run on a Linux system"
exit 1
fi
print-usage () {
printf "\nUsage: %s [workstation|server] [--ansible --home-manager]\n" "$0"
exit 0
}
[[ $# -eq 0 ]] && print-usage
# Exit if $1 doesn't exist or is not workstation/server
system="$1"
[[ "${system}" != "workstation" && "${system}" != "server" ]] && print-usage
# If --ansible provided, set ansible=true
echo "$@" | grep -q '\-\-ansible' && ansible=true
# If --home-manager provided, set home-manager=true
echo "$@" | grep -q '\-\-home-manager' && home_manager=true
# Install Nix
if [ ! -d /nix ]
then
echo "Installing Nix"
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
fi
[ -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ] && . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
install-nix-package () {
package_bin="$1"
package_source="$2"
unfree="$3"
exists=false
ls -l "$HOME/.nix-profile/bin/${package_bin}" &>/dev/null && exists=true
if [[ "${exists}" == "false" ]]
then
if [[ -n "${unfree}" ]]
then
echo "Installing unfree package ${package_source}"
NIXPKGS_ALLOW_UNFREE=1 nix profile install "${package_source}" --impure
else
echo "Installing package ${package_source}"
nix profile install "${package_source}"
fi
else
echo "Package ${package_source} already exists"
fi
}
if [[ "${home_manager}" != "true" ]]
then
echo "Installing standalone packages"
# Install flakes
flakes="vim tmux git"
for flake in $flakes
do
install-nix-package "${flake}" "github:heywoodlh/flakes?dir=${flake}"
done
# Configure GNOME
if [[ "${system}" == "workstation" ]]
then
echo "Configuring GNOME"
nix run "github:heywoodlh/flakes?dir=gnome"
fi
# Install 1password
install-nix-package "op" "github:heywoodlh/flakes?dir=1password" "unfree"
[[ "${system}" == "workstation" ]] && install-nix-package "1password" "nixpkgs#_1password-gui" "unfree"
[[ "${system}" == "workstation" ]] && mkdir -p ~/.config/autostart && ln -s ~/.nix-profile/share/applications/1password.desktop ~/.config/autostart/1password.desktop &>/dev/null
[[ "${system}" == "workstation" ]] && nix run "github:heywoodlh/flakes?dir=1password#op-desktop-setup" && chmod u+w ~/.config/1Password/settings/settings.json
# Install Lima for Docker
install-nix-package "lima" "nixpkgs#lima"
install-nix-package "docker" "nixpkgs#docker-client"
else
if [[ "${system}" == "workstation" ]]
then
echo "Installing home-manager desktop configuration"
nix run "github:heywoodlh/nixos-configs#homeConfigurations.heywoodlh.activationPackage" --impure --no-write-lock-file
fi
if [[ ${system} == "server" ]]
then
echo "Installing home-manager server configuration"
nix run "github:heywoodlh/nixos-configs#homeConfigurations.heywoodlh-server.activationPackage" --impure --no-write-lock-file
fi
fi
# Run ansible playbooks
if [[ "${ansible}" == "true" ]]
then
echo "Running ansible playbooks"
nix run "github:heywoodlh/flakes/$(git ls-remote https://github.com/heywoodlh/flakes | head -1 | awk '{print $1}')?dir=ansible#${system}"
fi
#!/usr/bin/env bash
# Get list of files, minus the script itself
script_dir="$(echo "$(dirname $0)")"
files="$(ls "${script_dir}" | grep -vE "$(basename "$0")|lefthook.yml")"
username="$(op-wrapper.sh item get "44abj6tnhmrjdhv6potivbc5by" --fields label=username)"
password="$(op-wrapper.sh item get "44abj6tnhmrjdhv6potivbc5by" --fields label=webdav)"
endpoint="https://myfiles.fastmail.com/files/scripts"
[[ -z "${username}" ]] && echo "Username not found" && exit 1
[[ -z "${password}" ]] && echo "Password not found" && exit 1
for file in ${files}
do
echo "Uploading ${file} to ${endpoint}/${file}"
curl --user "${username}:${password}" -T "${script_dir}/${file}" "${endpoint}/${file}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment