-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.sh
executable file
·188 lines (167 loc) · 4.49 KB
/
cli.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
# list of files to backup in home dir
FILES=".bashrc .tmux.conf .zshrc"
TODAY="$(date +%Y-%m-%d_%H-%M-%S)"
BACKUPDIR="$HOME/dotfiles_old/$TODAY"
DOTDIR="$HOME/dotfiles"
VIMDIR="$HOME/.config/nvim"
ZSHTHEMESDIR=$HOME/.oh-my-zsh/themes
# Checks if the command $1 exists
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# Move a file to the backup folder
# $1: Directory path of the file
# $2: File name
function createBackup() {
local ORIGIN="$1/$2"
if [ -e "$ORIGIN" ]; then
local DESTINATION="$BACKUPDIR/$2"
mkdir -p "$BACKUPDIR"
mv -f "$ORIGIN" "$DESTINATION"
fi
}
# Create a symbolic link
# $1: Origin (path + file name)
# $2: Destination (path + file name)
function createSymlink() {
local ORIGIN="$1"
local LINK="$2"
ln -s "$ORIGIN" "$LINK"
}
function installBasicSoftware() {
echo -e "\e[33mInstalling basic software\e[0m"
if command_exists dnf; then
sudo dnf install \
ag \
cheat \
curl \
fd-find \
gcc \
git-extras \
golang \
jq \
luarocks \
make \
meld \
neofetch \
neovim \
p7zip \
ripgrep \
saidar \
shfmt \
tmux \
trash-cli \
tree \
wget \
whois \
xclip \
xsel \
zsh
else
echo -e "\e[35m dnf not found. Aborting...\e[0m"
fi
}
function installRPMFusion() {
echo -e "\e[33mInstalling RPM Fusion Free\e[0m"
if ! dnf repolist | grep -q rpmfusion; then
sh -c 'sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm' &&
echo 'RPM Fusion Free ok'
echo -e "\e[33mInstalling REPM Fusion Non-Free\e[0m"
sh -c 'sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm' &&
echo 'RPM Fusion Free ok'
else
echo 'RPM Fusion already installed. Skipping...'
fi
}
function installOhMyZsh() {
echo -e "\e[33mInstalling ZSH plugin manager (OhMyZsh)...\e[0m"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" &&
echo 'ok'
}
function installDeno() {
echo -e "\e[33mInstalling Deno...\e[0m"
if command_exists deno; then
echo "Deno already installed. Skipping..."
else
sh -c "curl -fsSL https://deno.land/install.sh | sh"
fi
}
function installFlatpaks() {
sh "./scripts/flatpaks.sh"
}
function installNode() {
echo -e "\e[33mInstalling Node.js...\e[0m"
if command_exists node; then
echo "Node.js already installed. Skipping..."
else
sh -c "curl -fsSL https://rpm.nodesource.com/setup_current.x | sudo bash -"
sh -c 'sudo dnf install -y nodejs'
mkdir "${HOME}/.npm-packages/bin" -p
sh -c "npm config set prefix '$HOME/.npm-packages/'"
sh -c "npm i -g sloc neovim"
fi
}
function installDotfiles() {
# Move old files to backup folder
echo -e "\e[33mInstalling dotfiles...\e[0m"
echo "Moving old files to backup folder..."
for file in $FILES; do
createBackup "$HOME" "$file"
done
createBackup "$VIMDIR" "init.lua"
createBackup "$ZSHTHEMESDIR" "adesis.zsh-theme"
# Create sylinks
echo -e "Creating symlinks..."
mkdir -p "$VIMDIR"
createSymlink "$DOTDIR/nvim/init.lua" "$VIMDIR/init.lua"
createSymlink "$DOTDIR/sh/bash.bashrc" "$HOME/.bashrc"
createSymlink "$DOTDIR/sh/zsh.zshrc" "$HOME/.zshrc"
createSymlink "$DOTDIR/tmux/tmux.conf" "$HOME/.tmux.conf"
createSymlink "$DOTDIR/sh/adesis.zsh-theme" "$ZSHTHEMESDIR/adesis.zsh-theme"
echo -e "\e[32mDotfiles ok!\e[0m"
}
function main() {
clear -x
local options=(
"Install basic software (cli tools, go, and lua)"
"Install OhMyZsh"
"Install Dotfiles"
"Install RPM Fusion and RPM Fusion Free"
"Install Deno"
"Install Node.js"
"Install Flatpaks"
)
menu() {
echo "What do you want to do?"
for i in "${!options[@]}"; do
local label=" $((i + 1))) ${options[i]}"
[ "${choices[i]}" ] && echo -e "\e[46m\e[30m+$label\e[0m" || echo -e " $label"
done
[[ "$msg" ]] && echo "$msg"
:
}
prompt="Check an option (again to uncheck, ENTER when done): "
while menu && read -s -n 1 -rp "$prompt" num && [[ "$num" ]]; do
([[ "$num" != *[![:digit:]]* ]] &&
((num > 0 && num <= ${#options[@]}))) ||
{
msg="Invalid option: $num"
clear -x
continue
}
((num--))
msg=""
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
clear -x
done
echo ""
[ -n "${choices[0]}" ] && installBasicSoftware
[ -n "${choices[1]}" ] && installOhMyZsh
[ -n "${choices[2]}" ] && installDotfiles
[ -n "${choices[3]}" ] && installRPMFusion
[ -n "${choices[4]}" ] && installDeno
[ -n "${choices[5]}" ] && installNode
[ -n "${choices[6]}" ] && installFlatpaks
}
main