~johanvandegriff/unix-shell-programming-revised-edition-programs

unix-shell-programming-revised-edition-programs/install/install_notes -rw-r--r-- 4.5 KiB
fc214385Johan Vandegriff added other old scripts, some newer ones too 2 years ago
                                                                                
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/sh
install=""
until [ -n "$install" ]
do
  echo "Do you want to install in your home directory,$HOME?(y/n)"
  read answer
  case $answer in
    y) install=$HOME;;
    n) echo "Where do you want to install?"
       read "install";;
    *) echo "Bad choice"
  esac
done

if [ ! -d "$install" ]
then
  echo "$install does not exist."
else
  if [ -d "$install/notes" ]
  then
    echo "$install/notes already exists."
  else

    for dir in  notes notes/bin notes/notes notes/trash
    do
      mkdir "$install/$dir"
    done

    echo '#!/usr/bin/env xdg-open

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=true
Icon[en_US]=gnome-panel-launcher
Name[en_US]=Notes
Exec=/home/johanv/programs/notes/run
Name=Notes
Icon=gnome-panel-launcher

' | sed "s/@@%/'/g" > "$install/notes/notes.desktop"
    chmod 755 "$install/notes/notes.desktop"

    echo '#!/bin/sh
location="$1"
tmp="$2"

echo "Enter the number:"
read number

file="$location/$number"

if [ ! -f "$file" ]
then
  echo "Invalid number."
  exit 1
fi

gedit --new-window "$tmp"
echo "Type ENTER when you are done."
read a
cat "$tmp" > "$file"

' | sed "s/@@%/'/g" > "$install/notes/bin/change_note"
    chmod 755 "$install/notes/bin/change_note"

    echo '#!/bin/sh
location="$1"
trash="$2"
echo "Enter the number:"
read number

file="$location/$number"

if [ ! -f "$file" ]
then
  echo "Invalid number."
  exit 1
fi

mv "$file" "$trash/$number.`date +%s`"

' | sed "s/@@%/'/g" > "$install/notes/bin/remove_note"
    chmod 755 "$install/notes/bin/remove_note"

    echo '#!/bin/sh
location="$1"
echo "Search for:"
read search

found=""
for file in `ls "$location"`
do
  grep "$search" "$location/$file" >/dev/null && found="$found $file"
done

if [ -z "$found" ]
then
  echo "No results found."
else
  echo "Results:"
  for file in $found
  do
    echo -n "$file. "
    head -1 "$location/$file"
  done
fi
echo

' | sed "s/@@%/'/g" > "$install/notes/bin/find_note"
    chmod 755 "$install/notes/bin/find_note"

    echo '#!/bin/sh
location="$1"
echo "Enter the number:"
read number

file="$location/$number"

if [ ! -f "$file" ]
then
  echo "Invalid number."
  exit 1
fi

cat "$file" 2> /dev/null || echo "$number does not exist."
echo

' | sed "s/@@%/'/g" > "$install/notes/bin/get_note"
    chmod 755 "$install/notes/bin/get_note"

    echo '#!/bin/sh
root="/home/johanv/programs/notes"
location="$root/notes"
tmp="$root/tmp.txt"
while true
do
  echo "Choose one:"
  echo "1.Add a note"
  echo "2.Search for a note"
  echo "3.Change a note"
  echo "4.Remove a note"
  echo "5.Get a note using its number"
  echo "6.Export a note"
  echo "7.Uninstall"
  echo "8.Exit"
  read choice
  case "$choice" in
    1)$root/bin/add_note "$location" "$tmp";;
    2)$root/bin/find_note "$location";;
    3)$root/bin/change_note "$location" "$tmp";;
    4)$root/bin/remove_note "$location" "$root/trash";;
    5)$root/bin/get_note "$location";;
    6)$root/bin/export "$location";;
    7)$root/bin/uninstall "$root"
      exit;;
    8)exit;;
  esac
done

' | sed "s/@@%/'/g" > "$install/notes/bin/main"
    chmod 755 "$install/notes/bin/main"

    echo '#!/bin/sh
location="$1"
echo "Enter the number:"
read number

file="$location/$number"

if [ ! -f "$file" ]
then
  echo "Invalid number."
  exit 1
fi

echo "What do you want to call it?"
read export_file

cp "$file" "$HOME/Desktop/$export_file" && echo "$export_file has been added to your desktop."


' | sed "s/@@%/'/g" > "$install/notes/bin/export"
    chmod 755 "$install/notes/bin/export"

    echo '#!/bin/sh
location="$1"
tmp="$2"

> $tmp
gedit --new-window "$tmp"
echo "Type ENTER when you are done."
number=`ls -1 "$location" | tail -1`
test -z "$number" && number=0
number=`expr "$number" "+" "1"`
read a
cat "$tmp" > "$location/$number"

' | sed "s/@@%/'/g" > "$install/notes/bin/add_note"
    chmod 755 "$install/notes/bin/add_note"

    echo '#!/bin/sh
root="$1"
echo "Are you sure you want to delete:"
find "$root"
echo "type y or n."
read answer
if [ "$answer" = "y" ]
then
  rm -r "$root"
else
  echo "Cancelled."
  echo "Press ENTER to continue."
  read a
fi

' | sed "s/@@%/'/g" > "$install/notes/bin/uninstall"
    chmod 755 "$install/notes/bin/uninstall"

    echo 'hi

' | sed "s/@@%/'/g" > "$install/notes/tmp.txt"
    chmod 755 "$install/notes/tmp.txt"

    echo '#!/bin/sh
/home/johanv/programs/notes/bin/main

' | sed "s/@@%/'/g" > "$install/notes/run"
    chmod 755 "$install/notes/run"

    echo '
' | sed "s/@@%/'/g" > "$install/notes/tmp.txt~"
    chmod 755 "$install/notes/tmp.txt~"


    echo "Installation has been successfully completed."
  fi
fi
echo "Press ENTER to exit."
read a