Compare commits
4 commits
1fb4bcac81
...
d5ed3d209d
Author | SHA1 | Date | |
---|---|---|---|
d5ed3d209d | |||
dc95d17211 | |||
5cce7f0d3b | |||
7c5a944148 |
2 changed files with 112 additions and 22 deletions
23
README.md
23
README.md
|
@ -28,6 +28,12 @@ bootstrap file :
|
||||||
dotinstall uninstall bootstrap
|
dotinstall uninstall bootstrap
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or update with `update` even in git mode
|
||||||
|
|
||||||
|
```
|
||||||
|
dotinstall update bootstrap
|
||||||
|
```
|
||||||
|
|
||||||
## Boostrap file syntax
|
## Boostrap file syntax
|
||||||
|
|
||||||
`bootstrap` is a simple bash script sourced by `dotinstall`. The `bootstrap`
|
`bootstrap` is a simple bash script sourced by `dotinstall`. The `bootstrap`
|
||||||
|
@ -128,6 +134,23 @@ define_env "NOTMUCH_CONFIG" "~/.config/notmuch"
|
||||||
displayed.
|
displayed.
|
||||||
- `OVERWRITE_FILE` : do the same with file
|
- `OVERWRITE_FILE` : do the same with file
|
||||||
|
|
||||||
|
## Return code
|
||||||
|
|
||||||
|
This script return 0 if there is not error.
|
||||||
|
|
||||||
|
- **1** : no bootstrap specified.
|
||||||
|
- **2** : boostrap file not found
|
||||||
|
|
||||||
|
### Git relative error codes
|
||||||
|
|
||||||
|
- **20** : can't clone dotfile git repository.
|
||||||
|
- **24** : can't update dotfile git repository.
|
||||||
|
- **25** : local git repository does not exist.
|
||||||
|
|
||||||
|
### Script relative error code
|
||||||
|
|
||||||
|
- **128** : a binary checked by `chek_bin()` is not present
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
This software is licenced under the GNU-GPL 3 licence, you can found a copy of
|
This software is licenced under the GNU-GPL 3 licence, you can found a copy of
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
# Personnal Dotfiles install script
|
# Personnal Dotfiles install script
|
||||||
|
|
||||||
BIN_DIRECTORY="${HOME}/.local/bin/"
|
BIN_DIRECTORY="${HOME}/.local/bin"
|
||||||
LIB_DIRECTORY="${HOME}/.local/lib/"
|
LIB_DIRECTORY="${HOME}/.local/lib"
|
||||||
SYD_DIRECTORY="${HOME}/.config/systemd/user"
|
SYD_DIRECTORY="${HOME}/.config/systemd/user"
|
||||||
DOTREPO="${HOME}/.config/dotrepo/"
|
CACHE_DIR="${HOME}/.cache/dotinstall"
|
||||||
|
|
||||||
|
DOTREPO="${HOME}/.config/dotrepo"
|
||||||
ENV_FILE="${HOME}/.config/environment"
|
ENV_FILE="${HOME}/.config/environment"
|
||||||
|
|
||||||
# DEFAULT VALUES
|
# DEFAULT VALUES
|
||||||
|
@ -14,6 +16,7 @@ OVERWRITE_FILE=0
|
||||||
|
|
||||||
repository=""
|
repository=""
|
||||||
install=1
|
install=1
|
||||||
|
update=0
|
||||||
|
|
||||||
usage ()
|
usage ()
|
||||||
{
|
{
|
||||||
|
@ -147,7 +150,8 @@ private:create_symblink ()
|
||||||
private:clone_repository ()
|
private:clone_repository ()
|
||||||
{
|
{
|
||||||
# Clone a git repository and test if it has a bootstrap file
|
# Clone a git repository and test if it has a bootstrap file
|
||||||
# $* url
|
# $1 url
|
||||||
|
# $2 local repository
|
||||||
# return : local directory
|
# return : local directory
|
||||||
|
|
||||||
local ret
|
local ret
|
||||||
|
@ -155,6 +159,19 @@ private:clone_repository ()
|
||||||
[[ $? -ne 0 ]] && die "Can't clone_repository : $ret" 20 0
|
[[ $? -ne 0 ]] && die "Can't clone_repository : $ret" 20 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:update_repository ()
|
||||||
|
{
|
||||||
|
# Update a git repository
|
||||||
|
# $1 : local repository
|
||||||
|
|
||||||
|
[ ! -d "$1" ] && die "Git update : directory $1 does not exist" 25 0
|
||||||
|
local current_dir=$(pwd)
|
||||||
|
local ret
|
||||||
|
cd "$1"
|
||||||
|
ret=$(git pull 2>&1)
|
||||||
|
[[ $? -ne 0 ]] && die "Can't update repository : $ret" 24 0
|
||||||
|
}
|
||||||
|
|
||||||
process_dirs () {
|
process_dirs () {
|
||||||
|
|
||||||
# Process a directory than contains subdir, create symblink from each subdir
|
# Process a directory than contains subdir, create symblink from each subdir
|
||||||
|
@ -166,7 +183,7 @@ process_dirs () {
|
||||||
local dest="${repository}/$1"
|
local dest="${repository}/$1"
|
||||||
printf "\nProcess directory %s\n" "$1"
|
printf "\nProcess directory %s\n" "$1"
|
||||||
|
|
||||||
[ ! -d "$dest" ] && { error " -> source is not a directory"; return; }
|
[ ! -d "$dest" ] && { error " -> source is not a directory $dest"; return; }
|
||||||
[ ! -d "$dest" ] && { error " -> destination is not a directory"; return; }
|
[ ! -d "$dest" ] && { error " -> destination is not a directory"; return; }
|
||||||
|
|
||||||
while read d
|
while read d
|
||||||
|
@ -309,32 +326,82 @@ define_env ()
|
||||||
|
|
||||||
## create bin directory
|
## create bin directory
|
||||||
[ ! -d $BIN_DIRECTORY ] && mkdir -p $BIN_DIRECTORY || printf "bin exist\n"
|
[ ! -d $BIN_DIRECTORY ] && mkdir -p $BIN_DIRECTORY || printf "bin exist\n"
|
||||||
|
[ ! -d $CACHE_DIR ] && mkdir -p $CACHE_DIR || printf "cache exist\n"
|
||||||
|
# define mode : install, uninstall or update
|
||||||
|
case $1 in
|
||||||
|
"uninstall")
|
||||||
|
install=0
|
||||||
|
printf "Activate uninstall mode\n"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
# Test parameters : we need to know if it's a git repo or a file
|
"update")
|
||||||
[[ $1 == "uninstall" || $1 == "-u" ]] && { install=0; printf "Activate uninstall mode\n"; shift; }
|
update=1;
|
||||||
[ "$*" = "" ] && die "You must specify a bootstrap file" 10 1
|
printf "Activate update mode\n"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
[ "$*" = "" ] && die "You must specify a bootstrap file or repo" 1 1
|
||||||
|
|
||||||
if [[ $* =~ ^https://.*\.git$ || $* =~ ^ssh://.*\.git$ ]]
|
if [[ $* =~ ^https://.*\.git$ || $* =~ ^ssh://.*\.git$ ]]
|
||||||
then
|
then
|
||||||
bin_check "git"
|
check_bin "git"
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
localdir="${DOTREPO}/$(basename $* .git)"
|
localrepo="${DOTREPO}/$(basename $* .git)"
|
||||||
[ -d "$localdir" ] && die "destination folder for git repository already exist" 21 0
|
if [ $update -eq 1 ]
|
||||||
|
|
||||||
private:clone_repository "$*" "$localdir"
|
|
||||||
if [ -f "${localdir}/bootstrap" ]
|
|
||||||
then
|
then
|
||||||
$0 "${localdir}/bootstrap"
|
private:update_repository "$localrepo"
|
||||||
exit $?
|
|
||||||
else
|
else
|
||||||
die "Can't find a \`boostrap\` file in ${repo}" 22 0
|
if [ $install -eq 1 ]
|
||||||
|
then
|
||||||
|
private:clone_repository "$*" "$localrepo"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
bootstrap_file="${localrepo}/bootstrap"
|
||||||
else
|
else
|
||||||
[ ! -f "$*" ] && die "$* does not exist" 10 1
|
bootstrap_file="$*"
|
||||||
private:get_bootstrap_path "$*"
|
|
||||||
|
|
||||||
# Include bootstrap
|
|
||||||
source $*
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ ! -f "$bootstrap_file" ] && die "$bootstrap_file does not exist" 2 1
|
||||||
|
|
||||||
|
private:get_bootstrap_path "$bootstrap_file"
|
||||||
|
|
||||||
|
cache_file="${CACHE_DIR}/$(echo $repository | tr '/' '_')"
|
||||||
|
|
||||||
|
if [ $update -eq 1 ]
|
||||||
|
then
|
||||||
|
# Update mode
|
||||||
|
if [ -f "$cache_file" ]
|
||||||
|
then
|
||||||
|
if [ $(diff "$bootstrap_file" "$cache_file" > /dev/null; echo $?;) -eq 0 ]
|
||||||
|
then
|
||||||
|
printf "There is no difference between cached copy and the bootstrap file\n";
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
# Uninstall old files
|
||||||
|
install=0
|
||||||
|
source "$cache_file"
|
||||||
|
rm "$cache_file"
|
||||||
|
install=1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "Can't found cached copy of bootstrap file, just install"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp "$bootstrap_file" "$cache_file"
|
||||||
|
|
||||||
|
# Include bootstrap
|
||||||
|
source "$bootstrap_file"
|
||||||
|
|
||||||
|
# remove cached file and repo if uninstall
|
||||||
|
if [ $install -eq 0 ]
|
||||||
|
then
|
||||||
|
printf "\nRemove files for complete uninstall\n"
|
||||||
|
rm $cache_file
|
||||||
|
rm -rf $repository
|
||||||
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Reference in a new issue