Commit Diff
Diff:
4ea91ad1abddd4143fe7ff794b10d03c306d974d
be29f5568839f3ac75c3e955344a25942af3df54
Commit:
be29f5568839f3ac75c3e955344a25942af3df54
Tree:
a4c2a8f317a02730509514265cc9075ee278bdc4
Author:
Fred. Galusik <f@galusik.xyz>
Committer:
Fred. Galusik <f@galusik.xyz>
Date:
Sat May 9 14:21:03 2015 UTC
Message:
cleanup and MIRROR var found in pkg.conf
blob - 457ff838b4ebf717befaaf78714f50f39e0523db
blob + fd8e285fc5c5e28a4c8a01f62540112720667a4a
--- snaps
+++ snaps
@@ -40,12 +40,12 @@
### VARS
###
+VERSION=0.1
+
+MIRRORSOURCE=/etc/pkg.conf
+MIRROR=$(sed -e 's/installpath = //' -e 's/packages\///' $MIRRORSOURCE)
+
RL=57
-ARCH=amd64
-
-MIRROR=http://ftp.fr.openbsd.org
-
-URL=$MIRROR/pub/OpenBSD/snapshots/$ARCH
BSDRD=bsd.rd
SHAF=SHA256
SIGF=SHA256.sig
@@ -61,110 +61,91 @@ NOW='date \"+ %Y-%m-%d %R\"'
###
###
-function usage {
- echo "snaps - Download, check and install bsd.rd from snapshot"
- echo "Usage: snaps [-g|-G|-l|-h]"
- echo " -g Just Download and check bsd.rd from snapshot"
- echo " -G Download, check and install bsd.rd"
- echo " -l Show the 3 last times you have upgraded your OS to snapshot"
- echo " -h Print this message and exit."
- exit
+usage() {
+ echo "Usage: ${0##*/} [-gGlh]" >&2 && exit 1
}
-function power {
- if [[ $(id -u) != "0" ]];then
- echo "You need to be root to do this." 1>&2
+s_root() {
+ if [[ $(id -u) != "0" ]]; then
+ echo "==> WARNING: You need to be root to do this" 1>&2
exit 1
fi
}
-function log {
- echo "$NOW FROM $URL" >> $LOGF
+s_log() {
+ echo "$NOW FROM $MIRROR" >> $LOGF
}
-function getlog {
- if [[ -f $LOGF ]];then
+get_log() {
+ if [[ -f $LOGF ]]; then
tail -n 3 $LOGF
else
- echo "No $LOGF file. Seems you have not yet played with snaps."
- exit
+ echo "No $LOGF file. Seems you have not yet played with snaps"
+ exit 1
fi
}
-function get_rd {
+get_rd() {
echo "\n=== FETCHING FILES ==="
- set -A fich $BSDRD $SHAF $SIGF
- for f in ${fich[@]}
- do
- if [[ -f $f ]];then
- echo "\nOld $f removed."
- rm $f
+ for _i in $BSDRD $SHAF $SIGF; do
+ if [[ -f ${_i} ]]; then
+ echo "\nDeleted old ${_i}"
+ rm ${_i}
fi
- echo "Fetching new $f"
- $GET $URL/$f || exit 1
+ echo "==> Fetching new ${_i}"
+ $GET $MIRROR${_i} || exit 1
done
}
-function check {
+s_check() {
echo "\n=== FILE INTEGRITY CHECKING ==="
OK=OK
# signify
- if [[ $(signify -C -p $SIGNPUB -x $SIGF $BSDRD | grep OK | awk '{print $2}') = $OK ]];then
- echo "Good, $SHAF file comes from OpenBSD."
+ if [[ $(signify -C -p $SIGNPUB -x $SIGF $BSDRD | grep OK | awk '{print $2}') = $OK ]]; then
+ echo "==> GOOD: $SHAF file is coming from OpenBSD"
else
- echo "WARNING: $SHAF is not coming from OpenBSD, aborting!!"
- exit
+ echo "==> WARNING: $SHAF is not coming from OpenBSD, aborting!!"
+ exit 1
fi
# sha256
- if [[ $(sha256 -c $SHAF 2>&1 | grep OK | awk '{print $3}') = $OK ]];then
- echo "bsd.rd integrity checked: OK!"
+ if [[ $(sha256 -c $SHAF 2>&1 | grep OK | awk '{print $3}') = $OK ]]; then
+ echo "==> GOOD: bsd.rd integrity checked"
else
- echo "bsd.rd seems corrupted, aborting!!"
- exit
+ echo "==> WARNING: bsd.rd seems corrupted, aborting!!"
+ exit 1
fi
}
-function move {
+s_move() {
echo "\n=== MOVING FILE ==="
- echo -n "Do you want to move $BSDRD to / ? (y/n)"
- read answer
- case $answer in
+ cp -p /bsd /bsd.o || exit 1
+ mv /bsd.rd /bsd.o.rd || exit 1
+ mv $BSDRD / || exit 1
+ rm $SHAF
+ rm $SIGF
+ echo "==> New bsd.rd installed and old files saved"
+ echo "You can reboot your OS"
+ echo "Type bsd.rd at the boot prompt, [enter] and choose (U)pgrade"
+ echo ""
+ echo "If something goes wrong, you can still boot your old kernel"
+ echo "Just type bsd.o at the boot prompt"
+ echo ""
+ echo -n "==> Do you want to do it now ? (y/n)"
+ read _a
+ case ${_a} in
y|Y)
- echo "First, copy /bsd to /bsd.o and /bsd.rd /bsd.o.rd"
- cp /bsd /bsd.o || exit 1
- mv /bsd.rd /bsd.o.rd || exit 1
- echo "Now, move the new one."
- mv $BSDRD / || exit 1
- echo "Done, your new bsd.rd is installed."
- echo "You can reboot your OS to it: type bsd.rd at the boot prompt."
- echo ""
- echo "If something goes wrong, you can still boot your old kernel."
- echo "Just type bsd.o at the boot prompt."
- echo "So, after backing up your important files, you can reboot your OS."
- echo -n "Do you want to do it now ? (y/n)"
- read reb
- case $reb in
- y|Y)
- echo "After the upgrade, don't forget to run:"
- echo "sysmerge (merging new conf. files)"
- echo "pkg_add -uiv (updating your packages)"
- echo ""
- echo "Rebooting..."
- $REBOOT
- ;;
- *)
- echo "Aborting..."
- exit
- ;;
- esac
+ echo "After upgrade, don't forget to run sysmerge(8)"
+ echo "Then, update packages or ports"
+ echo "==> Rebooting..."
+ $REBOOT
;;
*)
- echo "Aborting..."
+ echo "==> Aborting (new bsd.rd is still installed)"
exit
;;
esac
@@ -176,14 +157,14 @@ function move {
case $1 in
-g)
get_rd
- check
+ s_check
;;
-G)
- power
- log
+ s_root
+ s_log
get_rd
- check
- move
+ s_check
+ s_move
;;
-l)
getlog
Frédéric Galusik