Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging #148

Open
wants to merge 9 commits into
base: linux-diagnostics-with-packaging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NfsDiagnostics/nfsclientlogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ main() {
then
stop 0<&- > "${STDLOG_FILE}" 2>&1
else
echo "Usage: ./nfsclientlogs.sh <v3b | v4> <> <start | stop> <CaptureNetwork> <OnAnomaly>"
echo "Usage: diag-main.sh nfs <v3b | v4> <start | stop> <CaptureNetwork> <OnAnomaly>"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion NfsDiagnostics/trace-nfsbpf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
Copy link
Collaborator

@ksub42 ksub42 Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, Python3 is not available by default on at least some of the distros that we support (RHEL 7?). It might be a better idea to invoke Python as /usr/bin/env python. IIRC the scripts work the same across Python 2 & 3.

#!/usr/bin/python3
from bcc import BPF
from bcc.utils import printb
from time import sleep
Expand Down
2 changes: 1 addition & 1 deletion SMBDiagnostics/smbclientlogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ main() {
then
stop 0<&- > "${STDLOG_FILE}" 2>&1
else
echo "Usage: ./smbclientlogs.sh <start | stop> <CaptureNetwork>"
echo "Usage: diag-main.sh cifs <start | stop> <CaptureNetwork> <OnAnomaly>"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion SMBDiagnostics/trace-cifsbpf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same /usr/bin/env python comment as in trace-nfsbpf.

#!/usr/bin/python3
from bcc import BPF
from bcc.utils import printb
from time import sleep
Expand Down
18 changes: 18 additions & 0 deletions diag-main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/bash

PACKAGE_TREE="$(dirname $(dirname $(readlink -f $0)))"
run() {
if [[ $1 == "nfs" ]] || [[ $1 == "cifs" ]];
then
if [[ $1 == "nfs" ]]
then script_path="${PACKAGE_TREE}/lib/NfsDiagnostics/nfsclientlogs.sh"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I'm a little divided about pushing nfsclientlogs (and the smb equivalent) into lib. I figure that since they're executable, they should be under bin. Then again, I also see that having them in lib makes sense. I'm not going to make this a blocker, but I guess it is something we could ask for an opinion about with other folks.

else script_path="${PACKAGE_TREE}/lib/SMBDiagnostics/smbclientlogs.sh"
fi
$script_path "$@"

else
echo "Usage: diag-main.sh <cifs | nfs> <start | stop> [Version] [CaptureNetwork] [OnAnomaly]" >&2
fi
}

run "$@"
5 changes: 5 additions & 0 deletions packaging/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Package: $PKG_NAME
Version: $VERSION
Maintainer: Microsoft
Architecture: all
Description: Diagnostics scripts for CIFS and NFS.
3 changes: 3 additions & 0 deletions packaging/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

chown root:root $SYS_DIR/bin/diag-main.sh
chmod 454 $SYS_DIR/bin/diag-main.sh
1 change: 1 addition & 0 deletions packaging/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -rf $SYS_DIR
44 changes: 44 additions & 0 deletions packaging/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export PKG_NAME=azure-files-diag
export RELEASE=1
export VERSION=1
export SYS_DIR=/opt/xstore
export SRC_DIR=..
# export PKG_BUILD=$(PKG_NAME)$(sles)-$(RELEASE)-1.x86_64
# export PKG_DIR=BUILDROOT/$(PKG_BUILD)
export PKG_DIR=$(PKG_NAME)
export DEB_PKG_DIR=$(PKG_DIR)/DEBIAN
export OPT_DIR=$(PKG_DIR)$(SYS_DIR)

build: init debian rpm clean
echo "Building deb and rpm packages"

init:
mkdir -p $(OPT_DIR)/bin
mkdir -p $(OPT_DIR)/lib
cp -r ../NfsDiagnostics $(OPT_DIR)/lib
cp -r ../SMBDiagnostics $(OPT_DIR)/lib
cp -r ../diag-main.sh $(OPT_DIR)/bin

debian: init
cp -r ./DEBIAN ./$(PKG_DIR)
for file in ./$(PKG_DIR)/DEBIAN/*; do \
sed -i "s/\$$PKG_NAME/${PKG_NAME}/g" $$file; \
sed -i "s:\$$SYS_DIR:${SYS_DIR}:g" $$file; \
sed -i "s/\$$VERSION/${VERSION}/g" $$file; \
done
dpkg-deb --build ./$(PKG_DIR)

rpm: init
mkdir -p ~/rpmbuild/SOURCES
cp -r $(PKG_DIR)/opt ~/rpmbuild/SOURCES
cp ./RPM/spec.spec .
sed -i "s:\$$SYS_DIR:${SYS_DIR}:g" spec.spec
sed -i "s:\$$PKG_NAME:${PKG_NAME}:g" spec.spec
sed -i "s:\$$VERSION:${VERSION}:g" spec.spec
sed -i "s:\$$RELEASE:${RELEASE}:g" spec.spec
rpmbuild -bb spec.spec
mv ~/rpmbuild/RPMS/x86_64/*.rpm .
rm -r ~/rpmbuild

clean:
rm -rf ./$(PKG_DIR) spec.spec
8 changes: 8 additions & 0 deletions packaging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Run `make` to generate both .deb and .rpm packages and clean the build directories or individually run the following:

- Run `make debian` to generate .deb package
- Run `make rpm` to generate .rpm package
- Run `make clean` once the packages are created.

Edit `DEBIAN/control` and `RPM/spec.spec` files to change package description or maintainer information. \
Edit `Makefile` to make changes to PKG_NAME, RELEASE or VERSION, etc.
35 changes: 35 additions & 0 deletions packaging/RPM/spec.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Name: $PKG_NAME
Version: $VERSION
Release: $RELEASE
Summary: Diagnostics scripts for NFS and CIFS
License: GPL
URL: https://example.com

%description
Diagnostics scripts for NFS and CIFS

%prep

%install
# Install script and related files
# install -m 454 ~/opt/xstore/bin/diag-main.sh %{buildroot}/opt/xstore/bin/diag-main.sh
cp -r ~/rpmbuild/SOURCES/opt %{buildroot}
echo %{buildroot}

%post
chmod 454 $SYS_DIR/bin/diag-main.sh

%files
# List all the files that are part of the package
# /opt/xstore/bin/diag-main.sh
$SYS_DIR/bin/diag-main.sh
$SYS_DIR/lib/NfsDiagnostics/README
$SYS_DIR/lib/NfsDiagnostics/nfsclientlogs.sh
$SYS_DIR/lib/NfsDiagnostics/trace-nfsbpf
$SYS_DIR/lib/SMBDiagnostics/README
$SYS_DIR/lib/SMBDiagnostics/smbclientlogs.sh
$SYS_DIR/lib/SMBDiagnostics/trace-cifsbpf
%changelog

%postun
rm -r $SYS_DIR