-
Notifications
You must be signed in to change notification settings - Fork 4
/
deepines-preinstall-fix.sh
executable file
·230 lines (210 loc) · 7.01 KB
/
deepines-preinstall-fix.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
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
#!/bin/sh
Fmt="printf"
APTDIR=/etc/apt
SRCLIST=${APTDIR}/sources.list
DEEPINESLIST="${SRCLIST}.d/deepines.list"
OLDSTABLEDIST="apricot"
OLDSTABLEREPO="## Generated by deepin-installer
deb https://community-packages.deepin.com/deepin/ apricot main contrib non-free
#deb-src https://community-packages.deepin.com/deepin/ apricot main contrib non-free"
RCDIST="beige"
RCREPO="## Generated by deepin-installer
deb https://community-packages.deepin.com/beige/ beige main commercial community
#deb-src https://community-packages.deepin.com/beige/ beige main commercial community"
SEPARATOR="=============================================================="
SEPARATOR2="--------------------------------------------------------------"
INSTALLING_DEEPIN_REPO="Installing Deepin %d main repositories...\n"
INSTALLING_DONE="Done!\n"
INSTALLING_FAILED="Failed to restore the repositories!\n"
NOT_SUPPORTED="This operating system is not Deepin 20 or Deepin 23."
ONLY_COMPATIBLE=" This repair script is only for Deepin 20 and Deepin 23.
It should not be used on other Linux distributions."
SRC_LIST_CHECKING="Checking configuration of main repositories..."
SRC_LIST_ARE_RIGHT="Repositories configured correctly."
SRC_LIST_NOT_FOUND="$SRCLIST was not found."
SRC_LIST_NOT_RIGHT="$SRCLIST does not have the needed repositories."
SRC_LIST_IMPROPER="Improperly configured repositories."
SRC_LIST_IMPROPER2="These repositories are incorrectly configured
in /etc/apt/sources.list instead of being separate
files under /etc/apt/sources.list.d/"
CHOOSE_OPTION="Choose one of the following options:"
WANT_RESTORE_OPTIONS=" R) Restore the original repository configuration.
X) Do not repair and exit."
NO_RESTORE="Deepines Store may not be able to be installed
if these problems are not fixed first.
No changes have been made."
INVALID_OPTION="Invalid option selected"
YESEXPR="[yY]*"
YDEF="[Y/n]"
DEEPINES_STORE_FOUND="Deepines Store is currently installed."
WANT_REMOVE_DEEPINES_STORE="Do you want to uninstall Deepines Store?"
WANT_REMOVE_DEEPINES_REPO="Do you want to uninstall Deepines Repository?"
DEEPINES_NO_STORE="The repository is installed, but Deepines Store is not."
REPO_NO_PKG="Currently the repository package is no longer provided."
RECOMMENDED_DEEPINES="It is recommended to install Deepines Store."
NO_DEEPINES="Deepines Store is not installed.
You should not have any problems now."
case "${LANGUAGE:-$LANG}" in
es*)
INSTALLING_DEEPIN_REPO="Instalando repositorios principales de Deepin %d...\n"
INSTALLING_DONE="¡Hecho!\n"
INSTALLING_FAILED="¡Error al intentar restaurar los repositorios!\n"
NOT_SUPPORTED="Este sistema operativo no es Deepin 20 o Deepin 23."
ONLY_COMPATIBLE=" Este script de reparación es sólo para Deepin 20 y Deepin 23.
No debe usarse en otras distribuciones Linux."
SRC_LIST_CHECKING="Comprobando configuración de los repositorios principales..."
SRC_LIST_ARE_RIGHT="Repositorios configurados correctamente."
SRC_LIST_NOT_FOUND="$SRCLIST no se encontró."
SRC_LIST_NOT_RIGHT="$SRCLIST no tiene los repositorios necesarios."
SRC_LIST_IMPROPER="Repositorios configurados de manera inadecuada"
SRC_LIST_IMPROPER2="Estos repositorios están configurados de manera
inadecuada en /etc/apt/sources.list en lugar de
ser archivos separados en /etc/apt/sources.list.d/"
CHOOSE_OPTION="Elija una de las siguientes opciones:"
WANT_RESTORE_OPTIONS=" R) Restaurar la configuración original de repositorios.
X) No reparar y salir."
NO_RESTORE="Es posible que no se pueda instalar Tienda Deepines
si estos problemas no se solucionan primero.
No se han realizado cambios."
INVALID_OPTION="Opción no válida"
YESEXPR="[sSyY]*"
YDEF="[S/n]"
DEEPINES_STORE_FOUND="Tienda Deepines está actualmente instalada."
WANT_REMOVE_DEEPINES_STORE="¿Desea desinstalar Tienda Deepines?"
WANT_REMOVE_DEEPINES_REPO="¿Desea desinstalar Repositorio Deepines?"
DEEPINES_NO_STORE="El repositorio está instalado, pero Tienda Deepines no."
REPO_NO_PKG="Actualmente ya no se proporciona el paquete de repositorio."
RECOMMENDED_DEEPINES="Se recomienda instalar Tienda Deepines."
NO_DEEPINES="Tienda Deepines no está instalada.
No debería tener ningún problema ahora."
;;
esac
InstallTextToRepo() {
sudo mkdir -p $APTDIR
echo "$1" | sudo tee "${SRCLIST}"
}
InstallDeepinRepo() {
echo
echo "$SEPARATOR"
$Fmt "${INSTALLING_DEEPIN_REPO}\n" "$1" && {
InstallTextToRepo "$2" 2>&1
} || {
$Fmt "$INSTALLING_FAILED"
echo "$SEPARATOR"
exit 1
} && $Fmt "$INSTALLING_DONE"
echo "$SEPARATOR"
}
UnsupportedOS() {
echo >&2 "$SEPARATOR"
echo >&2 "$NOT_SUPPORTED"
echo >&2
echo >&2 "$ONLY_COMPATIBLE"
echo >&2 "$SEPARATOR"
exit 1
}
CheckBadRepos() {
CHECKREPOS=$(grep -E '^deb' <"${SRCLIST}" | grep -Ev "^deb .*($1) ")
if [ "${CHECKREPOS}" ]; then
echo >&2 "$SRC_LIST_IMPROPER"
echo >&2 "$SEPARATOR"
echo >&2
echo >&2 "$CHECKREPOS" | sed -e "s/deb h/\n deb h/g; s/deb \[/\n deb \[/g"
echo >&2
echo >&2 "$SEPARATOR"
echo >&2 "$SRC_LIST_IMPROPER2"
return 1
else
echo "$SRC_LIST_ARE_RIGHT"
echo
echo "$SEPARATOR"
return 0
fi
}
# If we reach here, then we have already made sure that the OS is really Deepin 20 or Deepin 23.
CheckRepos() {
echo "$SEPARATOR"
if [ -f "${SRCLIST}" ]; then
echo "$SRC_LIST_CHECKING"
echo
DEBDIST=$(grep -E "^deb .*($1)? " "${SRCLIST}" | sed -r 's/^.* (\S+) main .*$/\1/g' | grep "$2")
if [ -n "${DEBDIST}" ]; then
CheckBadRepos "$1" && return 0
else
echo >&2 "$SRC_LIST_NOT_RIGHT"
echo >&2
fi
else
echo >&2 "$SRC_LIST_NOT_FOUND"
echo >&2
fi
return 1
}
AnsweredYesTo() { # Xoas' Get Answer Function.
$Fmt "%s " "$1 $YDEF"
eval "case '$(head -n1)' in
($YESEXPR|'') return 0 ;; # Yes.
(*) return 1 ;; esac # No."
}
CheckDeepines() {
if dpkg -s "deepines-store" >/dev/null 2>&1; then
echo "$DEEPINES_STORE_FOUND"
if AnsweredYesTo "$WANT_REMOVE_DEEPINES_STORE"; then
sudo apt purge deepines-store -y && sudo apt autoremove --purge -y
fi
elif dpkg -s "deepines-repository" >/dev/null 2>&1; then
echo "$REPO_NO_PKG"
echo "$RECOMMENDED_DEEPINES"
if AnsweredYesTo "$WANT_REMOVE_DEEPINES_REPO"; then
sudo apt purge deepines-repository -y
fi
elif [ -f "${DEEPINESLIST}" ]; then
echo "$DEEPINES_NO_STORE"
echo "$RECOMMENDED_DEEPINES"
else
echo "$NO_DEEPINES"
fi
}
WantRestoreRepos() {
echo "$SEPARATOR2"
echo "$CHOOSE_OPTION"
echo
echo "$WANT_RESTORE_OPTIONS"
echo
FINISH=0
while [ $FINISH -eq 0 ]; do
read -r SELECTEDOPTION
case $SELECTEDOPTION in
R | r)
InstallDeepinRepo "$1" "$2" && FINISH=1 && return 0
;;
X | x)
echo >&2
echo >&2 "$NO_RESTORE"
FINISH=1
exit 1
;;
*)
echo "$INVALID_OPTION"
;;
esac
done
}
Main() {
DIST_ID=$(lsb_release -is 2>/dev/null)
REL_NUM=$(lsb_release -rs 2>/dev/null)
if [ "$DIST_ID" = "Deepin" ]; then
case $REL_NUM in
20 | 20.*)
CheckRepos "/deepin/|/deepin-20-beta/" $OLDSTABLEDIST || WantRestoreRepos "20" "$OLDSTABLEREPO"
;;
"23 Nightly" | 23 | 23.*)
CheckRepos "/beige/|/dde-nightly/" $RCDIST || WantRestoreRepos "23" "$RCREPO"
;;
*) UnsupportedOS ;;
esac
else
UnsupportedOS
fi
}
Main && CheckDeepines