Repository navigation
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·74 lines (59 loc) · 2.04 KB
/
Copy pathinit.sh
File metadata and controls
executable file
·74 lines (59 loc) · 2.04 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
69
70
71
72
73
74
#!/bin/sh
# Snippet from Tanktalus at stackoverflow.com
me=`basename "$0"`
# End of snippet
initialize () {
echo "$me: Directory to use for storing data:"
echo "$me: Recommended: $HOME/.splan/data/ [type RETURN to select this]"
echo "$me: Do not include variables such as \$HOME, instead use full path, and include a forward slash at the end."
read directory
[ "$directory" = "" ] && directory=$HOME/.splan/data/ && echo "$me: Chose recommened directory!";
if [ -d $directory ]
then
if [[ $(ls -A $directory) ]]
then
echo "$me: Data directory is not an empty directory!"
echo "$me: Please choose another directory or empty the one chosen!"
echo "$me: Failure initializing splan!"
exit 1
else
cp res/splan-default.conf $HOME/.splan/splan.conf && echo "$me: Initialized at $HOME/.splan"
echo "datadir=$directory" >> $HOME/.splan/splan.conf && echo "$me: Successfully written configuration!" && exit 0
fi
else
cp res/splan-default.conf $HOME/.splan/splan.conf && echo "$me: Initialized at $HOME/.splan"
echo "datadir=$directory" >> $HOME/.splan/splan.conf && echo "$me: Successfully written configuration!"
printf "$me: Creating new data directory..."
mkdir -p $directory && printf " done!" && exit 0 || echo "$me: Failed creating directory!" && exit 1
fi
}
if [ -d $HOME/.splan/ ] && [ -e $HOME/.splan/splan.conf ]
then
echo "$me: Configuration already exists."
echo "$me: Do you want to reinitialize[y/n]?"
read reinitialize
case $reinitialize in
"y")
initialize
;;
"n")
echo "$me: Then what are you doing with this script? (In case you don't know, you're running init.sh.)"
exit 0
;;
"k")
echo "$me: Bayyak k! (For those who don't understand, your answer is not valid, use only 'y' or 'n' and not k.)"
exit 2
;;
*)
echo "$me: Invalid answer! Please use 'y' or 'n.' Exiting because of you! :D"
exit 2
;;
esac
else
if [ -d $HOME/.splan/ ]
then
initialize
else
mkdir -p $HOME/.splan/ && initialize
fi
fi