✨ feat(install, update-repo): allow standalone installation, improvements
no need to clone repository to run the script anymoregit add install.sh update-repo.sh utils.sh
This commit is contained in:
+38
-18
@@ -1,17 +1,19 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
source ./utils.sh
|
||||
|
||||
set -e
|
||||
|
||||
trap "printf \"\nOk, quitting beacuse you entered an exit signal. (SIGINT).\n\"; exit 1" SIGINT
|
||||
trap "printf \"\nOh noo!! Some application just killed the script!\"; exit 2" SIGTERM
|
||||
|
||||
XDG_CONFIG_HOME=$(sh -c '[[ ! -z "$XDG_CONFIG_HOME" ]] && echo "$XDG_CONFIG_HOME" || echo "$HOME/.config"')
|
||||
XDG_CONFIG_HOME=`[[ ! -z "$XDG_CONFIG_HOME" ]] && echo $XDG_CONFIG_HOME || echo $HOME/.config`
|
||||
|
||||
skip_prompts=`[[ "$@" =~ "\-y" ]] && echo -n true`
|
||||
is_standalone=`git remove -v && remote=\`git remote -v | head -n 1 | awk '{print $2}' | sed 's/.git$//g'\` || echo -n`
|
||||
repo_directory=`[[ $is_standalone ]] && echo "/tmp/colorshell-git" || echo "."`
|
||||
|
||||
function Apply_wallpapers() {
|
||||
echo -n "Would you also like to apply the wallpapers folder? :3 [y/n] "
|
||||
read answer
|
||||
printf "\n"
|
||||
Ask "Would you also like to apply the wallpapers folder? :3"
|
||||
|
||||
if [[ $answer =~ "y" ]]; then
|
||||
echo "Thanks for choosing! Please remember that I am not the author of the wallpapers!"
|
||||
@@ -31,20 +33,37 @@ function Apply_wallpapers() {
|
||||
# Start #
|
||||
#########
|
||||
|
||||
# makes bash force-load the script into memory to avoid issues when
|
||||
# switching source to a tag
|
||||
{
|
||||
Print_header
|
||||
echo -e "colorshell is a project made by retrozinndev. source: https://github.com/retrozinndev/colorshell\n"
|
||||
echo -e "Colorshell is a project made by retrozinndev.\nhttps://github.com/retrozinndev/colorshell\n"
|
||||
sleep .5
|
||||
|
||||
echo "Welcome to the colorshell installation script!"
|
||||
|
||||
# Warn user of possible problems that can happen
|
||||
echo "!!!WARNING!!! By running this script, you assume total responsability for any issues that may occur with your filesystem"
|
||||
Send_log warn "!! By running this script, you assume total responsability for any issues that may occur with your filesystem"
|
||||
|
||||
echo -n "Do you want to start the shell installation? [y/n] "
|
||||
[[ ! $1 == "dots" ]] && read input || printf "\n"
|
||||
[[ ! $1 == "dots" ]] && Ask "Do you want to start the shell installation?"
|
||||
|
||||
if [[ $1 == "dots" ]] || [[ $input =~ "y" ]]; then
|
||||
Send_log "Starting installation...\n"
|
||||
rm -rf $repo_directory 2> /dev/null
|
||||
Send_log "cloning repository in \`$repo_directory\`..."
|
||||
git clone https://github.com/retrozinndev/colorshell.git $repo_directory
|
||||
|
||||
if [[ $1 == "dots" ]] || [[ $answer == "y" ]]; then
|
||||
Ask "Nice! Use the stable version instead of the unstable(git)?"
|
||||
|
||||
if [[ ! $1 == "dots" ]] && [[ $answer == "y" ]]; then
|
||||
Send_log "fetching latest release from colorshell repository"
|
||||
latest_tag=`curl -s "$repo_api_url/releases" | jq -r '. | select(.[].prerelease == false) | .[0].tag_name'`
|
||||
|
||||
Send_log "done fetching"
|
||||
Send_log "checking out latest non-pre-release version: $latest_tag"
|
||||
git -C $repo_directory checkout $latest_tag 1> /dev/null
|
||||
fi
|
||||
|
||||
Send_log "starting colorshell installation"
|
||||
|
||||
for dir in ${config_dirs[@]}; do
|
||||
dest=$XDG_CONFIG_HOME/$dir
|
||||
@@ -52,19 +71,19 @@ if [[ $1 == "dots" ]] || [[ $input =~ "y" ]]; then
|
||||
echo "-> Installing $dir in $dest"
|
||||
mkdir -p "$dest" # create parents
|
||||
|
||||
if [[ -f "./$dir" ]]; then
|
||||
rm -r "$dest" # delete unused directory
|
||||
cp -f ./$dir "$dest" # copy actual file
|
||||
if [[ -f "$repo_directory/$dir" ]]; then
|
||||
rm -rf "$dest" # delete unused directory
|
||||
cp -f $repo_directory/$dir "$dest" # copy actual file
|
||||
else
|
||||
cp -rf ./$dir/* "$dest" # force-copy content
|
||||
cp -rf $repo_directory/$dir/* "$dest" # force-copy content
|
||||
fi
|
||||
done
|
||||
|
||||
echo "-> Copying default user config"
|
||||
cp -rf ./hypr/user $XDG_CONFIG_HOME/hypr
|
||||
cp -rf $repo_directory/hypr/user $XDG_CONFIG_HOME/hypr
|
||||
|
||||
echo "-> Copying default hyprpaper.conf"
|
||||
cp -f ./hypr/hyprpaper.conf $XDG_CONFIG_HOME/hypr
|
||||
cp -f $repo_directory/hypr/hyprpaper.conf $XDG_CONFIG_HOME/hypr
|
||||
|
||||
# Ask if user also wants to install default wallpapers
|
||||
Apply_wallpapers
|
||||
@@ -84,4 +103,5 @@ if [[ $1 == "dots" ]] || [[ $input =~ "y" ]]; then
|
||||
fi
|
||||
|
||||
printf "Ok, doing as you said! Bye bye!\n"
|
||||
exit 0
|
||||
exit
|
||||
}
|
||||
|
||||
+36
-42
@@ -4,7 +4,8 @@ source ./utils.sh
|
||||
|
||||
Check_current_dir() {
|
||||
if ! [[ -f ./utils.sh ]]; then
|
||||
Send_log warn "Looks like you're not in the repository directory!\nPlease run this script from the repo directory to avoid problems."
|
||||
Send_log warn "Looks like you're not in the repository directory! \
|
||||
Please run this script from the repo directory to avoid problems."
|
||||
Send_log "Exiting"
|
||||
sleep .5
|
||||
exit 1
|
||||
@@ -22,7 +23,7 @@ Clean_local() {
|
||||
Send_log "info" "Cleaning wallpapers..."
|
||||
rm -rf ./wallpapers
|
||||
|
||||
echo "Done cleaning."
|
||||
Send_log "Done cleaning"
|
||||
}
|
||||
|
||||
Update_local() {
|
||||
@@ -53,43 +54,42 @@ Update_local() {
|
||||
}
|
||||
|
||||
Update_remote() {
|
||||
echo "Git status:"
|
||||
/bin/env git status
|
||||
echo "Please type one of the dotfiles you want to push now(only one dir):"
|
||||
printf "directory/file: "
|
||||
read chosen_dir
|
||||
if [[ -d $chosen_dir ]] || [[ -f $chosen_dir ]]; then
|
||||
git add $chosen_dir
|
||||
echo -n "Would you like to add more dirs to queue? [y/n] "
|
||||
read add_more_dirs
|
||||
if [[ $add_more_dirs =~ y ]]; then
|
||||
git status
|
||||
read -p "Single file/directory to add: " chosen
|
||||
if [[ -d $chosen ]] || [[ -f $chosen ]]; then
|
||||
git add $chosen
|
||||
Ask "Add more files/directories to queue?"
|
||||
if [[ $answer =~ y ]]; then
|
||||
Update_remote
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
commit_message=""
|
||||
commit_description=""
|
||||
push_changes=""
|
||||
echo -en "(You can use emojis by typing its name between colons, e.g.: \":tada:\" for \"🎉\").\nCommit message: "
|
||||
echo "You can use emojis by typing its name between colons, e.g.: \":tada:\" for \"🎉\""
|
||||
echo -n "Commit message: "
|
||||
read commit_message
|
||||
echo -n "Type commit description(leave blank if none): "
|
||||
read commit_description
|
||||
|
||||
echo "Committing changes..."
|
||||
Send_log "Committing changes..."
|
||||
[[ ! -z $commit_description ]] && \
|
||||
git commit -m "$commit_message" -m "$commit_description" || \
|
||||
git commit -m "$commit_message"
|
||||
|
||||
echo -n "Done! Do you want to push? If not, you'll go back to file selection [y/n] "
|
||||
read push_changes
|
||||
Send_log "Done!"
|
||||
Ask "Push changes now? If not, you'll go back to the queue step"
|
||||
|
||||
if [[ $push_changes =~ "y" ]]; then
|
||||
if [[ $answer == y ]]; then
|
||||
git push
|
||||
echo "Done pushing!!"
|
||||
else
|
||||
Send_log "Done pushing!"
|
||||
return
|
||||
fi
|
||||
|
||||
Update_remote
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Looks like this directory does not exist! Try taking a look at the dir list."
|
||||
echo "Looks like this file/directory does not exist."
|
||||
Update_remote
|
||||
fi
|
||||
|
||||
@@ -99,38 +99,32 @@ Update_remote() {
|
||||
Check_current_dir
|
||||
Print_header
|
||||
|
||||
printf "\n"
|
||||
echo "!!WARNING!! Running this script may override all data in current repo with host configurations."
|
||||
echo "This script is intended to be used only by the dotfiles owner"
|
||||
printf "\n"
|
||||
Send_log warn "!! Running this script may override all data in the local repo with host files"
|
||||
Send_log warn "This script is intended to be used only by the dotfiles owner\n"
|
||||
|
||||
echo "Please run this script in it's current directory to avoid issues"
|
||||
echo "Tip: Press Ctrl + C to stop script at any time"
|
||||
Send_log "Please run this script in it's current directory to avoid issues"
|
||||
Send_log "Tip: Press ^C([Ctrl] + [C]) to stop script at any time\n"
|
||||
|
||||
printf "\n"
|
||||
|
||||
echo -n "Do you want to update local repository with host configurations? [y/n] "
|
||||
read answer
|
||||
if ! [[ $answer =~ y ]]; then
|
||||
Ask "Update local repository with host configurations?"
|
||||
if ! $answer == y; then
|
||||
Send_log "Exiting"
|
||||
exit 1
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf "\n"
|
||||
printf '\n'
|
||||
|
||||
Clean_local
|
||||
Update_local
|
||||
|
||||
echo -n "Would you like to commit to remote? (You will be prompted for commits) [y/n] "
|
||||
read answer
|
||||
if command -v git; then
|
||||
Ask "Would you like to commit to remote? (You will be prompted for commits)"
|
||||
|
||||
if [[ $answer =~ y ]]; then
|
||||
if $answer =~ y; then
|
||||
Update_remote
|
||||
echo "Looks like it's done! Have a great day!"
|
||||
else
|
||||
echo "Ok, work's finished here! Have a great day!"
|
||||
fi
|
||||
|
||||
env git status
|
||||
|
||||
exit 0
|
||||
git status
|
||||
fi
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script contains useful functions to be used
|
||||
# in other scripts from retrozindev's dotfiles.
|
||||
# in other scripts from colorshell.
|
||||
# ----------
|
||||
# Made by retrozinndev (João Dias)
|
||||
# Licensed under the MIT License
|
||||
@@ -23,6 +23,11 @@ config_dirs=(
|
||||
"ags"
|
||||
)
|
||||
|
||||
# -------------
|
||||
# The repository's api url
|
||||
# -------------
|
||||
repo_api_url=https://api.github.com/repos/retrozinndev/colorshell
|
||||
|
||||
# -------------
|
||||
# Sends stdout log with type and message provided
|
||||
# in parameters.
|
||||
@@ -30,29 +35,22 @@ config_dirs=(
|
||||
# param $2 log message
|
||||
# -------------
|
||||
function Send_log() {
|
||||
log_message=$2
|
||||
log_message=`[[ -z $2 ]] && echo $1 || echo $2`
|
||||
color="\e[34m"
|
||||
log_type="info"
|
||||
|
||||
case ${1,,} in
|
||||
"^warn(ing)$")
|
||||
case "${1,,}" in
|
||||
warn)
|
||||
color="\e[33m"
|
||||
log_type="warning"
|
||||
;;
|
||||
|
||||
"^err(or)$")
|
||||
err)
|
||||
color="\e[31m"
|
||||
log_type="error"
|
||||
;;
|
||||
|
||||
*)
|
||||
color="\e[34m"
|
||||
log_type="info"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -z $2 ]]; then
|
||||
log_message=$1
|
||||
fi
|
||||
|
||||
echo -e "${color}[$log_type]\e[0m $log_message"
|
||||
}
|
||||
|
||||
@@ -67,3 +65,23 @@ function Print_header() {
|
||||
echo "#############################"
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
# -------------
|
||||
# Ask a yes/no question to user
|
||||
# Input answer is exported as $answer
|
||||
# -------------
|
||||
function Ask() {
|
||||
read -n 1 -p "$1 [y/n] " r
|
||||
printf '\n'
|
||||
export answer=$r
|
||||
}
|
||||
|
||||
# -------------
|
||||
# Ask a yes/no question to user
|
||||
# Input answer is exported as $answer
|
||||
# -------------
|
||||
function Choose() {
|
||||
read -n 1 -p "$1 [y/n] " r
|
||||
printf '\n'
|
||||
export answer=$r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user