diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2015-09-11 16:08:22 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2015-09-11 16:08:22 +0200 |
commit | bb8e24cb3936df895aedd4418c2841a03a9bb58d (patch) | |
tree | e71175ae1a8e74ff54acca9217c74d0d20c152d6 | |
parent | e9fd4bba0d8bf404a1f2d24e1d36bd68cbbfdbaa (diff) | |
parent | 436442a0f7c06682de2bd42764a8656e5aa8cb4c (diff) |
Merge pull request #77 from matthiasbeyer/channel-update
Channel update tool
-rwxr-xr-x | nix-script-channel-update.sh | 69 | ||||
-rw-r--r-- | nix-utils.sh | 7 |
2 files changed, 76 insertions, 0 deletions
diff --git a/nix-script-channel-update.sh b/nix-script-channel-update.sh new file mode 100755 index 0000000..505e4b0 --- /dev/null +++ b/nix-script-channel-update.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh + +usage() { + cat <<EOS + $(help_synopsis "channel" "update [-h] [-t <name>] [-w <cfgdir>] [-n]") + + -t <name> | Name for the new tag, instead of nixos-<host>-channel-<num> + -w <cfgdir> | Alternative config dir, default: $RC_CONFIG + -n | DON'T include hostname in tag name + -h | Show this help and exit + +$(help_end) +EOS +} + +TAG_NAME="" +CONFIG=$RC_CONFIG +HOST="$(hostname)" + +while getopts "t:w:nh" OPTION +do + case $OPTION in + t) + TAG_NAME=$OPTARG + dbg "TAG_NAME = $TAG_NAME" + ;; + + w) + CONFIG=$OPTARG + dbg "CONFIG = $CONFIG" + ;; + + n) + HOST="" + dbg "HOST = $HOST" + ;; + + h) + usage + exit 0 + ;; + + *) + ;; + esac +done + +[[ -z "$CONFIG" ]] && \ + stderr "No configuration git directory." && \ + stderr "Won't do anything" && exit 1 + +stdout "Updating nix-channel" +explain sudo nix-channel --update +stdout "Ready with updating" + +if [[ -z "$NAME" ]] +then + TAG_NAME="nixos-$([[ ! -z "$HOST" ]] && echo "$HOST-")channel-$(current_channel_generation)" + stdout "Tag name: '$TAG_NAME'" +fi + +stdout "Resetting sudo password" +sudo -k + +stdout "Tagging '$CONFIG' repo with tag name '$TAG_NAME'" +__git "$CONFIG" tag $TAG_NAME + diff --git a/nix-utils.sh b/nix-utils.sh index 382763f..4028004 100644 --- a/nix-utils.sh +++ b/nix-utils.sh @@ -95,6 +95,13 @@ current_user_generation() { } # +# get the current channel generation +# +current_channel_generation() { + grep_generation "sudo nix-env -p /nix/var/nix/profiles/per-user/root/channels --list-generations" +} + +# # Ask the user whether to continue or not # continue_question() { |