Skip to content

Commit

Permalink
squash: Improved project and added features
Browse files Browse the repository at this point in the history
03b18b7: Improved openvm to start and connect to specified vm
9dfbaa7: Changed available extension installations from manual to dnf
2e20415: Improved project structure and Updated desktop icons
bbbb2b5: Refactored to conform to shellcheck rules
12c163b: Refactored sync-obsidian to conform to Shellcheck
d54c9f4: Added an 'already strated' check to sync-obsidian
a053349: Refactored pandock to conform to Shellcheck
4189507: Refactored openvm to conform to Shellcheck
e80b4aa: Refactored update-btop to conform to Shellcheck
1effd92: Refactored update-docker-compose to conform to Shellcheck
9b12829: Added code alias launch nvim in vim.sh
4dc8270: Refactored post block of fedora.dist.cfg to conform to Shellcheck
662a18c: Refactored post-install to conform to Shellcheck
e6c128b: Refactored files paths to match the destinations
ca6bc97: Added configuration script template and small changes
ff5ff3f: Updated Gnome extension install
  • Loading branch information
lilian-pouliquen committed Aug 3, 2024
1 parent 27f5c7c commit f9ffe1c
Show file tree
Hide file tree
Showing 38 changed files with 778 additions and 1,617 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ The project is used on my laptop. Here are its specifications:
install-fedora/
|
+-- files/ => Files used throughout the post installation process
| +-- confs/ => Confs used throughout the post installation process
| +-- images/ => Images used throughout the post installation process
| +-- scripts/ => Scripts used throughout the post installation process
|
+-- .gitignore => Files ignored from Git
+-- fedora.dist.cfg => Fedora workstation kickstart
Expand Down
164 changes: 164 additions & 0 deletions configure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Configuration script template

## Table of content

[TOC]

## 1. Introduction

The file `install-configs.sh` is a configuration script which will do all your configuration for you. The one in this directory is a template that you can edit to match your needs. This document will explain how it works.

## 2. File structure

```text
configure/
|
+-- service-1/ : configuration files for service-1
+-- service-2/ : configuration files for service-2
+-- ...
+-- service-n/ : configuration files for service-n
|
+-- install-configs.sh : configuration script
+-- README.md : documentation
```

## 3. Getting start with the script

1. Start by adding the needed directories to the parent folder of `install-configs.sh`. One for each service or app you want to configure as in the [file structure section](#file-structure). Do not forget to add the configuration files to them.
1. In the script `install-configs.sh`, for each service or app you want to configure, do the following:
1. Add a configuration function in the `CONFIGURE APP` section:
1. Note: The script uses pushd to move within the directory matching the service name (here: `my-service`) to execute the function.

```bash
#
# APP CONFIGURATION FUNCTIONS
# Add your configuration functions here
#

# configuration function for the service 'my-service'
configure-my-service() {
# Do what you want here
# The current path will be /path/to/the/script/parent/dir/my-service/
}
```

1. Add an option entry in the handling option case statement according to your case:

```bash
#
# BEGIN
#
# [...]
# Handle options
for opt in "$@"
do
case "${opt}" in
"--help")
# [...]
;;
"--all")
# [...]
;;
# Add your options here
"--my-service")
# Choose and adapt one of the next options:
# Configure my-service without checking for a specific path
configure-app "my-service" false
# OR
# Configure my-service after checking for a specific path
my_service_dir="/path/to/required/directory/"
configure-app "my-service" true "${my_service_dir}"
# OR
# Configure my-service that requires sudo
try-sudo "my-service" && configure-app "my-service" false
# OR
# Configure my-service that requires sudo and checks for a specific
my_service_dir="/path/to/required/directory/"
try-sudo "my-service" && configure-app "my-service" true "${my_service_dir}"
;;
*)
# [...]
;;
esac
done
```

1. Add you new option in the command called by `--all` option:

```bash
#
# BEGIN
#
# [...]
# Handle options
for opt in "$@"
do
case "${opt}" in
"--help")
# [...]
;;
"--all")
# Configure all only if --all is the only argument
if [ $# -eq 1 ]
then
bash "${script_path}" --my-service # <= Add your option here
else
echo "There are other arguments than --all. Skipping --all argument"
fi
;;
# Add your options here
"--my-service")
# [your choice from the previous step]
;;
*)
# [...]
;;
esac
done
```

1. Add a description in the `print-help` function for your new option:

```bash
#
# FUNCTIONS
#
print-help() {
# [...]
echo "[AVAILABLE OPTIONS]"
# [...]
# Add your option descriptions here
echo " --my-service : Configure my-service"
# [...]
}
```

## 4. Use the script

Once all the setup is done, you can use the script as follows, assuming the file structure to be the one discribed in the [file structure section](#file-structure):

```bash
# To configure only service-1
bash "/path/to/the/script/install-configs.sh" --service-1
# To congigure several services
bash "/path/to/the/script/install-configs.sh" --service-1 --service-2 ...
# To congigure all sercices
bash "/path/to/the/script/install-configs.sh" --all
```

## 5. Author

* Lilian POULIQUEN: [Github – @lilian-pouliquen](https://github.com/lilian-pouliquen)
160 changes: 160 additions & 0 deletions configure/install-configs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/bin/bash

#
# COLORS
#
green="\e[0;92m"
red="\e[0;91m"
reset="\e[0m"

#
# VARIABLES
#
script_path="$(realpath -- "$0")"
script_parent_dir="$(dirname -- "${script_path}")"
log_file="${script_path}.log"

#
# FUNCTIONS
#
print-help() {
echo ""
echo -e "${green}[ USAGE ]${reset}"
echo " $0 [options]"
echo ""
echo -e "${green}[ AVAILABLE OPTIONS ]${reset}"
echo " --help : Print the current help message"
echo " --all : Configure all available apps"
# Add your option descriptions here
echo ""
echo -e "${green}[EXIT CODES]${reset}"
echo " 0 : Success"
echo " 1 : Unknown argument"
echo " 2 : Error while pushd to or popd from the script parent directory"
echo " 3 : Error while popd from an app directory"
echo ""
}

try-pushd() {
local app="$1"
local return_code=0
if ! pushd "${app}" &>> "${log_file}"
then
echo -e "${red}FAILURE${reset} ]"
echo "${red}Could not move to ${app}'s directory.${reset} Skipping." | tee --append "${log_file}" >&2
return_code=1
fi

return $return_code
}

try-sudo() {
local app="$1"
local return_code=0
if ! sudo --validate
then
echo -e "${red}Could not use sudo to configure ${app}.${reset} Skipping." | tee --append "${log_file}" >&2
return_code=1
fi

return $return_code
}

check-directory() {
local app="$1"
local path="$2"
local return_code=0
if ! [ -d "${path}" ]
then
echo -e "${red}FAILURE${reset} ]"
echo -e "${red}Could not find ${path}.${reset} Try launching ${app} once first." | tee --append "${log_file}" >&2
return_code=1
fi

return $return_code
}

configure-app() {
local app="$1"
local check_dir="$2"
local dir_to_check="$3"
local app_uppercase
app_uppercase="$(echo "${app}" | tr "[:lower:]" "[:upper:]")"

{
echo ""
echo "--------------------"
echo ""
echo "[ ${app_uppercase} ]"
} >> "${log_file}"
echo -n "[ ${app_uppercase}... "

if try-pushd "${app}"
then
if ! ${check_dir} || check-directory "${app}" "${dir_to_check}"
then
"configure-${app}"
if popd &>> "${log_file}"
then
echo -e "${green}OK${reset} ]"
else
echo -e "${red}FATAL ERROR${reset} ]"
exit 3
fi
fi
fi
}

#
# APP CONFIGURATION FUNCTIONS
# Add your configuration functions here
#

#
# BEGIN
#

# Testing if could move to the script directory
if ! pushd "${script_parent_dir}" &> "${log_file}"
then
echo -e "${red}Could not move to ${script_parent_dir}. Exiting.${reset}" | tee --append "${log_file}" >&2
exit 2
fi

# Handle options
for opt in "$@"
do
case "${opt}" in
"--help")
print-help
exit 0
;;

"--all")
# Configure all only if --all is the only argument
if [ $# -eq 1 ]
then
bash "${script_path}" # <= Add your option here
else
echo "There are other arguments than --all. Skipping --all argument"
fi
;;
# Add your options here
*)
echo -e "${red}Unknown argument : ${opt}${reset}" >&2
exit 1
;;
esac
done

#
# END
#
if ! popd &>> "${log_file}"
then
echo -e "${red}Could not leave ${script_parent_dir}. Exiting.${reset}" | tee --append "${log_file}" >&2
exit 2
else
exit 0
fi

Loading

0 comments on commit f9ffe1c

Please sign in to comment.