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

script for linux installation #63

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
53 changes: 9 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Pantheon CMD is a Python-based command-line tool that allows you to generate a rendered preview of modular documentation using the new HAML templates.

Installing Pantheon CMD using RPM allows you to perform actions using the predefined aliases such as:
Installing Pantheon CMD using RPM allows you to perform actions using the predefined aliases such as:
* `pcmd validate`
* `pcmd build`
* `pcmd preview`
Expand All @@ -24,58 +24,23 @@ A script used to package the script as an RPM-based package that can be installe
**PantheonCMD**
A directory containing the source files for the script, and the man page file.

## Updating the Script
All additions and updates to the script are welcome.

## Packaging the Script
## Packaging and Installing Pantheon CMD on RHEL and Fedora
After you update Pantheon CMD and test the changes, build an RPM-based package for the script to be installed on systems that use *yum* or *dnf*.

* Prerequisites:
* A user has registered their SSH keys with GitHub.

1. Install the `svn` and `rpmbuild` packages on your system:
```shell
# on RHEL
$ sudo yum install subversion
$ sudo yum install rpm-build

# on Fedora
$ sudo dnf install subversion
$ sudo dnf install rpm-build
```
2. Clone this repository.
1. Clone this repository.
```shell
$ git clone [email protected]:redhataccess/pantheon-cmd.git
```
3. Open *./build/pantheon-cmd.spec*.
4. Increment the value of the *Release* number.
As an example, `Release: 1%{?dist}` increments the version of the build to `1.0.1`, where `{?dist}` identifies of your Linux distribution.
5. Run the build script:
```shell
$ sh make.sh 1.0
```
As a result, the `build/pantheon-cmd-1.0-X.<your-distribution-and-version>.noarch.rpm` file is generated in the root of the repository. This file will be used in the following step.

## Installing Pantheon CMD

Install Pantheon CMD on a local system.

## Installing Pantheon CMD on RHEL and Fedora

Install the RPM and all Ruby gem dependencies.

1. Install the RPM:
```shell
$ sudo dnf localinstall build/pantheon-cmd-1.0-X.el8.noarch.rpm
```
Note that your `rpm` filename might differ based on your Linux distribution.
* Example:
* `el8` for RHEL 8
* `fc34` for Fedora 34

2. Install Ruby gem dependencies:
2. Navigate to the `pantheon-cmd` directory:
```shell
$ cd pantheon-cmd
```
3. Run the `linux-cmd-intallation.sh` packaging and installation script:
```shell
$ sudo gem install asciidoctor concurrent-ruby haml tilt
$ sh linux-cmd-intallation.sh
```

The script is installed on your local machine.
Expand Down
61 changes: 61 additions & 0 deletions linux-cmd-intallation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Error handling
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
terminate()
{
echo >&2 '
*** terminated ***
'
echo "\"$last_command\" command failed with exit code $?."
exit 1
}

trap 'terminate' 0

set -e

# install required packages
echo 'Installing package dependencies...'
sudo dnf install python3 ruby subversion rpm-build

echo 'Installing ruby gem dependencies...'
sudo gem install asciidoctor concurrent-ruby haml tilt
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

smth here isn't quite right, I get a deprecation message

DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621 Requirement already satisfie

# do we still need pygit2?
pip3 install pygit2

echo 'Creating resources directories...'
for dir in "PantheonCMD/haml" "PantheonCMD/locales"; do if [ ! -d "$dir" ]; then mkdir $dir; fi; done

echo 'Getting HAML templates...'
svn checkout https://github.com/redhataccess/pantheon/trunk/pantheon-bundle/src/main/resources/apps/pantheon/templates/haml/html5 PantheonCMD/haml

echo 'Getting locales...'
svn checkout https://github.com/asciidoctor/asciidoctor/trunk/data/locale PantheonCMD/locales
rm -rf PantheonCMD/{haml,locales}/.svn

echo 'Updating styling references...'
sed -i 's/^-\ pantheonCssPath.*/-\ pantheonCssPath\ \=\ \"resources\/rhdocs.min.css\"/' PantheonCMD/haml/document.html.haml
sed -i 's/href\=\"https\:\/\/static\.redhat\.com\/libs\/redhat\/redhat-font\/2\/webfonts\/red-hat-font\.css/href\=\"resources\/red-hat-font.css/' PantheonCMD/haml/document.html.haml

echo 'Copying the source files to the local binaries directory...'
sudo cp -r PantheonCMD /usr/local/bin

# do we need to account for different shells?
# exit code is 0 so setting +e
echo 'Adding an alias to the current shell...'
if [[ $SHELL = '/bin/bash' ]]; then
set +e && alias pcmd='/usr/bin/python3 /usr/local/bin/PantheonCMD/pcmd.py $@' && source ~/.bashrc
elif [[ $SHELL = '/bin/tcsh' ]]; then
set +e && alias pcmd '/usr/bin/python3 /usr/local/bin/PantheonCMD/pcmd.py $@' && source ~/.tcshrc
elif [[ $SHELL = '/bin/csh' ]]; then
set +e && alias pcmd '/usr/bin/python3 /usr/local/bin/PantheonCMD/pcmd.py $@' && source ~/.cshrc
fi
Comment on lines +47 to +53
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure if we should account for various shells or just roll with bash


rm -rf PantheonCMD/{haml,locales}

trap : 0

echo >&2 '
*** DONE ***
'
2 changes: 1 addition & 1 deletion osx-cmd-intallation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cp -r PantheonCMD /usr/local/bin

echo 'Adding an alias to ~/.zshrc file...'

alias pcmd="/usr/local/bin/python3 /usr/local/bin/PantheonCMD/pcmd.py $@"
alias pcmd="/usr/bin/python3 /usr/local/bin/PantheonCMD/pcmd.py $@"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in linux this command gives an exit code 0, which terminates the script. is it the same on mac? in which case I can change it to this:

Suggested change
alias pcmd="/usr/bin/python3 /usr/local/bin/PantheonCMD/pcmd.py $@"
set +e && alias pcmd="/usr/bin/python3 /usr/local/bin/PantheonCMD/pcmd.py $@"


echo 'Sourcing your ~/.zshrc file...'

Expand Down