✨ 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:
+39
-19
@@ -1,17 +1,19 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
|
||||||
source ./utils.sh
|
source ./utils.sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
trap "printf \"\nOk, quitting beacuse you entered an exit signal. (SIGINT).\n\"; exit 1" SIGINT
|
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
|
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() {
|
function Apply_wallpapers() {
|
||||||
echo -n "Would you also like to apply the wallpapers folder? :3 [y/n] "
|
Ask "Would you also like to apply the wallpapers folder? :3"
|
||||||
read answer
|
|
||||||
printf "\n"
|
|
||||||
|
|
||||||
if [[ $answer =~ "y" ]]; then
|
if [[ $answer =~ "y" ]]; then
|
||||||
echo "Thanks for choosing! Please remember that I am not the author of the wallpapers!"
|
echo "Thanks for choosing! Please remember that I am not the author of the wallpapers!"
|
||||||
@@ -31,40 +33,57 @@ function Apply_wallpapers() {
|
|||||||
# Start #
|
# Start #
|
||||||
#########
|
#########
|
||||||
|
|
||||||
|
# makes bash force-load the script into memory to avoid issues when
|
||||||
|
# switching source to a tag
|
||||||
|
{
|
||||||
Print_header
|
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
|
sleep .5
|
||||||
|
|
||||||
echo "Welcome to the colorshell installation script!"
|
echo "Welcome to the colorshell installation script!"
|
||||||
|
|
||||||
# Warn user of possible problems that can happen
|
# 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" ]] && Ask "Do you want to start the shell installation?"
|
||||||
[[ ! $1 == "dots" ]] && read input || printf "\n"
|
|
||||||
|
|
||||||
if [[ $1 == "dots" ]] || [[ $input =~ "y" ]]; then
|
rm -rf $repo_directory 2> /dev/null
|
||||||
Send_log "Starting installation...\n"
|
Send_log "cloning repository in \`$repo_directory\`..."
|
||||||
|
git clone https://github.com/retrozinndev/colorshell.git $repo_directory
|
||||||
|
|
||||||
for dir in ${config_dirs[@]}; do
|
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
|
dest=$XDG_CONFIG_HOME/$dir
|
||||||
|
|
||||||
echo "-> Installing $dir in $dest"
|
echo "-> Installing $dir in $dest"
|
||||||
mkdir -p "$dest" # create parents
|
mkdir -p "$dest" # create parents
|
||||||
|
|
||||||
if [[ -f "./$dir" ]]; then
|
if [[ -f "$repo_directory/$dir" ]]; then
|
||||||
rm -r "$dest" # delete unused directory
|
rm -rf "$dest" # delete unused directory
|
||||||
cp -f ./$dir "$dest" # copy actual file
|
cp -f $repo_directory/$dir "$dest" # copy actual file
|
||||||
else
|
else
|
||||||
cp -rf ./$dir/* "$dest" # force-copy content
|
cp -rf $repo_directory/$dir/* "$dest" # force-copy content
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "-> Copying default user config"
|
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"
|
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
|
# Ask if user also wants to install default wallpapers
|
||||||
Apply_wallpapers
|
Apply_wallpapers
|
||||||
@@ -84,4 +103,5 @@ if [[ $1 == "dots" ]] || [[ $input =~ "y" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
printf "Ok, doing as you said! Bye bye!\n"
|
printf "Ok, doing as you said! Bye bye!\n"
|
||||||
exit 0
|
exit
|
||||||
|
}
|
||||||
|
|||||||
+54
-60
@@ -4,7 +4,8 @@ source ./utils.sh
|
|||||||
|
|
||||||
Check_current_dir() {
|
Check_current_dir() {
|
||||||
if ! [[ -f ./utils.sh ]]; then
|
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"
|
Send_log "Exiting"
|
||||||
sleep .5
|
sleep .5
|
||||||
exit 1
|
exit 1
|
||||||
@@ -22,7 +23,7 @@ Clean_local() {
|
|||||||
Send_log "info" "Cleaning wallpapers..."
|
Send_log "info" "Cleaning wallpapers..."
|
||||||
rm -rf ./wallpapers
|
rm -rf ./wallpapers
|
||||||
|
|
||||||
echo "Done cleaning."
|
Send_log "Done cleaning"
|
||||||
}
|
}
|
||||||
|
|
||||||
Update_local() {
|
Update_local() {
|
||||||
@@ -53,43 +54,42 @@ Update_local() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Update_remote() {
|
Update_remote() {
|
||||||
echo "Git status:"
|
git status
|
||||||
/bin/env git status
|
read -p "Single file/directory to add: " chosen
|
||||||
echo "Please type one of the dotfiles you want to push now(only one dir):"
|
if [[ -d $chosen ]] || [[ -f $chosen ]]; then
|
||||||
printf "directory/file: "
|
git add $chosen
|
||||||
read chosen_dir
|
Ask "Add more files/directories to queue?"
|
||||||
if [[ -d $chosen_dir ]] || [[ -f $chosen_dir ]]; then
|
if [[ $answer =~ y ]]; 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
|
|
||||||
Update_remote
|
Update_remote
|
||||||
else
|
return
|
||||||
commit_message=""
|
|
||||||
commit_description=""
|
|
||||||
push_changes=""
|
|
||||||
echo -en "(You can use emojis by typing its name between colons, e.g.: \":tada:\" for \"🎉\").\nCommit message: "
|
|
||||||
read commit_message
|
|
||||||
echo -n "Type commit description(leave blank if none): "
|
|
||||||
read commit_description
|
|
||||||
|
|
||||||
echo "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
|
|
||||||
|
|
||||||
if [[ $push_changes =~ "y" ]]; then
|
|
||||||
git push
|
|
||||||
echo "Done pushing!!"
|
|
||||||
else
|
|
||||||
Update_remote
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
commit_message=""
|
||||||
|
commit_description=""
|
||||||
|
push_changes=""
|
||||||
|
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
|
||||||
|
|
||||||
|
Send_log "Committing changes..."
|
||||||
|
[[ ! -z $commit_description ]] && \
|
||||||
|
git commit -m "$commit_message" -m "$commit_description" || \
|
||||||
|
git commit -m "$commit_message"
|
||||||
|
|
||||||
|
Send_log "Done!"
|
||||||
|
Ask "Push changes now? If not, you'll go back to the queue step"
|
||||||
|
|
||||||
|
if [[ $answer == y ]]; then
|
||||||
|
git push
|
||||||
|
Send_log "Done pushing!"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
Update_remote
|
||||||
else
|
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
|
Update_remote
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -99,38 +99,32 @@ Update_remote() {
|
|||||||
Check_current_dir
|
Check_current_dir
|
||||||
Print_header
|
Print_header
|
||||||
|
|
||||||
printf "\n"
|
Send_log warn "!! Running this script may override all data in the local repo with host files"
|
||||||
echo "!!WARNING!! Running this script may override all data in current repo with host configurations."
|
Send_log warn "This script is intended to be used only by the dotfiles owner\n"
|
||||||
echo "This script is intended to be used only by the dotfiles owner"
|
|
||||||
printf "\n"
|
|
||||||
|
|
||||||
echo "Please run this script in it's current directory to avoid issues"
|
Send_log "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 "Tip: Press ^C([Ctrl] + [C]) to stop script at any time\n"
|
||||||
|
|
||||||
printf "\n"
|
Ask "Update local repository with host configurations?"
|
||||||
|
if ! $answer == y; then
|
||||||
echo -n "Do you want to update local repository with host configurations? [y/n] "
|
|
||||||
read answer
|
|
||||||
if ! [[ $answer =~ y ]]; then
|
|
||||||
Send_log "Exiting"
|
Send_log "Exiting"
|
||||||
exit 1
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "\n"
|
printf '\n'
|
||||||
|
|
||||||
Clean_local
|
Clean_local
|
||||||
Update_local
|
Update_local
|
||||||
|
|
||||||
echo -n "Would you like to commit to remote? (You will be prompted for commits) [y/n] "
|
if command -v git; then
|
||||||
read answer
|
Ask "Would you like to commit to remote? (You will be prompted for commits)"
|
||||||
|
|
||||||
if [[ $answer =~ y ]]; then
|
if $answer =~ y; then
|
||||||
Update_remote
|
Update_remote
|
||||||
echo "Looks like it's done! Have a great day!"
|
echo "Looks like it's done! Have a great day!"
|
||||||
else
|
else
|
||||||
echo "Ok, work's finished here! Have a great day!"
|
echo "Ok, work's finished here! Have a great day!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
git status
|
||||||
fi
|
fi
|
||||||
|
|
||||||
env git status
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# This script contains useful functions to be used
|
# 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)
|
# Made by retrozinndev (João Dias)
|
||||||
# Licensed under the MIT License
|
# Licensed under the MIT License
|
||||||
@@ -23,6 +23,11 @@ config_dirs=(
|
|||||||
"ags"
|
"ags"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# -------------
|
||||||
|
# The repository's api url
|
||||||
|
# -------------
|
||||||
|
repo_api_url=https://api.github.com/repos/retrozinndev/colorshell
|
||||||
|
|
||||||
# -------------
|
# -------------
|
||||||
# Sends stdout log with type and message provided
|
# Sends stdout log with type and message provided
|
||||||
# in parameters.
|
# in parameters.
|
||||||
@@ -30,29 +35,22 @@ config_dirs=(
|
|||||||
# param $2 log message
|
# param $2 log message
|
||||||
# -------------
|
# -------------
|
||||||
function Send_log() {
|
function Send_log() {
|
||||||
log_message=$2
|
log_message=`[[ -z $2 ]] && echo $1 || echo $2`
|
||||||
|
color="\e[34m"
|
||||||
|
log_type="info"
|
||||||
|
|
||||||
case ${1,,} in
|
case "${1,,}" in
|
||||||
"^warn(ing)$")
|
warn)
|
||||||
color="\e[33m"
|
color="\e[33m"
|
||||||
log_type="warning"
|
log_type="warning"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"^err(or)$")
|
err)
|
||||||
color="\e[31m"
|
color="\e[31m"
|
||||||
log_type="error"
|
log_type="error"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
|
||||||
color="\e[34m"
|
|
||||||
log_type="info"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ -z $2 ]]; then
|
|
||||||
log_message=$1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "${color}[$log_type]\e[0m $log_message"
|
echo -e "${color}[$log_type]\e[0m $log_message"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,3 +65,23 @@ function Print_header() {
|
|||||||
echo "#############################"
|
echo "#############################"
|
||||||
printf "\n"
|
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