Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Putting in place the install script #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 50_vim
143 changes: 143 additions & 0 deletions dotmgr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env bash


[[ "$1" == "source" ]] || \

echo 'DotManager - Ali "Ashkan" Dorostkar'

if [[ "$1" == "-h" || "$1" == "--help" ]];
then
cat <<HELP

Usage: $(basename "$0")

See the README for documentation.
https://github.com/ashkan2200/dotmgr

HELP
exit;
fi

###########################################
# GENERAL PURPOSE EXPORTED VARS / FUNCTIONS
###########################################

# Test if the dotmgr script is currently
function is_dotmgr_running() {
[[ "$DOTMGR_SCRIPT_RUNNING" ]] || return 1
}

# Test if this script was run via the "dotmgr" bin script (vs. via curl/wget)
function is_dotmgr_bin() {
[[ "$(basename $0 2>/dev/null)" == dotmgr ]] || return 1
}


# Where the magic happens.
# if not already set, set it as the folowing
export DOTMGR=${DOTMGR:-~/.dotmgr}
DOTMGR_GH_BRANCH=${DOTMGR_GH_BRANCH:-master}
DOTMGR_GH_USER=${DOTMGR_GH_USER:-ashkan2200}
BACKUP_DIR="$HOME/.cache/dotmgr/backups/$(date "+%Y_%m_%d-%H_%M_%S")/"
CACHE_DIR="$HOME/.cache/dotmgr/cache/"
# TODO: Need to update this to point into .local/share/...
MAN_DIR="$HOME/.cache/dotmgr/man/"
# TODO: should we pass and install directory to .local/ or some other place if an script needs it?
DOTMGR_SCRIPT_RUNNING=1

function cleanup {
unset DOTMGR_SCRIPT_RUNNING
unset prompt_delay
}
trap cleanup EXIT

SUDO=$(type -P sudo)
if [[ "$SUDO" == "" ]]
then
e_error "No sudo found, trying to continue without it"
fi


# Set the prompt delay to be longer for the very first run.
export prompt_delay=5 is_dotmgr_bin || prompt_delay=15

# Ensure that we can actually, like, compile anything.
if [[ ! "$(type -P gcc)" ]] && is_osx; then
e_error "XCode or the Command Line Tools for XCode must be installed first."
exit 1
fi

# If Git is not installed, install it (Ubuntu only, since Git comes standard
# with recent XCode or CLT)
if [[ ! "$(type -P git)" ]] && is_ubuntu; then
e_header "Installing Git"
${SUDO} apt-get -qq install git-core &> /dev/null
fi

# If Git isn't installed by now, something exploded. We gots to quit!
if [[ ! "$(type -P git)" ]]; then
e_error "Git should be installed. It isn't. Aborting."
exit 1
fi

# # Initialize.
# if [[ ! -d $DOTMGR ]]; then
# # Dotmgr directory doesn't exist? Clone it!
# e_header "Downloading dotmgr"
# git clone --branch ${DOTMGR_GH_BRANCH} --recursive \
# git://github.com/${DOTMGR_GH_USER}/dotmgr.git $DOTMGR
# cd $DOTMGR
# elif [[ "$1" != "restart" ]]; then
# # Make sure we have the latest files.
# e_header "Updating dotmgr"
# cd $DOTMGR
# prev_head="$(git rev-parse HEAD)"
# git pull
# git submodule update --init --recursive --quiet
# if [[ "$(git rev-parse HEAD)" != "$prev_head" ]]; then
# if is_dotmgr_bin; then
# e_header "Changes detected, restarting script"
# exec "$0" restart
# else
# e_header "Changes detected, please re-run script"
# exit
# fi
# fi
# fi



# Source shared folder, everything that is needed for this
# script and will be sourced in every shell after setups
for f in ./shared/*
do
echo "sourcing $f"
source $f
done

# Get every folder that has install.sh in it under current directory
# this automatically omits any folder that this script has to be aware of
modules=$(find . -mindepth 2 -maxdepth 2 -name "install.sh" -printf "%h\n")
if [ "$modules" == "" ]; then
e_error "No module to process"
exit 0
fi

# make the pattern to auto select most appropriate submodules
oses=($(get_os 1))
ptrn="(^[^a-z]("
for os in "${oses[@]}"; do
ptrn="${ptrn}$os|"
done
ptrn="${ptrn::-1})($|[^a-z])"


# Where to place the install cache
dotfile_cachedir=$HOME/.cache/dotmgr/install_cache.txt
# folders=($(filter_files $modules $ptrn $dotfile_cachedir $prompt_delay))
folders=($(filter_files "$modules" "$ptrn" "./cache.txt" "$prompt_delay"))
for d in "${folders[@]}"; do
e_arrow "Processing $d"
$d/install.sh --cache-prefix ${CACHE_DIR} --backup-prefix ${BACKUP_DIR}
--man-prefix ${MAN_DIR}
done
71 changes: 71 additions & 0 deletions template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

# Write the correct path for these variable in order to make
# default paths
__INSTALL_PREFIX=/path/to/install/root
__CACHE_PREFIX=/path/to/cache/root
__BACKUP_PREFIX=/path/to/backup/root
__MAN_PREFIX=/path/to/man/root

help(){
cat<<HELP
Usage: $(basename $0) [option]

Options:
-p/--prefix : set prefix directory for install, cache and backup folder
-i/--install-prefix: set prefix directory for install folder
-c/--cache-prefix: set prefix directory for cache folder
-b/--backup-prefix: set prefix directory for backup folder
-m/--man-prefix: set prefix directory for backup folder
HELP
}

process_commands() {
# Process options and save positional target
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-p|--prefix)
__INSTALL_PREFIX=$2
__CACHE_PREFIX=$2
__BACKUP_PREFIX=$2
__MAN_PREFIX=$2
shift 2 # past argument
;;
-i|--install)
__INSTALL_PREFIX=$2
shift 2 # past argument
;;
-c|--cache)
__CACHE_PREFIX=$2
shift 2 # past argument
;;
-b|--backup)
__BACKUP_PREFIX=$2
shift 2 # past argument
;;
-m|--man)
__MAN_PREFIX=$2
shift 2 # past argument
;;
*) # unknown option
echo "Unknown option '"$1"'" 1>&2
help
exit 1
;;
esac
done
}

# This is called by the dotfiles script
install() {
process_commands $@
# check if the paths are non empty (if it is necessary
# for the installation

}

if [ "$1" != "src" ]; then
install $@
fi