-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathsetup-arch.sh
executable file
·201 lines (180 loc) · 5.18 KB
/
setup-arch.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
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
clear
# -----------------------------------------------------
# Repository
# -----------------------------------------------------
repo="mylinuxforwork/dotfiles"
# -----------------------------------------------------
# Download Folder
# -----------------------------------------------------
download_folder="$HOME/.ml4w"
# Create download_folder if not exists
if [ ! -d $download_folder ]; then
mkdir -p $download_folder
fi
# Get latest tag from GitHub
get_latest_release() {
curl --silent "https://api.github.com/repos/$repo/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Get latest zip from GitHub
get_latest_zip() {
curl --silent "https://api.github.com/repos/$repo/releases/latest" | # Get latest release from GitHub api
grep '"zipball_url":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Check if package is installed
_isInstalled() {
package="$1"
check="$(sudo pacman -Qs --color always "${package}" | grep "local" | grep "${package} ")"
if [ -n "${check}" ]; then
echo 0 #'0' means 'true' in Bash
return #true
fi
echo 1 #'1' means 'false' in Bash
return #false
}
# Check if command exists
_checkCommandExists() {
package="$1"
if ! command -v $package >/dev/null; then
return 1
else
return 0
fi
}
# Install required packages
_installPackages() {
toInstall=()
for pkg; do
if [[ $(_isInstalled "${pkg}") == 0 ]]; then
echo ":: ${pkg} is already installed."
continue
fi
toInstall+=("${pkg}")
done
if [[ "${toInstall[@]}" == "" ]]; then
# echo "All pacman packages are already installed.";
return
fi
printf "Package not installed:\n%s\n" "${toInstall[@]}"
sudo pacman --noconfirm -S "${toInstall[@]}"
}
# install yay if needed
_installYay() {
_installPackages "base-devel"
SCRIPT=$(realpath "$0")
temp_path=$(dirname "$SCRIPT")
git clone https://aur.archlinux.org/yay.git $download_folder/yay
cd $download_folder/yay
makepkg -si
cd $temp_path
echo ":: yay has been installed successfully."
}
# Required packages for the installer
packages=(
"wget"
"unzip"
"gum"
"rsync"
"git"
)
latest_version=$(get_latest_release)
# Some colors
GREEN='\033[0;32m'
NONE='\033[0m'
# Header
echo -e "${GREEN}"
cat <<"EOF"
____ __ ____
/ _/__ ___ / /____ _/ / /__ ____
_/ // _ \(_-</ __/ _ `/ / / -_) __/
/___/_//_/___/\__/\_,_/_/_/\__/_/
EOF
echo "ML4W Dotfiles for Hyprland"
echo -e "${NONE}"
while true; do
read -p "DO YOU WANT TO START THE INSTALLATION NOW? (Yy/Nn): " yn
case $yn in
[Yy]*)
echo ":: Installation started."
echo
break
;;
[Nn]*)
echo ":: Installation canceled"
exit
break
;;
*)
echo ":: Please answer yes or no."
;;
esac
done
# Create Download folder if not exists
if [ ! -d $download_folder ]; then
mkdir -p $download_folder
echo ":: $download_folder folder created"
fi
# Remove existing download folder and zip files
if [ -f $download_folder/dotfiles-main.zip ]; then
rm $download_folder/dotfiles-main.zip
fi
if [ -f $download_folder/dotfiles-dev.zip ]; then
rm $download_folder/dotfiles-dev.zip
fi
if [ -f $download_folder/dotfiles.zip ]; then
rm $download_folder/dotfiles.zip
fi
if [ -d $download_folder/dotfiles ]; then
rm -rf $download_folder/dotfiles
fi
if [ -d $download_folder/dotfiles_temp ]; then
rm -rf $download_folder/dotfiles_temp
fi
if [ -d $download_folder/dotfiles-main ]; then
rm -rf $download_folder/dotfiles-main
fi
if [ -d $download_folder/dotfiles-dev ]; then
rm -rf $download_folder/dotfiles-dev
fi
# Synchronizing package databases
sudo pacman -Sy
echo
# Install required packages
echo ":: Checking that required packages are installed..."
_installPackages "${packages[@]}"
# Install yay if needed
if _checkCommandExists "yay"; then
echo ":: yay is already installed"
else
echo ":: The installer requires yay. yay will be installed now"
_installYay
fi
echo
# Select the dotfiles version
echo "Please choose between: "
echo "- ML4W Dotfiles for Hyprland $latest_version (latest stable release)"
echo "- ML4W Dotfiles for Hyprland Rolling Release (main branch including the latest commits)"
echo
version=$(gum choose "main-release" "rolling-release" "CANCEL")
if [ "$version" == "main-release" ]; then
echo ":: Installing Main Release"
yay -S --noconfirm ml4w-hyprland
elif [ "$version" == "rolling-release" ]; then
echo ":: Installing Rolling Release"
yay -S ml4w-hyprland-git
elif [ "$version" == "CANCEL" ]; then
echo ":: Setup canceled"
exit 130
else
echo ":: Setup canceled"
exit 130
fi
echo ":: Installation complete."
echo
# Start Spinner
gum spin --spinner dot --title "Starting setup now..." -- sleep 3
# Start setup
ml4w-hyprland-setup -p arch