-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·105 lines (90 loc) · 2.46 KB
/
install.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
#!/bin/bash
# Small script to install dotfiles either
# directly as files or as symlinks.
config_folder="${HOME}/.config"
main () {
printf "Please select preferred installation method\n"
printf "Install dotfiles either [directly] as files or as [symlinks]: "
local input
read input
if [[ $input == "symlinks" ]]; then
confirm $input
install create_file
elif [[ $input == "directly" ]]; then
confirm $input
install create_symlink
else
printf "Invalid option entered, exiting...\n"
fi
}
confirm () {
printf "You have selected installing ${1}, confirm by entering [yes]: "
local confirm
read confirm
if [[ $confirm == "yes" ]]; then
return 0
else
printf "yes was not entered, exiting...\n"
exit 0
fi
}
install () {
printf "\nBeginning install\n\n"
backup_config
local nr_of_files=0
local nr_of_installed=0
for file in *; do
if [[ -d $file ]] && [[ $file != "oldconfig" ]]; then
let nr_of_files++
if $1 $file $config_folder; then
let nr_of_installed++
fi
printf "\n"
fi
done
printf "Finished installing $nr_of_installed out of $nr_of_files\n"
}
backup_config () {
printf "A backup of your current ~/.config will be saved in ./oldconfig\n"
if cp -r $config_folder ./oldconfig; then
printf "Backup successfully created\n\n"
else
printf "Backup failed, exiting...\n"
exit 1
fi
}
create_symlink () {
printf "Creating symlink for ${1} in ${2}\n"
if [[ -f "${2}/${1}" ]]; then
printf "Found already existing ${1} config\n"
printf "Overwrite it? [yes]/[no]: "
local overwrite
read overwrite
if [[ $overwrite == "yes" ]]; then
ln -sf $1 $2
printf "Symlink successfully created\n"
fi
else
ln -s $1 $2
printf "Symlink successfully created\n"
fi
return 0
}
create_file () {
printf "Creating config for ${1} in ${2}\n"
if [[ -f "${2}/${1}" ]]; then
printf "Found already existing ${1} config\n"
printf "Overwrite it? [yes]/[no]: "
local overwrite
read overwrite
if [[ $overwrite == "yes" ]]; then
cp -rf $1 $2
printf "File successfully created\n"
fi
else
cp -r $1 $2
printf "File successfully created\n"
fi
return 0
}
main "$@"