Commit fc596f24 authored by Otheus Shelling's avatar Otheus Shelling 😀
Browse files

Initial commit

parents
#!/bin/bash
${debug:+set -x}
fatal() { echo >&2 "$@"; exit 1; }
warn() { echo >&2 "$@"; }
## variable initialization and global checks
PATH="/usr/bin:/bin"
test -z "$HOME" || HOME=$(getent passwd `id -u`|cut -d: -f6)
test -z "$HOSTNAME" || HOSTNAME=$(hostname -s)
PROFILE="${1:-default}"
DATE=$(date +%F)
prodir="$HOME/.profiles/$PROFILE"
prodir_rel=".profiles/$PROFILE"
if [ ! -d "$prodir" ]; then
fatal "Unknown profile $PROFILE: $prodir not found"
fi
## Place to put files that should not be overwritten
stashdir="$HOME/.profiles/stash-$HOSTNAME-$DATE-$$"
mkdir $stashdir
trap "rmdir --ignore-fail-on-non-empty $stashdir" 0
## pull?
cd $HOME/.profiles
.lib/fix-permissions $PROFILE
install -m 700 -t .git/hooks/ .lib/hooks/*
## Merge, replace, or stash & replace all files
## in the specified profile directory, except
## for .profiles-*, .git/, .git*, INSTALL and matching
## expressions in .profiles-skip . (TODO not yet tested)
## NOTE: .gitconfig will be replaced.
##
## If the target exists and is NOT a soft-link
## then if the target is a directory: rsync the dirs
## else if it is a normal file: stash the file and replace it
## else leave it alone.
##
cd $HOME
{ cd $prodir; command ls -A1; } |
if [ -f $prodir/.skip ]; then
command grep -v -f $prodir/.profiles-skip
else
command cat
fi |
while read node; do
# Never copy these over
case $node in
.gitconfig) : ;; # Yes, copy this one
.profiles-|.git*|INSTALL) continue;;
esac
# Replace softlinks,
# Merge directories,
# Stash and replace normal files
if [ -e "$HOME/$node" -a ! -L "$HOME/$node" ]; then
if [ -d "$HOME/$node" ]; then
# merge directories with rsync
command rsync -qrpcbt --backup-dir="$stashdir" \
"$prodir_rel/$node/." "$node"
continue
elif [ -f "$HOME/$node" ]; then
# stash
warn "Stashing $node"
command mv "$HOME/$node" "$stashdir/"
else
warn "Not replacing or stashing $node"
continue
fi
fi
# replace:
command ln -sf "$prodir_rel/$node"
done
exit 0
#!/bin/bash
${debug:+set -x}
fatal() { echo >&2 "$@"; exit 1; }
warn() { echo >&2 "$@"; }
## variable initialization and global checks
PATH="/usr/bin:/bin"
test -z "$HOME" || HOME=$(getent passwd `id -u`|cut -d: -f6)
test -z "$HOSTNAME" || HOSTNAME=$(hostname -s)
PROFILE="${1:-default}"
DATE=$(date +%F)
prodir="$HOME/.profiles/$PROFILE"
prodir_rel=".profiles/$PROFILE"
if [ ! -d "$prodir" ]; then
fatal "Unknown profile $PROFILE: $prodir not found"
fi
## Place to put files that should not be overwritten
stashdir="$HOME/.profiles/stash-$HOSTNAME-$DATE-$$"
mkdir $stashdir
trap "rmdir --ignore-fail-on-non-empty $stashdir" 0
## pull?
cd $HOME/.profiles
.lib/fix-permissions $PROFILE
install -m 700 -t .git/hooks/ .lib/hooks/*
## Merge, replace, or stash & replace all files
## in the specified profile directory, except
## for .profiles-*, .git/, .git*, INSTALL and matching
## expressions in .profiles-skip . (TODO not yet tested)
## NOTE: .gitconfig will be replaced.
##
## If the target exists and is NOT a soft-link
## then if the target is a directory: rsync the dirs
## else if it is a normal file: stash the file and replace it
## else leave it alone.
##
cd $HOME
{ cd $prodir; command ls -A1; } |
if [ -f $prodir/.skip ]; then
command grep -v -f $prodir/.profiles-skip
else
command cat
fi |
while read node; do
# Never copy these over
case $node in
.gitconfig) : ;; # Yes, copy this one
.profiles-|.git*|INSTALL) continue;;
esac
# Replace softlinks,
# Merge directories,
# Stash and replace normal files
if [ -e "$HOME/$node" -a ! -L "$HOME/$node" ]; then
if [ -d "$HOME/$node" ]; then
# merge directories with rsync
command rsync -qrpcbt --backup-dir="$stashdir" \
"$prodir_rel/$node/." "$node"
continue
elif [ -f "$HOME/$node" ]; then
# stash
warn "Stashing $node"
command mv "$HOME/$node" "$stashdir/"
else
warn "Not replacing or stashing $node"
continue
fi
fi
# replace:
command ln -sf "$prodir_rel/$node"
done
exit 0
#!/bin/bash
${debug:+set -x}
fatal() { echo >&2 "$@"; exit 1; }
warn() { echo >&2 "$@"; }
## variable initialization and global checks
PATH="/usr/bin:/bin"
test -z "$HOME" || HOME=$(getent passwd `id -u`|cut -d: -f6)
test -z "$HOSTNAME" || HOSTNAME=$(hostname -s)
PROFILE="${1:-default}"
DATE=$(date +%F)
prodir="$HOME/.profiles/$PROFILE"
prodir_rel=".profiles/$PROFILE"
if [ ! -d "$prodir" ]; then
fatal "Unknown profile $PROFILE: $prodir not found"
fi
## Place to put files that should not be overwritten
stashdir="$HOME/.profiles/stash-$HOSTNAME-$DATE-$$"
mkdir $stashdir
trap "rmdir --ignore-fail-on-non-empty $stashdir" 0
## pull?
cd $HOME/.profiles
.lib/fix-permissions $PROFILE
install -m 700 -t .git/hooks/ .lib/hooks/*
## Merge, replace, or stash & replace all files
## in the specified profile directory, except
## for .profiles-*, .git/, .git*, INSTALL and matching
## expressions in .profiles-skip . (TODO not yet tested)
## NOTE: .gitconfig will be replaced.
##
## If the target exists and is NOT a soft-link
## then if the target is a directory: rsync the dirs
## else if it is a normal file: stash the file and replace it
## else leave it alone.
##
cd $HOME
{ cd $prodir; command ls -A1; } |
if [ -f $prodir/.skip ]; then
command grep -v -f $prodir/.profiles-skip
else
command cat
fi |
while read node; do
# Never copy these over
case $node in
.gitconfig) : ;; # Yes, copy this one
.profiles-|.git*|INSTALL) continue;;
esac
# Replace softlinks,
# Merge directories,
# Stash and replace normal files
if [ -e "$HOME/$node" -a ! -L "$HOME/$node" ]; then
if [ -d "$HOME/$node" ]; then
# merge directories with rsync
command rsync -qrpcbt --backup-dir="$stashdir" \
"$prodir_rel/$node/." "$node"
continue
elif [ -f "$HOME/$node" ]; then
# stash
warn "Stashing $node"
command mv "$HOME/$node" "$stashdir/"
else
warn "Not replacing or stashing $node"
continue
fi
fi
# replace:
command ln -sf "$prodir_rel/$node"
done
exit 0
.TH PROFILES 7 @VERSION@
.SH NAME
.B PROFILES
- A system for a distributed HOME environment for users
.SH SYNOPSIS
.B "profiles-setup [options]"
.PP
.B "profiles-use [options] [<profile-name>|default]"
.SH DESCRIPTION
.PP
The profiles system allows a user to set up, switch back and forth, and migrate
the files comprising their "HOME" environment. It relies on a some kind of distributed
version control system. On the initial setup, it fetches the user's desired "profiles"
repository, which contains one or more environments -- each in its own sub-directory --
comprising one or more files and directories. If no such repository exists and the user
so desires, the user's current $HOME environment will be installed as the "default" profile,
and the repository created. Locally, profiles are stored within the user's $HOME/.profiles
directory.
.PP
To switch or install a particular profile, the user executes the "profiles-use" command,
which will \fBreplace\fP the user's existing $HOME files and directories with soft-links
to the corresponding files in the desired profiles subdir. To prevent the idiocy of the
user from destroying or overwriting desired files, the current $HOME environment is first
backed up.
.PP
Users can override the behavior of how and which files are installed, per profile.
Within each profile, the .profiles directory contains several control files:
.TP 12
.B permissions
File permissions are specified in the form of <octal>:<path>
.TP
.B nolink
Directory entries which should be removed and re-created and file entries which should be copied instead of soft-linked. One entry per line.
.TP
In the above examples, the file path is always relative to the user's $HOME directory.
.PP
A global configuration files, \fB@CONFIG_FILE@\fP, can be used to supply
defaults for the repository and version control system implementation. The user
may provide or override such values using the \fBprofiles-setup\fP command and its prompts.
.SH FILES
.TP
@CONFIG_FILE@
contains global configuration parameters, such as the version control system and a template for the URI common to all (or most) users.
.TP
$HOME/.profiles
Where all profiles are stored. Each directory within represents a "profile". All files and directories under each profile are copied or re-linked into the user's $HOME directory. (The exception is any version-control meta-information and the .profiles control files and directory.)
.SH VERSION
@VERSION@ packaged on @BUILDDATE@
.SH AUTHOR
.TP 10
0.1.0
Otheus <otheus.shelling@uibk.ac.at>
.br
.sv 5
.bp
# RPM spec file for sushi
Summary: Profiles system to allow distributed, selectable HOME environments for the user
Name: profiles
Version: 0.1.0
Release: 2%{?dist}
License: Apache-2.0
Group: System Environment/Shells
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: bash
BuildArch: noarch
# do not change
%define Version %{version}-%{release}
%description
Profiles is a system to allow users to easily switch between one or more HOME environments
(all the files in the user's $HOME directory) and to store them in a source-code repository
such as git.
%prep
# Production version:
# tar xzf %{S:0}
# Development version:
mkdir -p %{name}-%{version}
cd %{name}-%{version}
cp %{_sourcedir}/%{name}-%{version}/* .
%build
cd %{name}-%{version}
sed -i \
-e 's^@CONFIG_FILE@^/etc/profiles_config^g' \
-e 's^@VERSION@^%{Version}^g' \
-e 's^@BUILDDATE@^'"$(date +%%d/%%b/%%Y)"'^g' \
*
%install
cd %{name}-%{version}
install -D -m 444 profiles_config.sample "$RPM_BUILD_ROOT"%{_datadir}/%{name}/profiles_config.sample
install -D -m 444 profiles.man "$RPM_BUILD_ROOT"%{_mandir}/man7/profiles.7
for f in setup use update; do
install -D -m 555 profiles-$f "$RPM_BUILD_ROOT"%{_bindir}/profiles-$f
install -D -m 444 profiles-$f.man "$RPM_BUILD_ROOT"%{_mandir}/man1/profiles-$f.1
done
/usr/lib/rpm/brp-compress
%clean
[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT"
%files
%attr(0444,root,root) %{_datadir}/%{name}/profiles_config.sample
%attr(0555,root,root) %{_bindir}/profiles-*
%doc %{_mandir}/man*/
%changelog
* Thu Jun 4 2014 Otheus <otheus.shelling@uibk.ac.at> 0.1.0
- Initial spec file
# Profiles global configuration
#
# VCS: Version control system. Currently only "git" is implemented.
VCS="git"
# URI: The URI pattern for the version control system to check out.
# The following strings are substituted
# @USER@ -- UNIX User name
# @USERID@ -- UNIX User ID
# @FULLNAME@ -- Determined from GECOS field
# @ORGANIZATION@ -- Determined from GECOS field
# @PROMPT@ -- Supplied by user during installation
# Examples:
URI="git@repo.your.org:@FULLNAME@/profiles.git"
URI="git@external_repository.git.org:@PROMPT@/my_profiles.git"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment