-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.shell_scripts
More file actions
executable file
·69 lines (63 loc) · 2.06 KB
/
Copy path.shell_scripts
File metadata and controls
executable file
·69 lines (63 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
function command_exists() {
command -v "$1" &> /dev/null
}
function lowercase() {
echo "$1" | tr '[:upper:]' '[:lower:]'
}
function y_n_dialog() {
# First parameter should be the default option (y or n)
if [ "$1" = "y" ]; then
echo -n "[Y/n] "
elif [ "$1" = "n" ]; then
echo -n "[y/N] "
else
echo -n "[y/n] "
fi
read -r ANSWER
ANSWER="$(lowercase "$ANSWER")"
if [ "$ANSWER" = "n" ] || { [ "$ANSWER" = "" ] && [ "$1" = "n" ]; }; then
# non-zero return value means error, and e. g. command false returns value 1
return 1
elif [ "$ANSWER" = "y" ] || { [ "$ANSWER" = "" ] && [ "$1" = "y" ]; }; then
# zero return value means successful
return 0
else
echo -n "Please answer 'y' or 'n': "
y_n_dialog "$1"
fi
}
function install_packages() {
if command_exists apt-get; then
sudo apt-get update
sudo apt-get -y install "$@"
elif command_exists dnf; then
sudo dnf install -y "$@"
elif command_exists zypper; then
sudo zypper refresh
sudo zypper install -y "$@"
elif command_exists pkg; then
pkg update
yes | pkg install "$@"
fi
}
function dotfiles() {
if ! command_exists envsubst; then
echo "Error: 'envsubst' command is not available."
echo "Please install 'envsubst' (often provided by package 'envsubst' or 'gettext-base') and try again."
exit 1
fi
DOTFILES_COMMAND_URL="https://raw.githubusercontent.com/samporapeli/dotfiles/main/.dotfiles-command.txt"
DOTFILES_COMMAND_PATH="$HOME/.dotfiles-command.txt"
if test -f "$DOTFILES_COMMAND_PATH"; then
DOTFILES_COMMAND=$(envsubst < "$DOTFILES_COMMAND_PATH")
elif command_exists "curl"; then
DOTFILES_COMMAND=$(curl -s "$DOTFILES_COMMAND_URL" | envsubst)
elif command_exists "wget"; then
DOTFILES_COMMAND=$(wget -qO - "$DOTFILES_COMMAND_URL" | envsubst)
else
echo "dotfiles-command.txt not available"
exit 1
fi
eval "$DOTFILES_COMMAND \"\$@\""
}